From d2098f95947dcf1ec19f5b76d2f574fb0411435d Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Thu, 31 May 2018 20:13:24 +0900 Subject: Add subscribe for client Change-Id: I9708c81275e783e4739469d069071fac11549554 Signed-off-by: Kazumasa Mitsunari --- src/wm-client.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++---------- src/wm-client.hpp | 8 ++++++++ 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/wm-client.cpp b/src/wm-client.cpp index b568817..2d440e6 100644 --- a/src/wm-client.cpp +++ b/src/wm-client.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include "wm-client.hpp" #include "hmi-debug.h" @@ -25,13 +26,16 @@ using std::vector; namespace wm { - const vector wm_events = { // Private event for applications "syncDraw", "flushDraw", "visible", "invisible", "active", "inactive", "error"}; +const vector error_description = { + "unknown-error"}; static const char key_drawing_name[] = "drawing_name"; static const char key_role[] = "role"; +static const char key_err[] = "error"; +static const char key_err_desc[] = "error_description"; WMClient::WMClient(const string &appid, unsigned layerID, unsigned surfaceID, const string &role) : layer(layerID), @@ -77,15 +81,18 @@ string WMClient::appID() return this->id; } -unsigned WMClient::surfaceID(const string &role){ - if(0 == role2surface.count(role)){ +unsigned WMClient::surfaceID(const string &role) +{ + if (0 == role2surface.count(role)) + { HMI_WARNING("wm", "invalid role"); return INVALID_SURFACE_ID; } return role2surface.at(role); } -unsigned WMClient::layerID(){ +unsigned WMClient::layerID() +{ return layer; } @@ -97,18 +104,21 @@ void WMClient::registerLayer(unsigned layerID) bool WMClient::addSurface(const string &role, unsigned surface) { HMI_DEBUG("wm", "Add role %s with surface %d", role.c_str(), surface); - if(0 != role2surface.count(role)){ + if (0 != role2surface.count(role)) + { HMI_NOTICE("wm", "override surfaceID %d with %d", role2surface[role], surface); } role2surface[role] = surface; return true; } -bool WMClient::removeSurfaceIfExist(unsigned surfaceID){ +bool WMClient::removeSurfaceIfExist(unsigned surfaceID) +{ bool ret = false; for (auto &x : role2surface) { - if(surfaceID == x.second){ + if (surfaceID == x.second) + { role2surface.erase(x.first); ret = true; break; @@ -117,7 +127,8 @@ bool WMClient::removeSurfaceIfExist(unsigned surfaceID){ return ret; } -bool WMClient::removeRole(const string& role){ +bool WMClient::removeRole(const string &role) +{ bool ret = false; if (role2surface.count(role) != 0) { @@ -127,10 +138,36 @@ bool WMClient::removeRole(const string& role){ return ret; } -void WMClient::dumpInfo(){ +bool WMClient::subscribe(afb_req req, const string &evname) +{ + int ret = afb_req_subscribe(req, event_list[evname]); + if (ret) + { + return false; + } + return true; +} + +void WMClient::emitError(WM_CLIENT_ERROR_EVENT ev) +{ + json_object *j = json_object_new_object(); + json_object_object_add(j, key_err, json_object_new_int(ev)); + json_object_object_add(j, key_err_desc, json_object_new_string(error_description[ev].c_str())); + HMI_DEBUG("wm", "error: %d, description:%s", ev, error_description[ev].c_str()); + + int ret = afb_event_push(this->event_list[key_err], j); + if (ret != 0) + { + HMI_DEBUG("wm", "afb_event_push failed: %m"); + } +} + +void WMClient::dumpInfo() +{ DUMP("APPID : %s", id.c_str()); DUMP(" LAYER : %d", layer); - for(const auto& x : role2surface){ + for (const auto &x : role2surface) + { DUMP(" ROLE : %s , SURFACE : %d", x.first.c_str(), x.second); } } diff --git a/src/wm-client.hpp b/src/wm-client.hpp index 3680d8f..4bfb60b 100644 --- a/src/wm-client.hpp +++ b/src/wm-client.hpp @@ -30,6 +30,11 @@ extern "C" namespace wm { +enum WM_CLIENT_ERROR_EVENT +{ + UNKNOWN_ERROR +}; + class WMClient { public: @@ -46,6 +51,9 @@ class WMClient bool removeSurfaceIfExist(unsigned surfaceID); bool removeRole(const std::string& role); + bool subscribe(afb_req req, const std::string &event_name); + void emitError(WM_CLIENT_ERROR_EVENT ev); + void dumpInfo(); private: -- cgit 1.2.3-korg