From 618af66611627c1248303b1c832f85718eee4cdd Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Fri, 3 Aug 2018 21:14:25 +0900 Subject: Add error event Change-Id: I774a364cdb3cb1bce38ceab43c5abdab1434dae8 Signed-off-by: Kazumasa Mitsunari --- src/libwindowmanager.cpp | 32 ++++++++++++++++++++++++++++++++ src/libwindowmanager.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp index 551ef58..5ed4def 100644 --- a/src/libwindowmanager.cpp +++ b/src/libwindowmanager.cpp @@ -77,6 +77,7 @@ class LibWindowmanager::Impl { void setSyncDrawHandler(sync_draw_handler f); void setFlushDrawHandler(flush_draw_handler f); void setScreenUpdatedHandler(screen_update_handler f); + void setErrorHandler(error_handler f); Impl(); ~Impl(); @@ -102,6 +103,7 @@ private: sync_draw_handler _on_sync_draw = nullptr; flush_draw_handler _on_flush_draw = nullptr; screen_update_handler _on_screen_updated = nullptr; + error_handler _on_error = nullptr; }; namespace { @@ -660,6 +662,7 @@ void LibWindowmanager::Impl::setFlushDrawHandler(flush_draw_handler f) { } this->_on_flush_draw = f; } + void LibWindowmanager::Impl::setScreenUpdatedHandler(screen_update_handler f) { struct json_object* j = json_object_new_object(); json_object_object_add(j, "event", json_object_new_int(Event_ScreenUpdated)); @@ -672,6 +675,18 @@ void LibWindowmanager::Impl::setScreenUpdatedHandler(screen_update_handler f) { this->_on_screen_updated = f; } +void LibWindowmanager::Impl::setErrorHandler(error_handler f) { + struct json_object* j = json_object_new_object(); + json_object_object_add(j, "event", json_object_new_int(Event_Error)); + + int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this); + if (0 > ret) { + HMI_ERROR("libwm", "Failed to subscribe event"); + return; + } + this->_on_error = f; +} + namespace { std::pair make_event_type(char const *et) { // Event have the form "$API/$EVENT", just try to find the first / and @@ -844,6 +859,18 @@ void LibWindowmanager::Impl::event(char const *et, json_object *object) { return _on_screen_updated(id_list); } break; + case Event_Error : + if(_on_error) { + // emit this case + json_object_object_get_ex(object, "error", &j_val); + int error = json_object_get_int(j_val); + json_object_object_get_ex(object, "errorDescription", &j_val); + const char* desc = json_object_get_string(j_val); + return _on_error(error, desc); + } + break; + default : + break; } auto i = this->handlers.find(oet.second); @@ -1057,6 +1084,11 @@ void LibWindowmanager::setScreenUpdatedHandler(screen_update_handler f) { return this->d->setScreenUpdatedHandler(f); } +void LibWindowmanager::setErrorHandler(error_handler f) { + return this->d->setErrorHandler(f); +} + + LibWindowmanager::LibWindowmanager() : d(new Impl) {} LibWindowmanager::~LibWindowmanager() { delete d; } diff --git a/src/libwindowmanager.h b/src/libwindowmanager.h index fe3b204..0f6dbc4 100644 --- a/src/libwindowmanager.h +++ b/src/libwindowmanager.h @@ -81,6 +81,7 @@ public: using sync_draw_handler = std::function; using flush_draw_handler= std::function; using screen_update_handler = std::function&)>; + using error_handler = std::function; /* DrawingArea name (usage: {layout}.{area}) */ const std::string kStrLayoutNormal = "normal"; @@ -131,6 +132,7 @@ public: void setSyncDrawHandler(sync_draw_handler f); void setFlushDrawHandler(flush_draw_handler f); void setScreenUpdatedHandler(screen_update_handler f); + void setErrorHandler(error_handler f); // Backward Compatible API int requestSurface(json_object *object); -- cgit 1.2.3-korg