use appid instead of appname in "tap_shortcut"
[src/libhomescreen.git] / src / libhomescreen.cpp
index 0462d4d..29ba7ef 100644 (file)
@@ -203,12 +203,12 @@ END:
  * When HomeScreen shortcut area is tapped, sending a event
  *
  * #### Parameters
- * - application_name [in] : Tapped application name (label)
+ * - application_id [in] : Tapped application id (label)
  *
  * #### Return
  * - Returns 0 on success or -1 in case of error.
  */
-int LibHomeScreen::tapShortcut(const char* application_name)
+int LibHomeScreen::tapShortcut(const char* application_id)
 {
        if(!sp_websock)
        {
@@ -216,8 +216,8 @@ int LibHomeScreen::tapShortcut(const char* application_name)
        }
 
        struct json_object* j_obj = json_object_new_object();
-       struct json_object* val = json_object_new_string(application_name);
-       json_object_object_add(j_obj, "application_name", val);
+       struct json_object* val = json_object_new_string(application_id);
+       json_object_object_add(j_obj, "application_id", val);
        return this->call("tap_shortcut", j_obj);
 }
 
@@ -445,8 +445,8 @@ void LibHomeScreen::on_call(void *closure, const char *api, const char *verb, st
 }
 
 /*
-* event is like "homescreen/tap_shortcut"
-* msg is like {"event":"homescreen\/tap_shortcut","data":{"application_name":"hoge"},"jtype":"afb-event"}
+* event is like "homescreen/hvac"
+* msg is like {"event":"homescreen\/hvac","data":{"type":"tap_shortcut"},"jtype":"afb-event"}
 * so you can get
        event name : struct json_object obj = json_object_object_get(msg,"event")
 */
@@ -459,7 +459,11 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
        }
 
        struct json_object* ev_contents = afb_wsj1_msg_object_j(msg);
-       struct json_object *json_data = json_object_object_get(ev_contents, "data");
+       struct json_object *json_data;
+       if(!json_object_object_get_ex(ev_contents, "data", &json_data)) {
+               HMI_ERROR("libhomescreen", "got ev_contents error.");
+               return;
+       }
 
        if(onEvent != nullptr)
        {
@@ -467,27 +471,29 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
                onEvent(ev, ev_contents);
        }
 
-       const char* event_only = strchr(event, '/');
-       if (event_only != nullptr) {
-               event_only = event_only + 1;
-       }else{
-               HMI_WARNING("libhomescreen","event_only is null.");
+       const char* event_type = nullptr;
+       struct json_object *json_event_type;
+       if(json_object_object_get_ex(json_data, "type", &json_event_type)) {
+               event_type = json_object_get_string(json_event_type);
+       }
+       else {
+               HMI_WARNING("libhomescreen","event_type is null.");
                return;
        }
 
-       if (strcasecmp(event_only, LibHomeScreen::event_list[0].c_str()) == 0) {
+       if (strcasecmp(event_type, LibHomeScreen::event_list[0].c_str()) == 0) {
                auto i = this->handlers.find(Event_TapShortcut);
                if ( i != this->handlers.end() ) {
                        i->second(json_data);
                }
        }
-       else if (strcasecmp(event_only, LibHomeScreen::event_list[1].c_str()) == 0) {
+       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_only, LibHomeScreen::event_list[2].c_str()) == 0) {
+       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);