POI: AGL LifeCycle Management
[apps/agl-service-windowmanager.git] / src / applist.cpp
index a5ae9f0..67980f1 100644 (file)
@@ -16,7 +16,7 @@
 #include <iostream>
 #include <algorithm>
 #include "applist.hpp"
-#include "../include/hmi-debug.h"
+#include "util.hpp"
 
 using std::shared_ptr;
 using std::string;
@@ -65,7 +65,7 @@ AppList::~AppList() {}
  * @attention This function should be called once for the app
  *            Caller should take care not to be called more than once.
  */
-void AppList::addClient(const std::string &appid, unsigned layer, unsigned surface, const std::string &role)
+void AppList::addClient(const string &appid, unsigned layer, unsigned surface, const string &role)
 {
     std::lock_guard<std::mutex> lock(this->mtx);
     shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, layer, surface, role);
@@ -73,6 +73,14 @@ void AppList::addClient(const std::string &appid, unsigned layer, unsigned surfa
     this->clientDump();
 }
 
+void AppList::addClient(const string &appid, unsigned layer, const string &role)
+{
+    std::lock_guard<std::mutex> lock(this->mtx);
+    shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, layer, role);
+    this->app2client[appid] = client;
+    this->clientDump();
+}
+
 /**
  * Remove WMClient from the list
  *
@@ -82,7 +90,7 @@ void AppList::removeClient(const string &appid)
 {
     std::lock_guard<std::mutex> lock(this->mtx);
     this->app2client.erase(appid);
-    HMI_INFO("wm", "Remove client %s", appid.c_str());
+    HMI_INFO("Remove client %s", appid.c_str());
 }
 
 /**
@@ -111,7 +119,7 @@ void AppList::removeSurface(unsigned surface){
     {
         ret = x.second->removeSurfaceIfExist(surface);
         if(ret){
-            HMI_DEBUG("wm", "remove surface %d from Client %s finish",
+            HMI_DEBUG("remove surface %d from Client %s finish",
                         surface, x.second->appID().c_str());
             break;
         }
@@ -132,7 +140,14 @@ void AppList::removeSurface(unsigned surface){
  */
 shared_ptr<WMClient> AppList::lookUpClient(const string &appid)
 {
-    return this->app2client.at(appid);
+    if(this->app2client.count(appid) != 0)
+    {
+        return this->app2client.at(appid);
+    }
+    else
+    {
+        return nullptr;
+    }
 }
 
 /**
@@ -154,17 +169,16 @@ int AppList::countClient() const
  * Returns AppID if found.
  *
  * @param     unsigned[in] surfaceID
- * @param     string[in]   role
  * @param     bool[in,out] AppID is found or not
  * @return    AppID
  * @attention If AppID is not found, param found will be false.
  */
-string AppList::getAppID(unsigned surface, const string& role, bool* found) const
+string AppList::getAppID(unsigned surface, bool* found) const
 {
     *found = false;
     for (const auto &x : this->app2client)
     {
-        if(x.second->surfaceID(role) == surface){
+        if(x.second->surfaceID() == surface){
             *found = true;
             return x.second->appID();
         }
@@ -296,6 +310,10 @@ const vector<struct WMAction> &AppList::getActions(unsigned req_num, bool* found
         }
     }
     HMI_SEQ_ERROR(req_num, "Couldn't get action with the request : %d", req_num);
+    {
+      static vector<struct WMAction> empty;
+      return empty;
+    }
 }
 
 /**
@@ -351,7 +369,7 @@ WMError AppList::setAction(unsigned req_num, const struct WMAction &action)
  *            otherwise (visible is false) app should be invisible. Then enddraw_finished param is set to true.
  *            This function doesn't support actions for focus yet.
  */
-WMError AppList::setAction(unsigned req_num, const string &appid, const string &role, const string &area, TaskVisible visible)
+WMError AppList::setAction(unsigned req_num, shared_ptr<WMClient> client, const string &role, const string &area, TaskVisible visible)
 {
     std::lock_guard<std::mutex> lock(this->mtx);
     WMError result = WMError::FAIL;
@@ -363,7 +381,7 @@ WMError AppList::setAction(unsigned req_num, const string &appid, const string &
         }
         // If visible task is not invisible, redraw is required -> true
         bool edraw_f = (visible != TaskVisible::INVISIBLE) ? false : true;
-        WMAction action{appid, role, area, visible, edraw_f};
+        WMAction action{req_num, client, role, area, visible, edraw_f};
 
         x.sync_draw_req.push_back(action);
         result = WMError::SUCCESS;
@@ -399,7 +417,7 @@ bool AppList::setEndDrawFinished(unsigned req_num, const string &appid, const st
         {
             for (auto &y : x.sync_draw_req)
             {
-                if (y.appid == appid && y.role == role)
+                if (y.client->appID() == appid && y.role == role)
                 {
                     HMI_SEQ_INFO(req_num, "Role %s finish redraw", y.role.c_str());
                     y.end_draw_finished = true;
@@ -514,7 +532,7 @@ void AppList::reqDump()
         {
             DUMP(
                 "Action  : (APPID :%s, ROLE :%s, AREA :%s, VISIBLE : %s, END_DRAW_FINISHED: %d)",
-                y.appid.c_str(),
+                y.client->appID().c_str(),
                 y.role.c_str(),
                 y.area.c_str(),
                 (y.visible == TaskVisible::INVISIBLE) ? "invisible" : "visible",