aboutsummaryrefslogtreecommitdiffstats
path: root/src/libhomescreen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libhomescreen.cpp')
-rw-r--r--src/libhomescreen.cpp80
1 files changed, 78 insertions, 2 deletions
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);
}