check subscribe event
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Mon, 14 Jan 2019 01:46:06 +0000 (09:46 +0800)
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Mon, 14 Jan 2019 01:46:06 +0000 (09:46 +0800)
Change-Id: I23944d900bf88eed989e30d12a1d42aaf9a5ae7b

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

index 6c638e0..dd91e10 100644 (file)
@@ -156,11 +156,17 @@ int HS_Client::subscribe(afb_req_t request)
     const char *value = afb_req_value(request, _event);
     if(value) {
         HMI_NOTICE("homescreen-service","subscribe event %s", value);
-        event_list.insert(std::string(value));
-        if(!subscription) {
-            ret = afb_req_subscribe(request, my_event);
-            if(ret == 0) {
-                subscription = true;
+        if(!isSupportEvent(value)) {
+            HMI_NOTICE("homescreen-service","subscibe event isn't existing.");
+            ret = AFB_EVENT_BAD_REQUEST;
+        }
+        else {
+            event_list.insert(std::string(value));
+            if(!subscription) {
+                ret = afb_req_subscribe(request, my_event);
+                if(ret == 0) {
+                    subscription = true;
+                }
             }
         }
     }
@@ -404,6 +410,26 @@ bool HS_Client::checkEvent(const char* event)
         return true;
 }
 
+/**
+ * check if event is supporting
+ *
+ * #### Parameters
+ *  - event: homescreen event, tap_shortcut etc.
+ *
+ * #### Return
+ * true: support
+ * false: not fosupportund
+ *
+ */
+bool HS_Client::isSupportEvent(const char* event)
+{
+    auto ip = func_list.find(std::string(event));
+    if(ip == func_list.end())
+        return false;
+    else
+        return true;
+}
+
 /**
  * handle homescreen event
  *
index 800f1d6..5b384b1 100644 (file)
@@ -59,6 +59,7 @@ private:
         {"showInformation",     &HS_Client::showInformation}
     };
     bool checkEvent(const char* event);
+    bool isSupportEvent(const char* event);
 
 private:
     std::string my_id;