add new features in homescreen-service and homescreen
[src/libhomescreen.git] / src / libhomescreen.cpp
index 29ba7ef..84e3472 100644 (file)
@@ -33,6 +33,7 @@ using namespace std;
 
 static bool has_verb(const string& verb);
 static const char API[] = "homescreen";
+static const char ApplicationId[] = "application_id";
 
 const std::vector<std::string> LibHomeScreen::api_list {
        std::string("ping"), // debug do not use
@@ -40,13 +41,23 @@ 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("showWindow"),
+       std::string("hideWindow"),
+       std::string("replyShowWindow"),
+       std::string("showNotification"),
+       std::string("showInformation")
 };
 
 const std::vector<std::string> 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("hideWindow"),
+       std::string("replyShowWindow"),
+       std::string("showNotification"),
+       std::string("showInformation"),
        std::string("none")
 };
 
@@ -210,15 +221,11 @@ END:
  */
 int LibHomeScreen::tapShortcut(const char* application_id)
 {
-       if(!sp_websock)
-       {
-               return -1;
-       }
+       struct json_object* obj = json_object_new_object();
+       struct json_object* val = json_object_new_string("normal");
+       json_object_object_add(obj, "area", val);
 
-       struct json_object* j_obj = json_object_new_object();
-       struct json_object* val = json_object_new_string(application_id);
-       json_object_object_add(j_obj, "application_id", val);
-       return this->call("tap_shortcut", j_obj);
+       return showWindow(application_id, obj);
 }
 
 /**
@@ -287,9 +294,9 @@ 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 <= 7) {
                switch (et) {
-                       case Event_TapShortcut:
+                       case Event_ShowWindow:
                                this->subscribe(LibHomeScreen::event_list[0]);
                                break;
                        case Event_OnScreenMessage:
@@ -298,6 +305,18 @@ void LibHomeScreen::set_event_handler(enum EventType et, handler_func f)
                        case Event_OnScreenReply:
                                this->subscribe(LibHomeScreen::event_list[2]);
                                break;
+                       case Event_HideWindow:
+                               this->subscribe(LibHomeScreen::event_list[3]);
+                               break;
+                       case Event_ReplyShowWindow:
+                               this->subscribe(LibHomeScreen::event_list[4]);
+                               break;
+                       case Event_ShowNotification:
+                               this->subscribe(LibHomeScreen::event_list[5]);
+                               break;
+                       case Event_ShowInformation:
+                               this->subscribe(LibHomeScreen::event_list[6]);
+                               break;
                }
 
                this->handlers[et] = std::move(f);
@@ -429,6 +448,147 @@ 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
+ * - application_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_id, 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_id);
+       json_object_object_add(j_obj, ApplicationId, val);
+
+       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 hide window event
+ *
+ * Call HomeScreen Service's hideWindow verb to release id's screen.
+ *
+ * #### Parameters
+ * - application_id [in] : This argument should be specified to the application's id.
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ */
+int LibHomeScreen::hideWindow(const char* application_id)
+{
+       if(!sp_websock)
+       {
+               return -1;
+       }
+
+       struct json_object* j_obj = json_object_new_object();
+       struct json_object* val = json_object_new_string(application_id);
+       json_object_object_add(j_obj, ApplicationId, val);
+
+       return this->call("hideWindow", j_obj);
+}
+
+/**
+ * Sending reply onscreen message event
+ *
+ * Call HomeScreen Service's replyShowWindow verb to reply onscreen message.
+ *
+ * #### Parameters
+ * - application_id [in] : This argument should be specified to the onscreen reply to applilcation 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::replyShowWindow(const char* application_id, json_object* json)
+{
+       if(!sp_websock)
+       {
+               return -1;
+       }
+
+       if (json == nullptr) {
+               HMI_WARNING("libhomescreen", "replyShowWindow`s parameter is null");
+               return -1;
+       }
+
+       struct json_object* j_obj = json_object_new_object();
+       struct json_object* val = json_object_new_string(application_id);
+       json_object_object_add(j_obj, ApplicationId, val);
+       json_object_object_add(j_obj, "parameter", json);
+
+       return this->call("replyShowWindow", j_obj);
+}
+
+/**
+ * Sending show notification event
+ *
+ * Call HomeScreen Service's notification verb to show notification on Status Bar.
+ *
+ * #### 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::showNotification(json_object* json)
+{
+       if(!sp_websock)
+       {
+               return -1;
+       }
+
+       return this->call("showNotification", json);
+}
+
+/**
+ * Sending show information event
+ *
+ * Call HomeScreen Service's information verb to show notification on Information Bar.
+ *
+ * #### 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::showInformation(json_object* json)
+{
+       if(!sp_websock)
+       {
+               return -1;
+       }
+
+       return this->call("showInformation", json);
+}
+
+
 /************* Callback Function *************/
 
 void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj)
@@ -482,7 +642,7 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
        }
 
        if (strcasecmp(event_type, LibHomeScreen::event_list[0].c_str()) == 0) {
-               auto i = this->handlers.find(Event_TapShortcut);
+               auto i = this->handlers.find(Event_ShowWindow);
                if ( i != this->handlers.end() ) {
                        i->second(json_data);
                }
@@ -499,6 +659,30 @@ 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[3].c_str()) == 0) {
+               auto i = this->handlers.find(Event_HideWindow);
+               if ( i != this->handlers.end() ) {
+                       i->second(json_data);
+               }
+       }
+       else if (strcasecmp(event_type, LibHomeScreen::event_list[4].c_str()) == 0) {
+               auto i = this->handlers.find(Event_ReplyShowWindow);
+               if ( i != this->handlers.end() ) {
+                       i->second(json_data);
+               }
+       }
+       else if (strcasecmp(event_type, LibHomeScreen::event_list[5].c_str()) == 0) {
+               auto i = this->handlers.find(Event_ShowNotification);
+               if ( i != this->handlers.end() ) {
+                       i->second(json_data);
+               }
+       }
+       else if (strcasecmp(event_type, LibHomeScreen::event_list[6].c_str()) == 0) {
+               auto i = this->handlers.find(Event_ShowInformation);
+               if ( i != this->handlers.end() ) {
+                       i->second(json_data);
+               }
+       }
 }
 
 /**