Use appid between homescreen-service and apps
[src/libhomescreen.git] / src / libhomescreen.cpp
index 0462d4d..c621a80 100644 (file)
@@ -115,6 +115,7 @@ LibHomeScreen::~LibHomeScreen()
 int LibHomeScreen::init(const int port, const string& token)
 {
        int ret = 0;
+
        if(port > 0 && token.size() > 0)
        {
                mport = port;
@@ -134,6 +135,16 @@ int LibHomeScreen::init(const int port, const string& token)
                HMI_DEBUG("libhomescreen","Initialized");
        }
 
+       mapp_id = std::getenv("AFM_ID");
+       if(mapp_id.size()) {
+               mapp_id.erase(mapp_id.find('@'));
+               HMI_DEBUG("libhomescreen","My application id is: %s.", mapp_id);
+       }
+       else
+       {
+               HMI_ERROR("libhomescreen","Failed to get my application id");
+       }
+
        return ret;
 }
 
@@ -203,12 +214,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
  *
  * #### 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 +227,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);
 }
 
@@ -446,14 +457,12 @@ 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"}
+* msg is like {"event":"homescreen\/tap_shortcut","data":{"application_id":"hoge"},"jtype":"afb-event"}
 * so you can get
        event name : struct json_object obj = json_object_object_get(msg,"event")
 */
 void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)
 {
-       HMI_DEBUG("libhomescreen","event: (%s) msg: (%s).", event, afb_wsj1_msg_object_s(msg));
-
        if (strstr(event, API) == NULL) {
                return;
        }
@@ -476,9 +485,16 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
        }
 
        if (strcasecmp(event_only, LibHomeScreen::event_list[0].c_str()) == 0) {
-               auto i = this->handlers.find(Event_TapShortcut);
-               if ( i != this->handlers.end() ) {
-                       i->second(json_data);
+               struct json_object *j_id;
+               json_object_object_get_ex(json_data, "application_id", &j_id);
+               const char* app_id = json_object_get_string(j_id);
+
+               if(!strcasecmp(app_id, mapp_id.c_str())) {
+                       HMI_DEBUG("libhomescreen","send Event_TapShortcut to: (%s).", mapp_id.c_str());
+                       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) {