From c0146077906057bf97688a617870228eaad0cf54 Mon Sep 17 00:00:00 2001 From: wang_zhiqiang Date: Wed, 14 Nov 2018 11:14:04 +0800 Subject: add new features in homescreen-service and homescreen homescreen-service: add five verbs. 1.showWindow: instead of tap_shortcut and show onscreen. 2.hideWindow: used when want to hide onscreen. 3.replyShowWindow: used when post onscreen reply information to application. 4.showNotification: used by application who want to display notification on homescreen top area. 5.showInformation: used by application who want to display information on homescreen botton area. homescreen: 1.add fullscreen transfer button. 2.display notification and information. Bug-AGL: SPEC-1931 Change-Id: Ie0753fe0656282b1ff8c04dcef625f2a4154edde Signed-off-by: wang_zhiqiang --- src/libhomescreen.cpp | 210 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 197 insertions(+), 13 deletions(-) (limited to 'src/libhomescreen.cpp') diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp index 29ba7ef..84e3472 100644 --- a/src/libhomescreen.cpp +++ b/src/libhomescreen.cpp @@ -33,6 +33,7 @@ using namespace std; static bool has_verb(const string& verb); static const char API[] = "homescreen"; +static const char ApplicationId[] = "application_id"; const std::vector LibHomeScreen::api_list { std::string("ping"), // debug do not use @@ -40,13 +41,23 @@ const std::vector LibHomeScreen::api_list { std::string("on_screen_message"), std::string("on_screen_reply"), std::string("subscribe"), - std::string("unsubscribe") + std::string("unsubscribe"), + std::string("showWindow"), + std::string("hideWindow"), + std::string("replyShowWindow"), + std::string("showNotification"), + std::string("showInformation") }; const std::vector LibHomeScreen::event_list { - std::string("tap_shortcut"), +// std::string("tap_shortcut"), + std::string("showWindow"), std::string("on_screen_message"), std::string("on_screen_reply"), + std::string("hideWindow"), + std::string("replyShowWindow"), + std::string("showNotification"), + std::string("showInformation"), std::string("none") }; @@ -210,15 +221,11 @@ END: */ int LibHomeScreen::tapShortcut(const char* application_id) { - if(!sp_websock) - { - return -1; - } + struct json_object* obj = json_object_new_object(); + struct json_object* val = json_object_new_string("normal"); + json_object_object_add(obj, "area", val); - struct json_object* j_obj = json_object_new_object(); - 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); + return showWindow(application_id, obj); } /** @@ -287,9 +294,9 @@ int LibHomeScreen::onScreenReply(const char* reply_message) */ void LibHomeScreen::set_event_handler(enum EventType et, handler_func f) { - if (et >= 1 && et <= 3) { + if (et >= 1 && et <= 7) { switch (et) { - case Event_TapShortcut: + case Event_ShowWindow: this->subscribe(LibHomeScreen::event_list[0]); break; case Event_OnScreenMessage: @@ -298,6 +305,18 @@ void LibHomeScreen::set_event_handler(enum EventType et, handler_func f) case Event_OnScreenReply: this->subscribe(LibHomeScreen::event_list[2]); break; + case Event_HideWindow: + this->subscribe(LibHomeScreen::event_list[3]); + break; + case Event_ReplyShowWindow: + this->subscribe(LibHomeScreen::event_list[4]); + break; + case Event_ShowNotification: + this->subscribe(LibHomeScreen::event_list[5]); + break; + case Event_ShowInformation: + this->subscribe(LibHomeScreen::event_list[6]); + break; } this->handlers[et] = std::move(f); @@ -429,6 +448,147 @@ int LibHomeScreen::unsubscribe(const string& event_name) return ret; } +/** + * Sending show window event + * + * Call HomeScreen Service's showWindow verb to request display id's screen. + * + * #### Parameters + * - application_id [in] : This argument should be specified to the application's id. + * - json [in] : This argument should be specified to the json parameters. + * + * #### Return + * - Returns 0 on success or -1 in case of error. + * + */ +int LibHomeScreen::showWindow(const char* application_id, json_object* json) +{ + if(!sp_websock) + { + return -1; + } + + struct json_object* j_obj = json_object_new_object(); + struct json_object* val = json_object_new_string(application_id); + json_object_object_add(j_obj, ApplicationId, val); + + if (json == nullptr) { + struct json_object* j_json = json_object_new_object(); + struct json_object* value = json_object_new_string("normal"); + json_object_object_add(j_json, "area", value); + json_object_object_add(j_obj, "parameter", j_json); + } + else { + json_object_object_add(j_obj, "parameter", json); + } + + return this->call("showWindow", j_obj); +} + +/** + * Sending hide window event + * + * Call HomeScreen Service's hideWindow verb to release id's screen. + * + * #### Parameters + * - application_id [in] : This argument should be specified to the application's id. + * + * #### Return + * - Returns 0 on success or -1 in case of error. + * + */ +int LibHomeScreen::hideWindow(const char* application_id) +{ + if(!sp_websock) + { + return -1; + } + + struct json_object* j_obj = json_object_new_object(); + struct json_object* val = json_object_new_string(application_id); + json_object_object_add(j_obj, ApplicationId, val); + + return this->call("hideWindow", j_obj); +} + +/** + * Sending reply onscreen message event + * + * Call HomeScreen Service's replyShowWindow verb to reply onscreen message. + * + * #### Parameters + * - application_id [in] : This argument should be specified to the onscreen reply to applilcation id. + * - json [in] : This argument should be specified to the json parameters. + * + * #### Return + * - Returns 0 on success or -1 in case of error. + * + */ +int LibHomeScreen::replyShowWindow(const char* application_id, json_object* json) +{ + if(!sp_websock) + { + return -1; + } + + if (json == nullptr) { + HMI_WARNING("libhomescreen", "replyShowWindow`s parameter is null"); + return -1; + } + + struct json_object* j_obj = json_object_new_object(); + struct json_object* val = json_object_new_string(application_id); + json_object_object_add(j_obj, ApplicationId, val); + json_object_object_add(j_obj, "parameter", json); + + return this->call("replyShowWindow", j_obj); +} + +/** + * Sending show notification event + * + * Call HomeScreen Service's notification verb to show notification on Status Bar. + * + * #### Parameters + * - json [in] : This argument should be specified to the json parameters. + * + * #### Return + * - Returns 0 on success or -1 in case of error. + * + */ +int LibHomeScreen::showNotification(json_object* json) +{ + if(!sp_websock) + { + return -1; + } + + return this->call("showNotification", json); +} + +/** + * Sending show information event + * + * Call HomeScreen Service's information verb to show notification on Information Bar. + * + * #### Parameters + * - json [in] : This argument should be specified to the json parameters. + * + * #### Return + * - Returns 0 on success or -1 in case of error. + * + */ +int LibHomeScreen::showInformation(json_object* json) +{ + if(!sp_websock) + { + return -1; + } + + return this->call("showInformation", json); +} + + /************* Callback Function *************/ void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj) @@ -482,7 +642,7 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m } if (strcasecmp(event_type, LibHomeScreen::event_list[0].c_str()) == 0) { - auto i = this->handlers.find(Event_TapShortcut); + auto i = this->handlers.find(Event_ShowWindow); if ( i != this->handlers.end() ) { i->second(json_data); } @@ -499,6 +659,30 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m i->second(json_data); } } + else if (strcasecmp(event_type, LibHomeScreen::event_list[3].c_str()) == 0) { + auto i = this->handlers.find(Event_HideWindow); + if ( i != this->handlers.end() ) { + i->second(json_data); + } + } + else if (strcasecmp(event_type, LibHomeScreen::event_list[4].c_str()) == 0) { + auto i = this->handlers.find(Event_ReplyShowWindow); + if ( i != this->handlers.end() ) { + i->second(json_data); + } + } + else if (strcasecmp(event_type, LibHomeScreen::event_list[5].c_str()) == 0) { + auto i = this->handlers.find(Event_ShowNotification); + if ( i != this->handlers.end() ) { + i->second(json_data); + } + } + else if (strcasecmp(event_type, LibHomeScreen::event_list[6].c_str()) == 0) { + auto i = this->handlers.find(Event_ShowInformation); + if ( i != this->handlers.end() ) { + i->second(json_data); + } + } } /** -- cgit 1.2.3-korg