summaryrefslogtreecommitdiffstats
path: root/src/homescreen.cpp
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2018-10-09 10:31:06 +0800
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2018-10-17 20:10:26 +0000
commitea459cc8988c3e664c3f9d56d3a9929775d8b57b (patch)
tree0fd0fbc929a5a5b8b8eb1a9eccc0e411f5106261 /src/homescreen.cpp
parent28b7b54a65f7954c4e279e22d2ff4f49ccc39f7f (diff)
emit event to one application
changed agl-service-homescreen and libhomescreen to make agl-service-homescreen emit event to one application only. BUG-AGL: SPEC-1764 Change-Id: I87e4fc8fe900fdf9d7fde04852077c7174b8a3ba Signed-off-by: wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Diffstat (limited to 'src/homescreen.cpp')
-rw-r--r--src/homescreen.cpp101
1 files changed, 51 insertions, 50 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp
index 744535b..a3039c5 100644
--- a/src/homescreen.cpp
+++ b/src/homescreen.cpp
@@ -17,24 +17,20 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
+#include <memory>
+#include <algorithm>
#include "hs-helper.h"
#include "hmi-debug.h"
+#include "hs-clientmanager.h"
-#define COMMAND_EVENT_NUM 4
#define EVENT_SUBSCRIBE_ERROR_CODE 100
-/* To Do hash table is better */
-struct event{
- const char* name;
- struct afb_event event;
-};
-
-static struct event event_list[COMMAND_EVENT_NUM];
+const char _error[] = "error";
+const char _application_name[] = "application_name";
+const char _display_message[] = "display_message";
+const char _reply_message[] = "reply_message";
-static const char _error[] = "error";
-static const char _application_name[] = "application_name";
-static const char _display_message[] = "display_message";
-static const char _reply_message[] = "reply_message";
+static HS_ClientManager* g_client_manager = HS_ClientManager::instance();
/*
********** Method of HomeScreen Service (API) **********
@@ -67,13 +63,20 @@ static void tap_shortcut (struct afb_req request)
int ret = 0;
const char* value = afb_req_value(request, _application_name);
if (value) {
-
HMI_NOTICE("homescreen-service","request params = %s.", value);
-
- struct json_object* push_obj = json_object_new_object();
- hs_add_object_to_json_object_str( push_obj, 2,
- _application_name, value);
- afb_event_push(event_list[hs_search_event_name_index(__FUNCTION__)].event, push_obj);
+ // first step get appid from appname, next step change appname to appid
+ std::string appid(value);
+ std::transform(appid.begin(), appid.end(), appid.begin(), ::tolower);
+ HS_Client* client = g_client_manager->find(appid);
+ if(client != nullptr) {
+ if(client->tap_shortcut(value) != 0) {
+ afb_req_fail_f(request, "afb_event_push failed", "called %s.", __FUNCTION__);
+ return;
+ }
+ }
+ else {
+ // app is not started, do nothing
+ }
} else {
afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
return;
@@ -106,11 +109,12 @@ static void on_screen_message (struct afb_req request)
if (value) {
HMI_NOTICE("homescreen-service","request params = %s.", value);
-
- struct json_object* push_obj = json_object_new_object();
- hs_add_object_to_json_object_str( push_obj, 2,
- _display_message, value);
- afb_event_push(event_list[hs_search_event_name_index(__FUNCTION__)].event, push_obj);
+ for(auto m : g_client_manager->getAllClient()) {
+ if(m->on_screen_message(request, value) != 0) {
+ afb_req_fail_f(request, "afb_event_push failed", "called %s.", __FUNCTION__);
+ return;
+ }
+ }
} else {
afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
return;
@@ -143,11 +147,12 @@ static void on_screen_reply (struct afb_req request)
if (value) {
HMI_NOTICE("homescreen-service","request params = %s.", value);
-
- struct json_object* push_obj = json_object_new_object();
- hs_add_object_to_json_object_str( push_obj, 2,
- _reply_message, value);
- afb_event_push(event_list[hs_search_event_name_index(__FUNCTION__)].event, push_obj);
+ for(auto m : g_client_manager->getAllClient()) {
+ if(m->on_screen_reply(request, value) != 0) {
+ afb_req_fail_f(request, "afb_event_push failed", "called %s.", __FUNCTION__);
+ return;
+ }
+ }
} else {
afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
return;
@@ -176,18 +181,14 @@ static void subscribe(struct afb_req request)
HMI_NOTICE("homescreen-service","value is %s", value);
int ret = 0;
if(value) {
- int index = hs_search_event_name_index(value);
- if(index < 0)
- {
- HMI_NOTICE("homescreen-service","dedicated event doesn't exist");
- ret = EVENT_SUBSCRIBE_ERROR_CODE;
- }
- else
- {
- afb_req_subscribe(request, event_list[index].event);
+ std::string appid(afb_req_get_application_id(request));
+ std::transform(appid.begin(), appid.end(), appid.begin(), ::tolower);
+ if(g_client_manager->getClient(request, appid)->subscribe(request, value) != 0) {
+ afb_req_fail_f(request, "afb_req_subscribe failed", "called %s.", __FUNCTION__);
+ return;
}
}
- else{
+ else {
HMI_NOTICE("homescreen-service","Please input event name");
ret = EVENT_SUBSCRIBE_ERROR_CODE;
}
@@ -214,15 +215,18 @@ static void unsubscribe(struct afb_req request)
HMI_NOTICE("homescreen-service","value is %s", value);
int ret = 0;
if(value) {
- int index = hs_search_event_name_index(value);
- if(index < 0)
- {
- HMI_NOTICE("homescreen-service","dedicated event doesn't exist");
- ret = EVENT_SUBSCRIBE_ERROR_CODE;
+ std::string appid(afb_req_get_application_id(request));
+ std::transform(appid.begin(), appid.end(), appid.begin(), ::tolower);
+ HS_Client* client = g_client_manager->find(appid);
+ if(client != nullptr) {
+ if(client->unsubscribe(request, value) != 0) {
+ afb_req_fail_f(request, "afb_req_unsubscribe failed", "called %s.", __FUNCTION__);
+ return;
+ }
}
- else
- {
- afb_req_unsubscribe(request, event_list[index].event);
+ else {
+ HMI_NOTICE("homescreen-service","not find app's client, unsubscribe failed");
+ ret = EVENT_SUBSCRIBE_ERROR_CODE;
}
}
else{
@@ -280,10 +284,7 @@ static int init()
{
HMI_NOTICE("homescreen-service","binding init");
- for(int i = 0; i < COMMAND_EVENT_NUM; ++i) {
- event_list[i].name = evlist[i];
- event_list[i].event = afb_daemon_make_event(evlist[i]);
- }
+ g_client_manager->init();
return 0;
}