aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2018-06-13 09:48:03 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2018-06-13 09:48:03 +0900
commitca16fef732febe6cc7f86875929fa205024c0116 (patch)
treea1e29ed229833c1ba7109fc257212db48c1d8bbf
parent478ad89b8da9d5bc68755433cab4963b7d0c8b96 (diff)
Add restriction event for als2018sandbox/zheng_wenlong/als2018
-rw-r--r--include/libhomescreen.hpp7
-rw-r--r--src/libhomescreen.cpp80
2 files changed, 83 insertions, 4 deletions
diff --git a/include/libhomescreen.hpp b/include/libhomescreen.hpp
index 4a92059..7785b74 100644
--- a/include/libhomescreen.hpp
+++ b/include/libhomescreen.hpp
@@ -42,7 +42,9 @@ public:
enum EventType {
Event_TapShortcut = 1,
Event_OnScreenMessage,
- Event_OnScreenReply
+ Event_OnScreenReply,
+ Event_AllocateRestriction,
+ Event_ReleaseRestriction
};
static const std::vector<std::string> api_list;
@@ -66,7 +68,8 @@ public:
int call(const char* verb, struct json_object* arg);
int subscribe(const std::string& event_name);
int unsubscribe(const std::string& event_name);
-
+ int allocateRestriction(const char* area);
+ int releaseRestriction(const char* area);
private:
int initialize_websocket();
diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp
index 66fd259..0f48643 100644
--- a/src/libhomescreen.cpp
+++ b/src/libhomescreen.cpp
@@ -40,13 +40,17 @@ const std::vector<std::string> LibHomeScreen::api_list {
std::string("on_screen_message"),
std::string("on_screen_reply"),
std::string("subscribe"),
- std::string("unsubscribe")
+ std::string("unsubscribe"),
+ std::string("allocateRestriction"),
+ std::string("releaseRestriction")
};
const std::vector<std::string> LibHomeScreen::event_list {
std::string("tap_shortcut"),
std::string("on_screen_message"),
std::string("on_screen_reply"),
+ std::string("allocateRestriction"),
+ std::string("releaseRestriction"),
std::string("none")
};
@@ -283,7 +287,7 @@ 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:
this->subscribe(LibHomeScreen::event_list[0]);
@@ -294,6 +298,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);
@@ -425,6 +435,60 @@ int LibHomeScreen::unsubscribe(const string& event_name)
return ret;
}
+/**
+ * Sending allocate restriction event
+ *
+ * #### Parameters
+ * - area [in] : display area id
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ * #### Note
+ * - Call HomeScreen Service's requestRestriction verb to request restriction screen.
+ */
+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);
+}
+
+/**
+ * Realease restriction application
+ *
+ * #### Parameters
+ * - area [in] : display area id
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ * #### Note
+ * - Call HomeScreen Service's releaseRestriction verb to request restriction screen.
+ */
+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)
@@ -486,6 +550,18 @@ 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[3].c_str()) == 0) {
+ auto i = this->handlers.find(Event_AllocateRestriction);
+ if ( i != this->handlers.end() ) {
+ i->second(json_data);
+ }
+ }
+ else if (strcasecmp(event_only, LibHomeScreen::event_list[4].c_str()) == 0) {
+ auto i = this->handlers.find(Event_ReleaseRestriction);
+ if ( i != this->handlers.end() ) {
+ i->second(json_data);
+ }
+ }
json_object_put(ev_contents);
}