From fbf27649e8b43a716d45c676acdee83292db7bbb Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Mon, 20 May 2019 16:02:58 +0900 Subject: add als2019 source code --- include/libhomescreen.hpp | 2 ++ src/libhomescreen.cpp | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/libhomescreen.hpp b/include/libhomescreen.hpp index e51e01c..0361fa4 100644 --- a/include/libhomescreen.hpp +++ b/include/libhomescreen.hpp @@ -51,6 +51,7 @@ public: Event_ShowNotification, Event_ShowInformation, Event_AppListChanged, + Event_RegisterShortcut, Event_Max }; @@ -82,6 +83,7 @@ public: int showNotification(json_object* json); int showInformation(json_object* json); int getRunnables(void); + int registerShortcut(json_object* json); private: diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp index ad18ca4..9c50c86 100644 --- a/src/libhomescreen.cpp +++ b/src/libhomescreen.cpp @@ -49,7 +49,8 @@ const std::vector LibHomeScreen::api_list { std::string("replyShowWindow"), std::string("showNotification"), std::string("showInformation"), - std::string("getRunnables") + std::string("getRunnables"), + std::string("registerShortcut") }; const std::vector LibHomeScreen::event_list { @@ -62,6 +63,7 @@ const std::vector LibHomeScreen::event_list { std::string("showNotification"), std::string("showInformation"), std::string("application-list-changed"), + std::string("registerShortcut"), std::string("none") }; @@ -332,6 +334,9 @@ void LibHomeScreen::set_event_handler(enum EventType et, handler_func f) case Event_AppListChanged: this->subscribe(LibHomeScreen::event_list[7]); break; + case Event_RegisterShortcut: + this->subscribe(LibHomeScreen::event_list[8]); + break; } this->handlers[et] = std::move(f); @@ -620,6 +625,27 @@ int LibHomeScreen::getRunnables(void) return this->call("getRunnables", nullptr); } +/** + * register shortcut to homescreen + * + * Call HomeScreen Service's registerShortcut verb to regitster shortcut. + * + * #### 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::registerShortcut(json_object* json) +{ + if(!sp_websock) + { + return -1; + } + + return this->call("registerShortcut", json); +} /************* Callback Function *************/ @@ -721,6 +747,12 @@ 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[8].c_str()) == 0) { + auto i = this->handlers.find(Event_RegisterShortcut); + if ( i != this->handlers.end() ) { + i->second(json_data); + } + } } /** -- cgit 1.2.3-korg