diff options
author | wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com> | 2019-04-02 09:13:16 +0800 |
---|---|---|
committer | wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com> | 2019-04-02 09:13:16 +0800 |
commit | 9f2e628c47c9bb431b3833cd4dd47ddc588d056c (patch) | |
tree | 648a92804497b5b9d33d162102688ae9196765c9 | |
parent | a7e49d93b4dd03f8ce3b77f831f9293ba5a3de01 (diff) |
try to use afb_api_event_handler_addsandbox/wangzhiqiang/jira2292
Change-Id: I49ecdd34d1c4493065fa7767210a762013118526
-rw-r--r-- | src/homescreen.cpp | 11 | ||||
-rw-r--r-- | src/hs-proxy.cpp | 20 | ||||
-rw-r--r-- | src/hs-proxy.h | 29 |
3 files changed, 60 insertions, 0 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp index c02f62b..7b78c1a 100644 --- a/src/homescreen.cpp +++ b/src/homescreen.cpp @@ -537,6 +537,13 @@ static int preinit(afb_api_t api) return 0; } +const char _wm_screenUpdated[] = "windowmanager/screenUpdated"; +static void callback(void *closure, const char *event, struct json_object *args, afb_api_t api) +{ + afb_api_verbose(api, 5, NULL, __LINE__, __FUNCTION__, "the handler received the event %s(%s)", + event, json_object_get_string(args)); +} + /** * homescreen binding init function * @@ -564,6 +571,10 @@ static int init(afb_api_t api) return -1; } + HS_WmProxy wm; + wm.subscribe(api, HS_WmProxy::Event_ScreenUpdated); + afb_api_event_handler_add(api, _wm_screenUpdated, callback, nullptr); + return g_hs_instance->init(api); } diff --git a/src/hs-proxy.cpp b/src/hs-proxy.cpp index f0ee5f0..ec730cb 100644 --- a/src/hs-proxy.cpp +++ b/src/hs-proxy.cpp @@ -17,6 +17,8 @@ #include "hs-proxy.h" const char _afm_main[] = "afm-main"; +const char _windowmanager[] = "windowmanager"; +const char _event[] = "event"; /** @@ -131,4 +133,22 @@ void HS_AfmMainProxy::start(afb_req_t request, const std::string &id) { struct json_object *args = json_object_new_string(id.c_str()); api_call(request->api, _afm_main, __FUNCTION__, args); +} + +/** + * subscribe windowmanager event + * + * #### Parameters + * - api : the api serving the request + * - event : windowmanager event + * + * #### Return + * None + * + */ +void HS_WmProxy::subscribe(afb_api_t api, EventType event) +{ + struct json_object* push_obj = json_object_new_object(); + json_object_object_add(push_obj, _event, json_object_new_int(event)); + api_call(api, _windowmanager, "wm_subscribe", push_obj); }
\ No newline at end of file diff --git a/src/hs-proxy.h b/src/hs-proxy.h index 8741e49..a6d84aa 100644 --- a/src/hs-proxy.h +++ b/src/hs-proxy.h @@ -31,4 +31,33 @@ struct HS_AfmMainProxy { void start(afb_req_t request, const std::string &id); }; +class HS_WmProxy { +public: + HS_WmProxy() = default; + ~HS_WmProxy() = default; + + enum EventType + { + Event_Val_Min = 0, + + Event_Active = Event_Val_Min, + Event_Inactive, + + Event_Visible, + Event_Invisible, + + Event_SyncDraw, + Event_FlushDraw, + + Event_ScreenUpdated, + + Event_Error, + + Event_Val_Max = Event_Error, + }; + + // asynchronous call, reply in callback function + void subscribe(afb_api_t api, EventType event); +}; + #endif // HOMESCREEN_PROXY_H
\ No newline at end of file |