diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/libwindowmanager.cpp | 56 | ||||
-rw-r--r-- | src/libwindowmanager.h | 4 |
3 files changed, 45 insertions, 16 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96cad55..9052d70 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,7 @@ set_target_properties(${TARGET_LIBWM} # INTERPROCEDURAL_OPTIMIZATION ON CXX_EXTENSIONS OFF CXX_STANDARD 14 + VERSION ${PACKAGE_VERSION} CXX_STANDARD_REQUIRED ON) if (LINK_LIBCXX) diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp index 770d248..267fecc 100644 --- a/src/libwindowmanager.cpp +++ b/src/libwindowmanager.cpp @@ -57,6 +57,10 @@ class LibWindowmanager::Impl { std::string("flushdraw") }; + /* Key for json obejct */ + const char *kKeyDrawingName = "drawing_name"; + const char *kKeyDrawingArea = "drawing_area"; + // This is the LibWindowmanager interface impl int init(int port, char const *token); @@ -134,8 +138,13 @@ void onEvent(void *closure, const char *event, afb_wsj1_msg *msg) { return; } - reinterpret_cast<LibWindowmanager::Impl *>(closure)->event( - event, json_object_object_get(afb_wsj1_msg_object_j(msg), "data")); + json_object *val; + if (json_object_object_get_ex(afb_wsj1_msg_object_j(msg), "data", &val)) { + reinterpret_cast<LibWindowmanager::Impl *>(closure)->event(event, val); + } + else { + fprintf(stderr, "Not found key \"data\"\n"); + } } /* called when wsj1 hangsup */ @@ -154,12 +163,6 @@ constexpr struct afb_wsj1_itf itf = { // XXX: I am not sure this is the right thing to do though... std::recursive_mutex dispatch_mutex; -json_object *drawing_name_json_argument(char const *label) { - json_object *j = json_object_new_object(); - json_object_object_add(j, "drawing_name", json_object_new_string(label)); - return j; -} - } // namespace /** @@ -228,8 +231,15 @@ fail: int LibWindowmanager::Impl::requestSurface(json_object *object) { TRACE(); - const char *tmp_label = json_object_get_string( - json_object_object_get(object, LibWindowmanager::kKeyDrawingName)); + json_object *val; + const char *tmp_label; + if (json_object_object_get_ex(object, this->kKeyDrawingName, &val)) { + tmp_label = json_object_get_string(val); + } + else { + fprintf(stderr, "Not found key \"%s\"\n", this->kKeyDrawingName); + return -EINVAL; + } // DrawingName in "object" is overwrited in api_call("RequestSurface") // So it is neccesary to copy it. @@ -249,8 +259,16 @@ int LibWindowmanager::Impl::requestSurface(json_object *object) { int rc2 = 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")); + json_object *val; + int id; + if (json_object_object_get_ex(j, "response", &val)) { + id = json_object_get_int(val); + } + else { + fprintf(stderr, "Not found key \"response\"\n"); + rc = -EINVAL; + return; + } char *buf; asprintf(&buf, "%d", id); printf("setenv(\"QT_IVI_SURFACE_ID\", %s, 1)\n", buf); @@ -328,6 +346,9 @@ void LibWindowmanager::Impl::set_event_handler(enum EventType et, handler_fun fu json_object_object_add(j, "event", json_object_new_int(et)); int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this); + if (0 > ret) { + fprintf(stderr, "calling %s/wm_subscribe failed\n", wmAPI); + } // Set event handler if (et >= Event_Active && et <= Event_FlushDraw) { @@ -443,8 +464,15 @@ void LibWindowmanager::Impl::event(char const *et, json_object *object) { 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)); + json_object *val; + const char *label; + if (json_object_object_get_ex(object, this->kKeyDrawingName, &val)) { + label = json_object_get_string(val); + } + else { + fprintf(stderr, "Not found key \"%s\"\n", this->kKeyDrawingName); + return; + } if (this->labels.find(label) != this->labels.end()) { i->second(object); diff --git a/src/libwindowmanager.h b/src/libwindowmanager.h index 59c5ca5..83dff5f 100644 --- a/src/libwindowmanager.h +++ b/src/libwindowmanager.h @@ -38,8 +38,8 @@ public: const std::string kStrAreaSub = "sub"; /* Key for json obejct */ - constexpr static char *kKeyDrawingName = "drawing_name"; - constexpr static char *kKeyDrawingArea = "drawing_area"; + const char *kKeyDrawingName = "drawing_name"; + const char *kKeyDrawingArea = "drawing_area"; enum EventType { Event_Active = 0, |