From b98e130e1dbedf7064678a1da4ebfaa0544c99d2 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Tue, 30 Oct 2018 14:29:15 +0900 Subject: add source for ces2019 --- src/libhomescreen.cpp | 136 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 127 insertions(+), 9 deletions(-) (limited to 'src/libhomescreen.cpp') diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp index c3e76ba..9689863 100644 --- a/src/libhomescreen.cpp +++ b/src/libhomescreen.cpp @@ -36,17 +36,23 @@ static const char API[] = "homescreen"; const std::vector LibHomeScreen::api_list { std::string("ping"), // debug do not use - std::string("tap_shortcut"), // HomeScreen Application only +// std::string("tap_shortcut"), // HomeScreen Application only std::string("on_screen_message"), std::string("on_screen_reply"), std::string("subscribe"), - std::string("unsubscribe") + std::string("unsubscribe"), + std::string("showWindow"), + std::string("allocateRestriction"), + std::string("releaseRestriction") }; 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("allocateRestriction"), + std::string("releaseRestriction"), std::string("none") }; @@ -215,10 +221,11 @@ int LibHomeScreen::tapShortcut(const char* application_name) return -1; } - struct json_object* j_obj = json_object_new_object(); - struct json_object* val = json_object_new_string(application_name); - json_object_object_add(j_obj, "application_name", val); - return this->call("tap_shortcut", j_obj); + struct json_object* obj = json_object_new_object(); + struct json_object* val = json_object_new_string("normal"); + json_object_object_add(obj, "area", val); + + return showWindow(application_name, obj); } /** @@ -287,9 +294,13 @@ 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 <= 5) { switch (et) { - case Event_TapShortcut: +/* case Event_TapShortcut: + this->subscribe(LibHomeScreen::event_list[0]); + break; +*/ + case Event_ShowWindow: this->subscribe(LibHomeScreen::event_list[0]); break; case Event_OnScreenMessage: @@ -298,6 +309,12 @@ void LibHomeScreen::set_event_handler(enum EventType et, handler_func f) case Event_OnScreenReply: this->subscribe(LibHomeScreen::event_list[2]); break; + case Event_AllocateRestriction: + this->subscribe(LibHomeScreen::event_list[3]); + break; + case Event_ReleaseRestriction: + this->subscribe(LibHomeScreen::event_list[4]); + break; } this->handlers[et] = std::move(f); @@ -429,6 +446,107 @@ 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 + * - 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_name, 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_name); + json_object_object_add(j_obj, "application_name", val); + // j_json = json; + 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 allocate restriction event + * + * Call HomeScreen Service's requestRestriction verb to request restriction screen. + * + * #### Parameters + * - area [in] : restriction display area id. + * + * #### Return + * - Returns 0 on success or -1 in case of error. + * + */ +int LibHomeScreen::allocateRestriction(const char* area) +{ + if(!sp_websock) + { + return -1; + } + + struct json_object* j_obj = json_object_new_object(); + struct json_object* a_obj = json_object_new_object(); + + struct json_object* val = json_object_new_string(area); + + json_object_object_add(j_obj, "area", val); + + json_object_object_add(a_obj, "args", j_obj); + + return this->call("allocateRestriction", a_obj); +} + +/** + * Sending release restriction event + * + * Call HomeScreen Service's releaseRestriction verb to release restriction screen. + * + * #### Parameters + * - area [in] : restriction display area id. + * + * #### Return + * - Returns 0 on success or -1 in case of error. + * + */ +int LibHomeScreen::releaseRestriction(const char* area) +{ + if(!sp_websock) + { + return -1; + } + + struct json_object* j_obj = json_object_new_object(); + struct json_object* a_obj = json_object_new_object(); + + struct json_object* val = json_object_new_string(area); + + json_object_object_add(j_obj, "area", val); + + json_object_object_add(a_obj, "args", j_obj); + + return this->call("releaseRestriction", a_obj); +} + + /************* Callback Function *************/ void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj) -- cgit 1.2.3-korg