summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2017-10-23 14:48:42 +0900
committerZheng Wenlong <wenlong_zheng@nexty-ele.com>2017-10-30 04:28:01 +0000
commit2dbbe0dbd2e5d5aa43a3f719ca2186b7c334d1d1 (patch)
treee585e17954b844458bbe23a744c15df5479bdeb1
parenteabd10ffe2f9cb5c31262ad3152b037eb2286857 (diff)
Use new OnScreenReply API in libhomescreen
As homescreen-service added the OnScreenReply function, we can add the OnScreenReply to libhomescreen so applications can use this api easily. BUG-AGL: SPEC-985 Change-Id: I8038fea7471d1ae0777dcbff19e45c38fb6f614f Signed-off-by: zheng_wenlong <wenlong_zheng@nexty-ele.com>
-rw-r--r--include/libhomescreen.hpp4
-rw-r--r--src/libhomescreen.cpp37
2 files changed, 39 insertions, 2 deletions
diff --git a/include/libhomescreen.hpp b/include/libhomescreen.hpp
index 9034dc8..0d3815d 100644
--- a/include/libhomescreen.hpp
+++ b/include/libhomescreen.hpp
@@ -42,7 +42,8 @@ public:
enum EventType {
Event_TapShortcut = 1,
- Event_OnScreenMessage
+ Event_OnScreenMessage,
+ Event_OnScreenReply
};
static const std::vector<std::string> api_list;
@@ -53,6 +54,7 @@ public:
int tapShortcut(const char* application_name);
int onScreenMessage(const char* display_message);
+ int onScreenReply(const char* reply_message);
void set_event_handler(enum EventType et, handler_func f);
diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp
index 2f3ef44..66fd259 100644
--- a/src/libhomescreen.cpp
+++ b/src/libhomescreen.cpp
@@ -38,6 +38,7 @@ const std::vector<std::string> LibHomeScreen::api_list {
std::string("ping"), // debug do not use
std::string("tap_shortcut"), // HomeScreen Application only
std::string("on_screen_message"),
+ std::string("on_screen_reply"),
std::string("subscribe"),
std::string("unsubscribe")
};
@@ -45,6 +46,7 @@ const std::vector<std::string> LibHomeScreen::api_list {
const std::vector<std::string> LibHomeScreen::event_list {
std::string("tap_shortcut"),
std::string("on_screen_message"),
+ std::string("on_screen_reply"),
std::string("none")
};
@@ -244,6 +246,30 @@ int LibHomeScreen::onScreenMessage(const char* display_message)
}
/**
+ * Sending onScreen reply event
+ *
+ * Sending OnScreen reply event to applications from HomeScreen
+ *
+ * #### Parameters
+ * - reply_message [in] : message for reply
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ */
+int LibHomeScreen::onScreenReply(const char* reply_message)
+{
+ if(!sp_websock)
+ {
+ return -1;
+ }
+
+ struct json_object* j_obj = json_object_new_object();
+ struct json_object* val = json_object_new_string(reply_message);
+ json_object_object_add(j_obj, "reply_message", val);
+ return this->call("on_screen_reply", j_obj);
+}
+
+/**
* Setting Event Handler
*
* Setting event handler for Homescreen
@@ -257,7 +283,7 @@ int LibHomeScreen::onScreenMessage(const char* display_message)
*/
void LibHomeScreen::set_event_handler(enum EventType et, handler_func f)
{
- if (et >= 1 && et <= 2) {
+ if (et >= 1 && et <= 3) {
switch (et) {
case Event_TapShortcut:
this->subscribe(LibHomeScreen::event_list[0]);
@@ -265,6 +291,9 @@ void LibHomeScreen::set_event_handler(enum EventType et, handler_func f)
case Event_OnScreenMessage:
this->subscribe(LibHomeScreen::event_list[1]);
break;
+ case Event_OnScreenReply:
+ this->subscribe(LibHomeScreen::event_list[2]);
+ break;
}
this->handlers[et] = std::move(f);
@@ -451,6 +480,12 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
i->second(json_data);
}
}
+ else if (strcasecmp(event_only, LibHomeScreen::event_list[2].c_str()) == 0) {
+ auto i = this->handlers.find(Event_OnScreenReply);
+ if ( i != this->handlers.end() ) {
+ i->second(json_data);
+ }
+ }
json_object_put(ev_contents);
}