diff options
-rw-r--r-- | src/homescreen.cpp | 144 | ||||
-rw-r--r-- | src/hs-client.cpp | 182 | ||||
-rw-r--r-- | src/hs-client.h | 5 | ||||
-rw-r--r-- | src/hs-clientmanager.cpp | 146 | ||||
-rw-r--r-- | src/hs-clientmanager.h | 5 | ||||
-rw-r--r-- | src/hs-helper.cpp | 5 | ||||
-rw-r--r-- | src/hs-helper.h | 2 |
7 files changed, 489 insertions, 0 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp index c6b4cdf..fce25ee 100644 --- a/src/homescreen.cpp +++ b/src/homescreen.cpp @@ -181,6 +181,145 @@ static void unsubscribe(afb_req_t request) afb_req_success_f(request, res, "homescreen binder unsubscribe success."); } +/** + * showWindow event + * + * #### Parameters + * - request : the request + * + * #### Return + * None + * + */ +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; + } + + // 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]"); +} + +/** + * hideWindow event + * + * #### Parameters + * - request : the request + * + * #### Return + * None + * + */ +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; + } + + // 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]"); +} + +/** + * replyShowWindow event + * + * #### Parameters + * - request : the request + * + * #### Return + * None + * + */ +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; + } + + // 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]"); +} + +/** + * showNotification event + * + * the contents to homescreen which display at top area. + * + * #### Parameters + * - request : the request + * + * #### Return + * None + * + */ +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; + } + + // 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]"); +} + +/** + * showInformation event + * + * the contents to homescreen which display at bottom area. + * + * #### Parameters + * - request : the request + * + * #### Return + * None + * + */ +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; + } + + // 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]"); +} + /* * array of the verbs exported to afb-daemon */ @@ -188,10 +327,15 @@ static const afb_verb_t verbs[]= { /* VERB'S NAME FUNCTION TO CALL */ { .verb="ping", .callback=pingSample }, { .verb="tap_shortcut", .callback=tap_shortcut }, + { .verb="showWindow", .callback=showWindow }, + { .verb="hideWindow", .callback=hideWindow }, + { .verb="replyShowWindow", .callback=replyShowWindow }, { .verb="on_screen_message", .callback=on_screen_message }, { .verb="on_screen_reply", .callback=on_screen_reply }, { .verb="subscribe", .callback=subscribe }, { .verb="unsubscribe", .callback=unsubscribe }, + { .verb="showNotification", .callback=showNotification }, + { .verb="showInformation", .callback=showInformation }, {NULL } /* marker for end of the array */ }; diff --git a/src/hs-client.cpp b/src/hs-client.cpp index 7da2cda..26e43bb 100644 --- a/src/hs-client.cpp +++ b/src/hs-client.cpp @@ -19,6 +19,11 @@ #include "hmi-debug.h" static const char _type[] = "type"; +static const char _text[] = "text"; +static const char _info[] = "info"; +static const char _icon[] = "icon"; +static const char _parameter[] = "parameter"; +static const char _replyto[] = "replyto"; /** * HS_Client construction function @@ -181,3 +186,180 @@ bool HS_Client::checkEvent(const char* event) else return true; } + +/** + * showWindow event + * + * input contents : {"application_id":"the appid that want to display", "parameter":{"area": "display area", ...}} + * + * #### Parameters + * - request : the request + * - appid : the appid that want to display + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_Client::showWindow(afb_req_t request, const char* appid) +{ + if(!checkEvent(__FUNCTION__)) + return 0; + + HMI_NOTICE("homescreen-service","%s application_id = %s.", __FUNCTION__, appid); + struct json_object* push_obj = json_object_new_object(); + hs_add_object_to_json_object_str( push_obj, 4, _application_id, appid, _type, __FUNCTION__); + const char* param = afb_req_value(request, _parameter); + if(param) { + const char* req_appid = afb_req_get_application_id(request); + struct json_object* param_obj = json_tokener_parse(param); + json_object_object_add(param_obj, _replyto, json_object_new_string(req_appid)); + json_object_object_add(push_obj, _parameter, param_obj); + } + else { + HMI_ERROR("homescreen-service","please input correct parameter."); + return AFB_EVENT_BAD_REQUEST; + } + afb_event_push(my_event, push_obj); + return 0; +} + +/** + * hideWindow event + * + * input contents : {"application_id":"the appid that want to hide"} + * + * #### Parameters + * - request : the request + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_Client::hideWindow(afb_req_t request) +{ + if(!checkEvent(__FUNCTION__)) + return 0; + + HMI_NOTICE("homescreen-service","%s application_id = %s.", __FUNCTION__); + const char* req_appid = afb_req_get_application_id(request); + struct json_object* push_obj = json_object_new_object(); + hs_add_object_to_json_object_str( push_obj, 4, _application_id, req_appid, + _type, __FUNCTION__); + afb_event_push(my_event, push_obj); + return 0; +} + +/** + * replyShowWindow event + * + * input contens : {"application_id": "the appid that want to reply", "parameter": {...}} + * + * #### Parameters + * - request : the request + * - appid : the appid that want to reply + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_Client::replyShowWindow(afb_req_t request, const char* appid) +{ + if(!checkEvent(__FUNCTION__)) + return 0; + + HMI_NOTICE("homescreen-service","%s application_id = %s.", __FUNCTION__, appid); + struct json_object* push_obj = json_object_new_object(); + hs_add_object_to_json_object_str( push_obj, 4, _application_id, appid, _type, __FUNCTION__); + const char* param = afb_req_value(request, _parameter); + if(param) { + json_object_object_add(push_obj, _parameter, json_tokener_parse(param)); + } + else { + HMI_ERROR("homescreen-service","please input correct parameter."); + return AFB_EVENT_BAD_REQUEST; + } + + afb_event_push(my_event, push_obj); + return 0; +} + +/** + * showNotification event + * + * input contents : {"icon": "icon path", "text": "message contents"} + * + * #### Parameters + * - request : the request + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_Client::showNotification(afb_req_t request) +{ + int ret = 0; + const char *value = afb_req_value(request, _text); + if(value) { + HMI_NOTICE("homescreen-service","text is %s", value); + const char* appid = afb_req_get_application_id(request); + struct json_object* param_obj = json_object_new_object(); + const char *icon = afb_req_value(request, _icon); + if(icon) { + json_object_object_add(param_obj, _icon, json_object_new_string(icon)); + json_object_object_add(param_obj, _text, json_object_new_string(value)); + struct json_object* push_obj = json_object_new_object(); + hs_add_object_to_json_object_str( push_obj, 4, _application_id, appid, _type, __FUNCTION__); + json_object_object_add(push_obj, _parameter, param_obj); + afb_event_push(my_event, push_obj); + } + else { + HMI_NOTICE("homescreen-service","please input icon."); + ret = AFB_REQ_SHOWNOTIFICATION_ERROR; + } + } + else { + HMI_NOTICE("homescreen-service","please input text."); + ret = AFB_REQ_SHOWNOTIFICATION_ERROR; + } + + return ret; +} + +/** + * showInformation event + * + * input contents : {"info": "information contents"} + * + * #### Parameters + * - request : the request + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_Client::showInformation(afb_req_t request) +{ + int ret = 0; + const char *value = afb_req_value(request, _info); + if(value) { + HMI_NOTICE("homescreen-service","info is %s", value); + const char* appid = afb_req_get_application_id(request); + struct json_object* param_obj = json_object_new_object(); + json_object_object_add(param_obj, _info, json_object_new_string(value)); + struct json_object* push_obj = json_object_new_object(); + hs_add_object_to_json_object_str( push_obj, 4, _application_id, appid, _type, __FUNCTION__); + json_object_object_add(push_obj, _parameter, param_obj); + afb_event_push(my_event, push_obj); + } + else { + HMI_NOTICE("homescreen-service","please input information."); + ret = AFB_REQ_SHOWINFORMATION_ERROR; + } + + return ret; +} diff --git a/src/hs-client.h b/src/hs-client.h index 2564587..16fa39c 100644 --- a/src/hs-client.h +++ b/src/hs-client.h @@ -31,10 +31,15 @@ public: ~HS_Client(); int tap_shortcut(const char* appid); + int showWindow(afb_req_t request, const char* appid); + int hideWindow(afb_req_t request); + int replyShowWindow(afb_req_t request, const char* appid); int on_screen_message (afb_req_t request, const char* message); int on_screen_reply (afb_req_t request, const char* message); int subscribe(afb_req_t request, const char* event); int unsubscribe(afb_req_t request, const char* event); + int showNotification(afb_req_t request); + int showInformation(afb_req_t request); private: bool checkEvent(const char* event); diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp index 15897b7..ba29326 100644 --- a/src/hs-clientmanager.cpp +++ b/src/hs-clientmanager.cpp @@ -17,6 +17,8 @@ #include "hs-clientmanager.h" #include "hmi-debug.h" +static const char _homescreen[] = "homescreen"; + HS_ClientManager* HS_ClientManager::me = nullptr; static void cbRemoveClientCtxt(void *data) @@ -309,3 +311,147 @@ int HS_ClientManager::unsubscribe(afb_req_t request) } return ret; } + +/** + * showWindow event + * + * #### Parameters + * - request : the request + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_ClientManager::showWindow(afb_req_t request) +{ + int ret = 0; + const char* value = afb_req_value(request, _application_id); + if (value) { + HMI_NOTICE("homescreen-service","request params = %s.", value); + std::lock_guard<std::mutex> lock(this->mtx); + auto ip = client_list.find(std::string(value)); + if(ip != client_list.end()) { + ret = ip->second->showWindow(request, value); + } + } + else { + HMI_NOTICE("homescreen-service","Please input application_id"); + ret = AFB_EVENT_BAD_REQUEST; + } + return ret; +} + +/** + * hideWindow event + * + * #### Parameters + * - request : the request + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_ClientManager::hideWindow(afb_req_t request) +{ + int ret = 0; + const char* value = afb_req_value(request, _application_id); + if (value) { + HMI_NOTICE("homescreen-service","request params = %s.", value); + std::lock_guard<std::mutex> lock(this->mtx); + auto ip = client_list.find(std::string(value)); + if(ip != client_list.end()) { + ret = ip->second->hideWindow(request); + } + } + else { + HMI_NOTICE("homescreen-service","Please input application_id"); + ret = AFB_EVENT_BAD_REQUEST; + } + return ret; +} + +/** + * replyShowWindow event + * + * #### Parameters + * - request : the request + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_ClientManager::replyShowWindow(afb_req_t request) +{ + int ret = 0; + const char* value = afb_req_value(request, _application_id); + if (value) { + HMI_NOTICE("homescreen-service","request params = %s.", value); + std::lock_guard<std::mutex> lock(this->mtx); + auto ip = client_list.find(std::string(value)); + if(ip != client_list.end()) { + ret = ip->second->replyShowWindow(request, value); + } + } + else { + HMI_NOTICE("homescreen-service","Please input application_id"); + ret = AFB_EVENT_BAD_REQUEST; + } + return ret; +} + +/** + * showNotification event + * + * #### Parameters + * - request : the request + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_ClientManager::showNotification(afb_req_t request) +{ + int ret = 0; + std::lock_guard<std::mutex> lock(this->mtx); + auto ip = client_list.find(_homescreen); + if(ip != client_list.end()) { + ret = ip->second->showNotification(request); + } + else { + HMI_NOTICE("homescreen-service","not exist sessiion with homescreen"); + ret = AFB_REQ_SHOWNOTIFICATION_ERROR; + } + + return ret; +} + +/** + * showInformation event + * + * #### Parameters + * - request : the request + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_ClientManager::showInformation(afb_req_t request) +{ + int ret = 0; + std::lock_guard<std::mutex> lock(this->mtx); + auto ip = client_list.find(_homescreen); + if(ip != client_list.end()) { + ret = ip->second->showInformation(request); + } + else { + HMI_NOTICE("homescreen-service","not exist sessiion with homescreen"); + ret = AFB_REQ_SHOWINFORMATION_ERROR; + } + + return ret; +} diff --git a/src/hs-clientmanager.h b/src/hs-clientmanager.h index 5258090..64ca03c 100644 --- a/src/hs-clientmanager.h +++ b/src/hs-clientmanager.h @@ -48,10 +48,15 @@ public: void removeClientCtxt(void *data); int tap_shortcut(afb_req_t request); + int showWindow(afb_req_t request); + int hideWindow(afb_req_t request); + int replyShowWindow(afb_req_t request); int on_screen_message(afb_req_t request); int on_screen_reply(afb_req_t request); int subscribe(afb_req_t request); int unsubscribe(afb_req_t request); + int showNotification(afb_req_t request); + int showInformation(afb_req_t request); private: HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid); diff --git a/src/hs-helper.cpp b/src/hs-helper.cpp index 2d8ab7a..07597b7 100644 --- a/src/hs-helper.cpp +++ b/src/hs-helper.cpp @@ -23,6 +23,11 @@ const char* evlist[] = { "tap_shortcut", "on_screen_message", "on_screen_reply", + "showWindow", + "hideWindow", + "replyShowWindow", + "showNotification", + "showInformation", "reserved" }; diff --git a/src/hs-helper.h b/src/hs-helper.h index ff8579a..c01e49a 100644 --- a/src/hs-helper.h +++ b/src/hs-helper.h @@ -23,6 +23,8 @@ #define AFB_EVENT_BAD_REQUEST 100 #define AFB_REQ_SUBSCRIBE_ERROR 101 #define AFB_REQ_UNSUBSCRIBE_ERROR 102 +#define AFB_REQ_SHOWNOTIFICATION_ERROR 103 +#define AFB_REQ_SHOWINFORMATION_ERROR 104 typedef enum REQ_ERROR { |