diff options
author | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-08-03 21:14:25 +0900 |
---|---|---|
committer | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-08-03 21:15:25 +0900 |
commit | 618af66611627c1248303b1c832f85718eee4cdd (patch) | |
tree | b512befba88cdc97193b6a6624ca8a30a05393ac | |
parent | f5c2151f6ebcfc71d499cf16e454cade434b2e07 (diff) |
Add error event
Change-Id: I774a364cdb3cb1bce38ceab43c5abdab1434dae8
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r-- | src/libwindowmanager.cpp | 32 | ||||
-rw-r--r-- | src/libwindowmanager.h | 2 |
2 files changed, 34 insertions, 0 deletions
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<bool, LibWindowmanager::EventType> 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<void(const char*, const char*, const Rect&)>; using flush_draw_handler= std::function<void(const char*)>; using screen_update_handler = std::function<void(const std::vector<std::string>&)>; + using error_handler = std::function<void(int err, const std::string&)>; /* 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); |