try to use afb_api_event_handler_add sandbox/wangzhiqiang/jira2292
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Tue, 2 Apr 2019 01:13:16 +0000 (09:13 +0800)
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Tue, 2 Apr 2019 01:13:16 +0000 (09:13 +0800)
Change-Id: I49ecdd34d1c4493065fa7767210a762013118526

src/homescreen.cpp
src/hs-proxy.cpp
src/hs-proxy.h

index c02f62b..7b78c1a 100644 (file)
@@ -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);
 }
 
index f0ee5f0..ec730cb 100644 (file)
@@ -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
index 8741e49..a6d84aa 100644 (file)
@@ -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