summaryrefslogtreecommitdiffstats
path: root/src/homescreen.cpp
diff options
context:
space:
mode:
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;
}