From 58d5aa69c638b5e6d59f858516385e01fe248031 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Mon, 6 Aug 2018 12:00:28 +0900 Subject: Use appid between homescreen-service and apps Use appid between hss and apps, and check event destination in libhomescreen. So these is no need compare code when recived Event_TapShortcut Event. [Patch Sets 2] Make a copy of the string returned by getenv. BUG-AGL: SPEC-1645 Change-Id: I042015ee92c4c142418b1ac15d51a9408e219757 Signed-off-by: zheng_wenlong Signed-off-by: Scott Murray --- src/libhomescreen.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp index 0462d4d..c621a80 100644 --- a/src/libhomescreen.cpp +++ b/src/libhomescreen.cpp @@ -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) { -- cgit 1.2.3-korg