aboutsummaryrefslogtreecommitdiffstats
path: root/src/homescreen.cpp
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-01-16 10:54:43 +0800
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-01-16 10:55:06 +0800
commit53ae85dc62875fc92f1d24e25359beda8787826d (patch)
tree71bb67f2d9f3c4e07aa8902d589c75eebc2b75ee /src/homescreen.cpp
parent83cc1aeb7dcb0ce030a24f9aa079bb15bc2ef60a (diff)
Improve homescreen-service
1.Improve class cohesion and reduce public interface number 2.Unified event pattern BUG-AGL: SPEC-2120 Change-Id: I4c5066be2deaf2b809af66cb5a8acdc5bffa5a23 Signed-off-by: wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Diffstat (limited to 'src/homescreen.cpp')
-rw-r--r--src/homescreen.cpp232
1 files changed, 131 insertions, 101 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp
index fce25ee..e921feb 100644
--- a/src/homescreen.cpp
+++ b/src/homescreen.cpp
@@ -58,17 +58,25 @@ static void pingSample(afb_req_t request)
static void tap_shortcut (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->tap_shortcut(request);
- if (ret != 0) {
- afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
- return;
+ int ret = 0;
+ const char* value = afb_req_value(request, _application_id);
+ if (value) {
+ HMI_NOTICE("homescreen-service","request appid = %s.", value);
+ ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
+ }
+ else {
+ ret = AFB_EVENT_BAD_REQUEST;
}
- // response to HomeScreen
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success(request, res, "afb_event_push event [tap_shortcut]");
+ if (ret) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [tap_shortcut]");
+ }
}
/**
@@ -85,18 +93,16 @@ static void tap_shortcut (afb_req_t request)
static void on_screen_message (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
-
- int ret = g_client_manager->on_screen_message(request);
- if (ret != 0) {
- afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
- return;
+ int ret = g_client_manager->handleRequest(request, __FUNCTION__);
+ if (ret) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [on_screen_message]");
}
-
- // response to HomeScreen
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success(request, res, "afb_event_push event [on_screen_message]");
}
/**
@@ -113,18 +119,16 @@ static void on_screen_message (afb_req_t request)
static void on_screen_reply (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
-
- int ret = g_client_manager->on_screen_reply(request);
- if (ret != 0) {
- afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
- return;
+ int ret = g_client_manager->handleRequest(request, __FUNCTION__);
+ if (ret) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [on_screen_reply]");
}
-
- // response to HomeScreen
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success(request, res, "afb_event_push event [on_screen_reply]");
}
/**
@@ -140,18 +144,24 @@ static void on_screen_reply (afb_req_t request)
static void subscribe(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
+ int ret = 0;
+ std::string req_appid = std::move(get_application_id(request));
+ if(!req_appid.empty()) {
+ ret = g_client_manager->handleRequest(request, __FUNCTION__, req_appid.c_str());
+ }
+ else {
+ ret = AFB_EVENT_BAD_REQUEST;
+ }
- int ret = g_client_manager->subscribe(request);
if(ret) {
- afb_req_fail_f(request, "afb_req_subscribe failed", "called %s.", __FUNCTION__);
- return;
+ afb_req_fail_f(request, "afb_req_subscribe failed", "called %s.", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success_f(request, res, "homescreen binder subscribe.");
}
-
- /*create response json object*/
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success_f(request, res, "homescreen binder subscribe.");
}
/**
@@ -167,18 +177,24 @@ static void subscribe(afb_req_t request)
static void unsubscribe(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
+ int ret = 0;
+ std::string req_appid = std::move(get_application_id(request));
+ if(!req_appid.empty()) {
+ ret = g_client_manager->handleRequest(request, __FUNCTION__, req_appid.c_str());
+ }
+ else {
+ ret = AFB_EVENT_BAD_REQUEST;
+ }
- int ret = g_client_manager->unsubscribe(request);
if(ret) {
- afb_req_fail_f(request, "afb_req_unsubscribe failed", "called %s.", __FUNCTION__);
- return;
+ afb_req_fail_f(request, "afb_req_unsubscribe failed", "called %s.", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success_f(request, res, "homescreen binder unsubscribe success.");
}
-
- /*create response json object*/
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success_f(request, res, "homescreen binder unsubscribe success.");
}
/**
@@ -194,18 +210,24 @@ static void unsubscribe(afb_req_t request)
static void showWindow(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
-
- int ret = g_client_manager->showWindow(request);
- if (ret != 0) {
- afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
- return;
+ int ret = 0;
+ const char* value = afb_req_value(request, _application_id);
+ if (value) {
+ ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
+ }
+ else {
+ ret = AFB_EVENT_BAD_REQUEST;
}
- // response to HomeScreen
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success(request, res, "afb_event_push event [showWindow]");
+ if (ret) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [showWindow]");
+ }
}
/**
@@ -221,18 +243,24 @@ static void showWindow(afb_req_t request)
static void hideWindow(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
-
- int ret = g_client_manager->hideWindow(request);
- if (ret != 0) {
- afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
- return;
+ int ret = 0;
+ const char* value = afb_req_value(request, _application_id);
+ if (value) {
+ ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
+ }
+ else {
+ ret = AFB_EVENT_BAD_REQUEST;
}
- // response to HomeScreen
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success(request, res, "afb_event_push event [hideWindow]");
+ if (ret) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [hideWindow]");
+ }
}
/**
@@ -248,18 +276,24 @@ static void hideWindow(afb_req_t request)
static void replyShowWindow(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
-
- int ret = g_client_manager->replyShowWindow(request);
- if (ret != 0) {
- afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
- return;
+ int ret = 0;
+ const char* value = afb_req_value(request, _application_id);
+ if (value) {
+ ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
+ }
+ else {
+ ret = AFB_EVENT_BAD_REQUEST;
}
- // response to HomeScreen
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success(request, res, "afb_event_push event [replyShowWindow]");
+ if (ret) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [replyShowWindow]");
+ }
}
/**
@@ -277,18 +311,16 @@ static void replyShowWindow(afb_req_t request)
static void showNotification(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
-
- int ret = g_client_manager->showNotification(request);
- if (ret != 0) {
- afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
- return;
+ int ret = g_client_manager->handleRequest(request, __FUNCTION__, "homescreen");
+ if (ret) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [showNotification]");
}
-
- // response to Application
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success(request, res, "afb_event_push event [showNotification]");
}
/**
@@ -306,18 +338,16 @@ static void showNotification(afb_req_t request)
static void showInformation(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
-
- int ret = g_client_manager->showInformation(request);
- if (ret != 0) {
- afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
- return;
+ int ret = g_client_manager->handleRequest(request, __FUNCTION__, "homescreen");
+ if (ret) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+ }
+ else {
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [showInformation]");
}
-
- // response to Application
- struct json_object *res = json_object_new_object();
- hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
- _error, ret);
- afb_req_success(request, res, "afb_event_push event [showInformation]");
}
/*