add vui event
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>
Thu, 6 Jun 2019 06:42:08 +0000 (15:42 +0900)
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>
Thu, 6 Jun 2019 06:42:08 +0000 (15:42 +0900)
include/libhomescreen.hpp
sample/simple-egl/src/simple-egl.cpp
src/libhomescreen.cpp

index 0361fa4..bdfeb4b 100644 (file)
@@ -51,7 +51,12 @@ public:
                Event_ShowNotification,
                Event_ShowInformation,
                Event_AppListChanged,
-        Event_RegisterShortcut,
+               Event_RegisterShortcut,
+               Event_UpdateShortcut,
+               Event_SetDestination,
+               Event_CancelDestination,
+               Event_StartNavigation,
+               Event_StopNavigation,
                Event_Max
        };
 
@@ -66,6 +71,7 @@ public:
        int onScreenReply(const char* reply_message);
 
        void set_event_handler(enum EventType et, handler_func f);
+       void publishSubscription(void);
 
        void registerCallback(
                void (*event_cb)(const std::string& event, struct json_object* event_contents),
@@ -83,11 +89,12 @@ public:
        int showNotification(json_object* json);
        int showInformation(json_object* json);
        int getRunnables(void);
-       int registerShortcut(json_object* json);
-
+       int registerShortcut(const char* application_id, json_object* json);
+       int updateShortcut(const char* application_id, json_object* json);
 
 private:
        int initialize_websocket();
+       int getEventType(const char *event);
 
        void (*onEvent)(const std::string& event, struct json_object* event_contents);
        void (*onReply)(struct json_object* reply);
index aa6ea19..2027b36 100644 (file)
@@ -572,12 +572,12 @@ init_hs(LibHomeScreen* hs){
        hs->set_event_handler(LibHomeScreen::Event_ShowWindow, [hs](json_object *object){
                HMI_DEBUG("simple-egl","try to activeWindow %s ", app_name.c_str());
 
-               struct json_object *param_obj = json_object_object_get(object, hs->_keyParameter);
+               struct json_object *param_obj = json_object_object_get(object, "parameter");
                const char *area = json_object_get_string(
-                       json_object_object_get(param_obj, hs->_keyArea));
+                       json_object_object_get(param_obj, "area"));
                // Application should call LibWindowmanager::activateWindow() in showWindow handler
                if(area == nullptr)
-                       wm->activateWindow(main_role, hs->_areaNormal);
+                       wm->activateWindow(main_role, "normal.full");
                else
                        wm->activateWindow(main_role, area);
        });
@@ -653,7 +653,7 @@ main(int argc, char **argv)
 
        eglSwapBuffers(window.display->egl.dpy, window.egl_surface);
 
-       wm->activateWindow(main_role);
+       hs->publishSubscription();
 
        /* The mainloop here is a little subtle.  Redrawing will cause
         * EGL to read events so we can just call
index 9c50c86..fa22da4 100644 (file)
@@ -50,7 +50,8 @@ const std::vector<std::string> LibHomeScreen::api_list {
        std::string("showNotification"),
        std::string("showInformation"),
        std::string("getRunnables"),
-       std::string("registerShortcut")
+       std::string("registerShortcut"),
+       std::string("updateShortcut")
 };
 
 const std::vector<std::string> LibHomeScreen::event_list {
@@ -64,6 +65,11 @@ const std::vector<std::string> LibHomeScreen::event_list {
        std::string("showInformation"),
        std::string("application-list-changed"),
        std::string("registerShortcut"),
+       std::string("updateShortcut"),
+       std::string("setDestination"),
+       std::string("cancelDestination"),
+       std::string("startNavigation"),
+       std::string("stopNavigation"),
        std::string("none")
 };
 
@@ -309,40 +315,30 @@ int LibHomeScreen::onScreenReply(const char* reply_message)
 void LibHomeScreen::set_event_handler(enum EventType et, handler_func f)
 {
        if (et > Event_Min && et < Event_Max) {
-               switch (et) {
-                       case Event_ShowWindow:
-                               this->subscribe(LibHomeScreen::event_list[0]);
-                               break;
-                       case Event_OnScreenMessage:
-                               this->subscribe(LibHomeScreen::event_list[1]);
-                               break;
-                       case Event_OnScreenReply:
-                               this->subscribe(LibHomeScreen::event_list[2]);
-                               break;
-                       case Event_HideWindow:
-                               this->subscribe(LibHomeScreen::event_list[3]);
-                               break;
-                       case Event_ReplyShowWindow:
-                               this->subscribe(LibHomeScreen::event_list[4]);
-                               break;
-                       case Event_ShowNotification:
-                               this->subscribe(LibHomeScreen::event_list[5]);
-                               break;
-                       case Event_ShowInformation:
-                               this->subscribe(LibHomeScreen::event_list[6]);
-                               break;
-                       case Event_AppListChanged:
-                               this->subscribe(LibHomeScreen::event_list[7]);
-                               break;
-                       case Event_RegisterShortcut:
-                this->subscribe(LibHomeScreen::event_list[8]);
-                break;
-               }
-
                this->handlers[et] = std::move(f);
        }
 }
 
+/**
+ * This function subscribe HomeScreen event
+ *
+ * #### Parameters
+ * None
+ *
+ * #### Return
+ * - Nothing
+ *
+ * #### Note
+ * To call HomeScreen's subscribe APIs.
+ *
+ */
+void LibHomeScreen::publishSubscription(void)
+{
+       for(auto &it : handlers) {
+               this->subscribe(LibHomeScreen::event_list[it.first - 1]);
+       }
+}
+
 /**
  * This function calls the API of HomeScreen via WebSocket
  *
@@ -637,16 +633,50 @@ int LibHomeScreen::getRunnables(void)
  * - Returns 0 on success or -1 in case of error.
  *
  */
-int LibHomeScreen::registerShortcut(json_object* json)
+int LibHomeScreen::registerShortcut(const char* application_id, json_object* json)
 {
-       if(!sp_websock)
-       {
-               return -1;
-       }
+    if(!sp_websock)
+    {
+               return -1;
+    }
 
-       return this->call("registerShortcut", json);
+       struct json_object* j_obj = json_object_new_object();
+       struct json_object* val = json_object_new_string(application_id);
+       json_object_object_add(j_obj, ApplicationId, val);
+       json_object_object_add(j_obj, "parameter", json);
+
+    return this->call("registerShortcut", j_obj);
 }
 
+
+/**
+ * update shortcut to launcher
+ *
+ * Call HomeScreen Service's updateShortcut verb to update shortcut.
+ *
+ * #### Parameters
+ * - json [in] : This argument should be specified to the json parameters.
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ */
+int LibHomeScreen::updateShortcut(const char* application_id, json_object* json)
+{
+    if(!sp_websock)
+    {
+               return -1;
+    }
+
+       struct json_object* j_obj = json_object_new_object();
+       struct json_object* val = json_object_new_string(application_id);
+       json_object_object_add(j_obj, ApplicationId, val);
+       json_object_object_add(j_obj, "parameter", json);
+
+    return this->call("updateShortcut", j_obj);
+}
+
+
 /************* Callback Function *************/
 
 void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj)
@@ -699,60 +729,13 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
                return;
        }
 
-       if (strcasecmp(event_type, LibHomeScreen::event_list[0].c_str()) == 0) {
-               auto i = this->handlers.find(Event_ShowWindow);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
-               }
-       }
-       else if (strcasecmp(event_type, LibHomeScreen::event_list[1].c_str()) == 0) {
-               auto i = this->handlers.find(Event_OnScreenMessage);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
-               }
-       }
-       else if (strcasecmp(event_type, LibHomeScreen::event_list[2].c_str()) == 0) {
-               auto i = this->handlers.find(Event_OnScreenReply);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
-               }
-       }
-       else if (strcasecmp(event_type, LibHomeScreen::event_list[3].c_str()) == 0) {
-               auto i = this->handlers.find(Event_HideWindow);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
-               }
-       }
-       else if (strcasecmp(event_type, LibHomeScreen::event_list[4].c_str()) == 0) {
-               auto i = this->handlers.find(Event_ReplyShowWindow);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
-               }
-       }
-       else if (strcasecmp(event_type, LibHomeScreen::event_list[5].c_str()) == 0) {
-               auto i = this->handlers.find(Event_ShowNotification);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
-               }
-       }
-       else if (strcasecmp(event_type, LibHomeScreen::event_list[6].c_str()) == 0) {
-               auto i = this->handlers.find(Event_ShowInformation);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
-               }
-       }
-       else if (strcasecmp(event_type, LibHomeScreen::event_list[7].c_str()) == 0) {
-               auto i = this->handlers.find(Event_AppListChanged);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
+       int e_type = getEventType(event_type);
+       if(e_type < Event_Max) {
+               auto it = this->handlers.find(EventType(e_type));
+               if ( it != this->handlers.end() ) {
+                       it->second(json_data);
                }
        }
-    else if (strcasecmp(event_type, LibHomeScreen::event_list[8].c_str()) == 0) {
-        auto i = this->handlers.find(Event_RegisterShortcut);
-        if ( i != this->handlers.end() ) {
-            i->second(json_data);
-        }
-    }
 }
 
 /**
@@ -769,6 +752,20 @@ void LibHomeScreen::on_reply(void *closure, struct afb_wsj1_msg *msg)
        }
 }
 
+/*
+* convert event name to event type
+*/
+int LibHomeScreen::getEventType(const char *event)
+{
+       int i = 0;
+       for(; i < LibHomeScreen::event_list.size(); ++i) {
+               if (strcasecmp(event, LibHomeScreen::event_list[i].c_str()) == 0) {
+                       break;
+               }
+       }
+       return (i + 1) < Event_Max ? (i + 1) : Event_Max;
+}
+
 static bool has_verb(const string& verb)
 {
        HMI_DEBUG("libhomescreen","verb is %s", verb.c_str());