fix issue,not free string
[apps/agl-service-homescreen.git] / src / hs-clientmanager.cpp
index aae8c42..1355c99 100644 (file)
@@ -17,6 +17,8 @@
 #include "hs-clientmanager.h"
 #include "hmi-debug.h"
 
+static const char _homescreen[] = "homescreen";
+
 HS_ClientManager* HS_ClientManager::me = nullptr;
 
 static void cbRemoveClientCtxt(void *data)
@@ -164,20 +166,17 @@ void HS_ClientManager::removeClientCtxt(void *data)
 int HS_ClientManager::tap_shortcut(afb_req_t request)
 {
     int ret = 0;
-    const char* value = afb_req_value(request, _application_name);
+    const char* value = afb_req_value(request, _application_id);
     if (value) {
         HMI_NOTICE("homescreen-service","request params = %s.", value);
-        // first step get appid from appname, next step change appname to appid
-        std::string appid(value);
-        std::transform(appid.begin(), appid.end(), appid.begin(), ::tolower);
         std::lock_guard<std::mutex> lock(this->mtx);
-        auto ip = client_list.find(appid);
+        auto ip = client_list.find(std::string(value));
         if(ip != client_list.end()) {
             ip->second->tap_shortcut(value);
         }
     }
     else {
-        HMI_NOTICE("homescreen-service","Please input application_name");
+        HMI_NOTICE("homescreen-service","Please input application_id");
         ret = AFB_EVENT_BAD_REQUEST;
     }
     return ret;
@@ -255,10 +254,13 @@ int HS_ClientManager::subscribe(afb_req_t request)
     const char *value = afb_req_value(request, "event");
     HMI_NOTICE("homescreen-service","value is %s", value);
     if(value) {
-        std::string appid(afb_req_get_application_id(request));
-        std::transform(appid.begin(), appid.end(), appid.begin(), ::tolower);
-        std::lock_guard<std::mutex> lock(this->mtx);
+        std::string appid =std::move(get_application_id(request));
+        if(appid.empty()) {
+            HMI_NOTICE("homescreen-service","can't get application identifier");
+            return AFB_REQ_GETAPPLICATIONID_ERROR;
+        }
 
+        std::lock_guard<std::mutex> lock(this->mtx);
         HS_Client* client = nullptr;
         auto ip = client_list.find(appid);
         if(ip != client_list.end()) {
@@ -297,10 +299,13 @@ int HS_ClientManager::unsubscribe(afb_req_t request)
     HMI_NOTICE("homescreen-service","value is %s", value);
     int ret = 0;
     if(value) {
-        std::string appid(afb_req_get_application_id(request));
-        std::transform(appid.begin(), appid.end(), appid.begin(), ::tolower);
-        std::lock_guard<std::mutex> lock(this->mtx);
+        std::string appid = std::move(get_application_id(request));
+        if(appid.empty()) {
+            HMI_NOTICE("homescreen-service","can't get application identifier");
+            return AFB_REQ_GETAPPLICATIONID_ERROR;
+        }
 
+        std::lock_guard<std::mutex> lock(this->mtx);
         auto ip = client_list.find(appid);
         if(ip != client_list.end()
         && ip->second->unsubscribe(request, value) != 0) {
@@ -314,3 +319,147 @@ int HS_ClientManager::unsubscribe(afb_req_t request)
     }
     return ret;
 }
+
+/**
+ * showWindow event
+ *
+ * #### Parameters
+ *  - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::showWindow(afb_req_t request)
+{
+    int ret = 0;
+    const char* value = afb_req_value(request, _application_id);
+    if (value) {
+        HMI_NOTICE("homescreen-service","request params = %s.", value);
+        std::lock_guard<std::mutex> lock(this->mtx);
+        auto ip = client_list.find(std::string(value));
+        if(ip != client_list.end()) {
+            ret = ip->second->showWindow(request, value);
+        }
+    }
+    else {
+        HMI_NOTICE("homescreen-service","Please input application_id");
+        ret = AFB_EVENT_BAD_REQUEST;
+    }
+    return ret;
+}
+
+/**
+ * hideWindow event
+ *
+ * #### Parameters
+ *  - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::hideWindow(afb_req_t request)
+{
+    int ret = 0;
+    const char* value = afb_req_value(request, _application_id);
+    if (value) {
+        HMI_NOTICE("homescreen-service","request params = %s.", value);
+        std::lock_guard<std::mutex> lock(this->mtx);
+        auto ip = client_list.find(std::string(value));
+        if(ip != client_list.end()) {
+            ret = ip->second->hideWindow(request);
+        }
+    }
+    else {
+        HMI_NOTICE("homescreen-service","Please input application_id");
+        ret = AFB_EVENT_BAD_REQUEST;
+    }
+    return ret;
+}
+
+/**
+ * replyShowWindow event
+ *
+ * #### Parameters
+ *  - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::replyShowWindow(afb_req_t request)
+{
+    int ret = 0;
+    const char* value = afb_req_value(request, _application_id);
+    if (value) {
+        HMI_NOTICE("homescreen-service","request params = %s.", value);
+        std::lock_guard<std::mutex> lock(this->mtx);
+        auto ip = client_list.find(std::string(value));
+        if(ip != client_list.end()) {
+            ret = ip->second->replyShowWindow(request, value);
+        }
+    }
+    else {
+        HMI_NOTICE("homescreen-service","Please input application_id");
+        ret = AFB_EVENT_BAD_REQUEST;
+    }
+    return ret;
+}
+
+/**
+ * showNotification event
+ *
+ * #### Parameters
+ *  - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::showNotification(afb_req_t request)
+{
+    int ret = 0;
+    std::lock_guard<std::mutex> lock(this->mtx);
+    auto ip = client_list.find(_homescreen);
+    if(ip != client_list.end()) {
+        ret = ip->second->showNotification(request);
+    }
+    else {
+        HMI_NOTICE("homescreen-service","not exist sessiion with homescreen");
+        ret = AFB_REQ_SHOWNOTIFICATION_ERROR;
+    }
+
+    return ret;
+}
+
+/**
+ * showInformation event
+ *
+ * #### Parameters
+ *  - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::showInformation(afb_req_t request)
+{
+    int ret = 0;
+    std::lock_guard<std::mutex> lock(this->mtx);
+    auto ip = client_list.find(_homescreen);
+    if(ip != client_list.end()) {
+        ret = ip->second->showInformation(request);
+    }
+    else {
+        HMI_NOTICE("homescreen-service","not exist sessiion with homescreen");
+        ret = AFB_REQ_SHOWINFORMATION_ERROR;
+    }
+
+    return ret;
+}