summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-10-26 15:58:21 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-10-26 15:58:21 +0200
commite1f0a60f5a06ff21b85d7905e77913fb9acacab4 (patch)
tree501fd8b0d224c261c2591a0c3cddc5aa66aaa385
parentc986011039cbb77171486d4b916c888f390cfbe2 (diff)
Add spitted library from agl-service-windowmanager
Relate commit : https://gerrit.automotivelinux.org/gerrit/#/c/11451/ Change-Id: Id82ee513e06f0c12eba044b8d42d8dde68063168 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp> # Conflicts: # src/CMakeLists.txt # src/libwindowmanager.cpp
-rw-r--r--src/libwindowmanager.cpp132
-rw-r--r--src/libwindowmanager.h22
2 files changed, 98 insertions, 56 deletions
diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp
index 263dd57..7cdd5c3 100644
--- a/src/libwindowmanager.cpp
+++ b/src/libwindowmanager.cpp
@@ -33,7 +33,6 @@
#include <systemd/sd-event.h>
-#include <json-c/json.h>
#include <pthread.h>
extern "C" {
@@ -43,20 +42,32 @@ extern "C" {
#define UNUSED(x) (void)(x)
-/**
- * @class LibWindowmanager::Impl
- */
+// _ ___ _
+// ___| | __ _ ___ ___ |_ _|_ __ ___ _ __ | |
+// / __| |/ _` / __/ __| | || '_ ` _ \| '_ \| |
+// | (__| | (_| \__ \__ \ | || | | | | | |_) | |
+// \___|_|\__,_|___/___/ |___|_| |_| |_| .__/|_|
+// |_|
class LibWindowmanager::Impl {
friend class LibWindowmanager;
+ const std::vector<std::string> kListEventName{
+ std::string("active"),
+ std::string("inactive"),
+ std::string("visible"),
+ std::string("invisible"),
+ std::string("syncdraw"),
+ std::string("flushdraw")
+ };
+
// This is the LibWindowmanager interface impl
int init(int port, char const *token);
// WM API
- int requestSurface(const char *label);
- int activateSurface(const char *label);
- int deactivateSurface(const char *label);
- int endDraw(const char *label);
+ int requestSurface(json_object *object);
+ int activateSurface(json_object *object);
+ int deactivateSurface(json_object *object);
+ int endDraw(json_object *object);
void set_event_handler(enum EventType et, handler_fun func);
@@ -74,7 +85,7 @@ class LibWindowmanager::Impl {
const std::function<void(bool, json_object *)> &onReply);
public:
- void event(char const *et, char const *label);
+ void event(char const *et, json_object *object);
private:
int runEventLoop();
};
@@ -127,8 +138,7 @@ void onEvent(void *closure, const char *event, afb_wsj1_msg *msg) {
}
reinterpret_cast<LibWindowmanager::Impl *>(closure)->event(
- event, json_object_get_string(
- json_object_object_get(afb_wsj1_msg_object_j(msg), "data")));
+ event, json_object_object_get(afb_wsj1_msg_object_j(msg), "data"));
}
/* called when wsj1 hangsup */
@@ -155,9 +165,12 @@ json_object *drawing_name_json_argument(char const *label) {
} // namespace
-/**
- * @class LibWindowmanager::Impl::Impl
- */
+// _ ___ _ _ _
+// ___| | __ _ ___ ___ |_ _|_ __ ___ _ __ | | (_)_ __ ___ _ __ | |
+// / __| |/ _` / __/ __| | || '_ ` _ \| '_ \| | | | '_ ` _ \| '_ \| |
+// | (__| | (_| \__ \__ \ | || | | | | | |_) | | | | | | | | | |_) | |
+// \___|_|\__,_|___/___/ |___|_| |_| |_| .__/|_| |_|_| |_| |_| .__/|_|
+// |_| |_|
LibWindowmanager::Impl::Impl() : wsj1{}, loop{}, labels(), handlers() { TRACE(); }
LibWindowmanager::Impl::~Impl() {
@@ -218,20 +231,29 @@ fail:
return rc;
}
-int LibWindowmanager::Impl::requestSurface(const char *label) {
+int LibWindowmanager::Impl::requestSurface(json_object *object) {
TRACE();
+ const char *tmp_label = json_object_get_string(
+ json_object_object_get(object, LibWindowmanager::kKeyDrawingName));
+
+ // DrawingName in "object" is overwrited in api_call("RequestSurface")
+ // So it is neccesary to copy it.
+ const char *label = std::string(tmp_label).c_str();
+
if (this->labels.find(label) != this->labels.end()) {
fputs("Surface label already known!\n", stderr);
return -EINVAL;
}
- json_object *j = drawing_name_json_argument(label);
+ // Store application name first
+ // because it may not return from setenv
+ this->labels.insert(this->labels.end(), label);
int rc = -1;
/* send the request */
int rc2 =
- this->api_call("RequestSurface", j, [&rc](bool ok, json_object *j) {
+ this->api_call("RequestSurface", object, [&rc](bool ok, json_object *j) {
if (ok) {
int id =
json_object_get_int(json_object_object_get(j, "response"));
@@ -257,17 +279,16 @@ int LibWindowmanager::Impl::requestSurface(const char *label) {
rc = rc2;
}
- if (rc >= 0) {
- this->labels.insert(this->labels.end(), label);
+ if (rc < 0) {
+ this->labels.erase(label);
}
return rc;
}
-int LibWindowmanager::Impl::activateSurface(const char *label) {
+int LibWindowmanager::Impl::activateSurface(json_object *object) {
TRACE();
- json_object *j = drawing_name_json_argument(label);
- return this->api_call("ActivateSurface", j, [](bool ok, json_object *j) {
+ return this->api_call("ActivateSurface", object, [](bool ok, json_object *j) {
if (!ok) {
fprintf(stderr, "API Call activate_surface() failed: %s\n",
j != nullptr ? json_object_to_json_string_ext(
@@ -277,10 +298,9 @@ int LibWindowmanager::Impl::activateSurface(const char *label) {
});
}
-int LibWindowmanager::Impl::deactivateSurface(const char *label) {
+int LibWindowmanager::Impl::deactivateSurface(json_object *object) {
TRACE();
- json_object *j = drawing_name_json_argument(label);
- return this->api_call("DeactivateSurface", j, [](bool ok, json_object *j) {
+ return this->api_call("DeactivateSurface", object, [](bool ok, json_object *j) {
if (!ok) {
fprintf(stderr, "API Call deactivate_surface() failed: %s\n",
j != nullptr ? json_object_to_json_string_ext(
@@ -290,10 +310,9 @@ int LibWindowmanager::Impl::deactivateSurface(const char *label) {
});
}
-int LibWindowmanager::Impl::endDraw(const char *label) {
+int LibWindowmanager::Impl::endDraw(json_object *object) {
TRACE();
- json_object *j = drawing_name_json_argument(label);
- return this->api_call("EndDraw", j, [](bool ok, json_object *j) {
+ return this->api_call("EndDraw", object, [](bool ok, json_object *j) {
if (!ok) {
fprintf(stderr, "API Call endDraw() failed: %s\n",
j != nullptr ? json_object_to_json_string_ext(
@@ -303,11 +322,21 @@ int LibWindowmanager::Impl::endDraw(const char *label) {
});
}
-void LibWindowmanager::Impl::set_event_handler(
- enum EventType et, std::function<void(char const *)> func) {
+static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
+{
+ // nop
+}
+
+void LibWindowmanager::Impl::set_event_handler(enum EventType et, handler_fun func) {
TRACE();
+ // Subscribe event
+ struct json_object* j = json_object_new_object();
+ json_object_object_add(j, "event", json_object_new_int(et));
- if (et >= 1 && et <= 6) { // Yeah ... just go with it!
+ int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this);
+
+ // Set event handler
+ if (et >= Event_Active && et <= Event_FlushDraw) {
this->handlers[et] = std::move(func);
}
}
@@ -341,12 +370,6 @@ std::pair<bool, LibWindowmanager::EventType> make_event_type(char const *et) {
}
} // namespace
-static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
-{
- fprintf(stderr, "Call %s\n", __func__);
-}
-
-
/// object will be json_object_put
int LibWindowmanager::Impl::api_call(
const char *verb, json_object *object,
@@ -416,7 +439,7 @@ int LibWindowmanager::Impl::api_call(
return rc;
}
-void LibWindowmanager::Impl::event(char const *et, char const *label) {
+void LibWindowmanager::Impl::event(char const *et, json_object *object) {
TRACE();
auto oet = make_event_type(et);
if (!oet.first) {
@@ -426,8 +449,11 @@ void LibWindowmanager::Impl::event(char const *et, char const *label) {
auto i = this->handlers.find(oet.second);
if (i != this->handlers.end()) {
+ const char *label = json_object_get_string(
+ json_object_object_get(object, LibWindowmanager::kKeyDrawingName));
+
if (this->labels.find(label) != this->labels.end()) {
- i->second(label);
+ i->second(object);
}
}
}
@@ -458,29 +484,33 @@ int LibWindowmanager::Impl::runEventLoop() {
}
}
-/**
- * @class LibWindowmanager
- */
+// _ _ _____ ____ ____ _ _ _
+// ___| | __ _ ___ ___ / \ | ___| __ ) / ___| (_) ___ _ __ | |_
+// / __| |/ _` / __/ __| / _ \ | |_ | _ \| | | | |/ _ \ '_ \| __|
+// | (__| | (_| \__ \__ \ / ___ \| _| | |_) | |___| | | __/ | | | |_
+// \___|_|\__,_|___/___/ /_/ \_\_| |____/ \____|_|_|\___|_| |_|\__|
+//
int LibWindowmanager::init(int port, char const *token) {
return this->d->init(port, token);
}
-int LibWindowmanager::requestSurface(const char *label) {
- return this->d->requestSurface(label);
+int LibWindowmanager::requestSurface(json_object *object) {
+ return this->d->requestSurface(object);
}
-int LibWindowmanager::activateSurface(const char *label) {
- return this->d->activateSurface(label);
+int LibWindowmanager::activateSurface(json_object *object) {
+ return this->d->activateSurface(object);
}
-int LibWindowmanager::deactivateSurface(const char *label) {
- return this->d->deactivateSurface(label);
+int LibWindowmanager::deactivateSurface(json_object *object) {
+ return this->d->deactivateSurface(object);
}
-int LibWindowmanager::endDraw(const char *label) { return this->d->endDraw(label); }
+int LibWindowmanager::endDraw(json_object *object) {
+ return this->d->endDraw(object);
+}
-void LibWindowmanager::set_event_handler(enum EventType et,
- std::function<void(char const *label)> f) {
+void LibWindowmanager::set_event_handler(enum EventType et, handler_fun f) {
return this->d->set_event_handler(et, std::move(f));
}
diff --git a/src/libwindowmanager.h b/src/libwindowmanager.h
index 6c13763..5bc97de 100644
--- a/src/libwindowmanager.h
+++ b/src/libwindowmanager.h
@@ -18,6 +18,7 @@
#define LIBWINDOWMANAGER_H
#include <functional>
+#include <json-c/json.h>
class LibWindowmanager {
public:
@@ -27,7 +28,18 @@ public:
LibWindowmanager(const LibWindowmanager &) = delete;
LibWindowmanager &operator=(const LibWindowmanager &) = delete;
- using handler_fun = std::function<void(const char *)>;
+ using handler_fun = std::function<void(json_object *)>;
+
+ /* DrawingArea name (usage: {layout}.{area}) */
+ const std::string kStrLayoutNormal = "normal";
+ const std::string kStrLayoutSplit = "split";
+ const std::string kStrAreaFull = "full";
+ const std::string kStrAreaMain = "main";
+ const std::string kStrAreaSub = "sub";
+
+ /* Key for json obejct */
+ constexpr static char *kKeyDrawingName = "drawing_name";
+ constexpr static char *kKeyDrawingArea = "drawing_area";
enum EventType {
Event_Active = 1,
@@ -43,10 +55,10 @@ public:
int init(int port, char const *token);
// WM API
- int requestSurface(const char *label);
- int activateSurface(const char *label);
- int deactivateSurface(const char *label);
- int endDraw(const char *label);
+ int requestSurface(json_object *object);
+ int activateSurface(json_object *object);
+ int deactivateSurface(json_object *object);
+ int endDraw(json_object *object);
void set_event_handler(enum EventType et, handler_fun f);