add registerShortcut
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Fri, 12 Apr 2019 09:44:21 +0000 (17:44 +0800)
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Fri, 12 Apr 2019 09:44:21 +0000 (17:44 +0800)
Change-Id: I4bd793378aa1428c8d88a7bdfdb1652b0e3d1f9d

src/homescreen.cpp
src/hs-client.cpp
src/hs-client.h
src/hs-helper.cpp

index e921feb..7bada37 100644 (file)
@@ -350,6 +350,39 @@ static void showInformation(afb_req_t request)
     }
 }
 
+/**
+ * registerShortcut event
+ *
+ * #### Parameters
+ *  - value  : the json contents to MenuBar.
+ *    {"application_id":"homescreen","parameter":{"shortcut_id":"dashboard@0.1","shortcut_name":"Dashboard","postion": 1}}
+ *
+ * #### Return
+ * None
+ *
+ */
+static void registerShortcut(afb_req_t request)
+{
+    int ret = 0;
+    const char* value = afb_req_value(request, _application_id);
+    if (value) {
+        ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
+    }
+    else {
+        ret = AFB_EVENT_BAD_REQUEST;
+    }
+
+    if (ret) {
+        afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+    }
+    else {
+        struct json_object *res = json_object_new_object();
+        hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+          _error,  ret);
+        afb_req_success(request, res, "afb_event_push event [registerShortcut]");
+    }
+}
+
 /*
  * array of the verbs exported to afb-daemon
  */
@@ -366,6 +399,7 @@ static const afb_verb_t verbs[]= {
     { .verb="unsubscribe",       .callback=unsubscribe            },
     { .verb="showNotification",  .callback=showNotification       },
     { .verb="showInformation",   .callback=showInformation        },
+    { .verb="registerShortcut",  .callback=registerShortcut       },
     {NULL } /* marker for end of the array */
 };
 
index f508f3d..607d016 100644 (file)
@@ -38,7 +38,8 @@ const std::unordered_map<std::string, HS_Client::func_handler> HS_Client::func_l
     {"subscribe",           &HS_Client::subscribe},
     {"unsubscribe",         &HS_Client::unsubscribe},
     {"showNotification",    &HS_Client::showNotification},
-    {"showInformation",     &HS_Client::showInformation}
+    {"showInformation",     &HS_Client::showInformation},
+    {"registerShortcut",    &HS_Client::registerShortcut},
 };
 
 /**
@@ -404,6 +405,35 @@ int HS_Client::showInformation(afb_req_t request)
     return ret;
 }
 
+/**
+ * registerShortcut event
+ *
+ * #### Parameters
+ *  - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_Client::registerShortcut(afb_req_t request)
+{
+    int ret = 0;
+    const char *value = afb_req_value(request, _parameter);
+    if(value) {
+        struct json_object* push_obj = json_object_new_object();
+        hs_add_object_to_json_object_str( push_obj, 4, _application_id, my_id.c_str(), _type, __FUNCTION__);
+        json_object_object_add(push_obj, _parameter, json_tokener_parse(value));
+        afb_event_push(my_event, push_obj);
+    }
+    else {
+        HMI_WARNING("homescreen-service","please input parameters.");
+        ret = AFB_EVENT_BAD_REQUEST;
+    }
+
+    return ret;
+}
+
 /**
  * check if client subscribe event
  *
index ac4d004..70338de 100644 (file)
@@ -44,6 +44,7 @@ private:
     int unsubscribe(afb_req_t request);
     int showNotification(afb_req_t request);
     int showInformation(afb_req_t request);
+    int registerShortcut(afb_req_t request);
 
     typedef int (HS_Client::*func_handler)(afb_req_t);
     static const std::unordered_map<std::string, func_handler> func_list;
index d0f5713..11feb09 100644 (file)
@@ -28,6 +28,7 @@ const char* evlist[] = {
     "replyShowWindow",
     "showNotification",
     "showInformation",
+    "registerShortcut",
     "reserved"
   };