add source for ces2019
[apps/agl-service-windowmanager-2017.git] / src / applist.cpp
index a5ae9f0..44865f6 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;
+    }
 }
 
 /**
@@ -159,7 +174,7 @@ int AppList::countClient() const
  * @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, const string& role, bool* found) const
 {
     *found = false;
     for (const auto &x : this->app2client)
@@ -170,6 +185,77 @@ string AppList::getAppID(unsigned surface, const string& role, bool* found) cons
         }
     }
     return string("");
+} */
+
+string AppList::getAppID(unsigned surface, bool* found) const
+{
+    *found = false;
+    for (const auto &x : this->app2client)
+    {
+        if(x.second->surfaceID() == surface){
+            *found = true;
+            return x.second->appID();
+        }
+    }
+    return string("");
+}
+
+WMError AppList::popFloatingSurface(unsigned pid, unsigned *surface)
+{
+    WMError ret = WMError::NO_ENTRY;
+
+    auto fwd_itr = std::remove_if(this->floating_surfaces.begin(), this->floating_surfaces.end(),
+                                    [pid, surface, &ret](FloatingSurface x) {
+                                        if(pid == x.pid){
+                                            *surface = x.surface_id;
+                                            ret = WMError::SUCCESS;
+                                            return true;
+                                        }
+                                        else{
+                                            return false;
+                                        }
+                                    });
+    if (fwd_itr != this->floating_surfaces.cend())
+    {
+        HMI_INFO("pop floating surface: %d", *surface);
+    }
+    this->floating_surfaces.erase(fwd_itr, this->floating_surfaces.end());
+    return ret;
+}
+
+// =================== Floating(Temporary) surface/client API ===================
+
+// TODO: After testing setRole, remove these API
+
+WMError AppList::popFloatingSurface(const string &appid, unsigned *surface)
+{
+    HMI_ERROR("This function is not implemented");
+    return WMError::SUCCESS;
+}
+
+void AppList::addFloatingClient(const string &appid, unsigned layer, const string &role)
+{
+}
+
+void AppList::addFloatingSurface(const string &appid, unsigned surface, unsigned pid)
+{
+    struct FloatingSurface fsurface{appid, surface, pid};
+    this->floating_surfaces.push_back(fsurface);
+    this->dumpFloatingSurfaces();
+}
+
+void AppList::removeFloatingSurface(unsigned surface)
+{
+    this->dumpFloatingSurfaces();
+    auto fwd_itr = std::remove_if(
+        this->floating_surfaces.begin(), this->floating_surfaces.end(),
+        [surface](FloatingSurface x) {
+            return x.surface_id == surface;
+        });
+    if(fwd_itr != this->floating_surfaces.cend()){
+        HMI_INFO("remove floating surface: %d", surface);
+    }
+    this->floating_surfaces.erase(fwd_itr, this->floating_surfaces.end());
 }
 
 // =================== Request Date container API ===================
@@ -351,7 +437,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 +449,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, TaskCarState::NO_TASK};
 
         x.sync_draw_req.push_back(action);
         result = WMError::SUCCESS;
@@ -399,11 +485,23 @@ 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 (nullptr != y.client)
+                {
+                    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;
+                        result = true;
+                    }
+                }
+                else
                 {
-                    HMI_SEQ_INFO(req_num, "Role %s finish redraw", y.role.c_str());
-                    y.end_draw_finished = true;
-                    result = true;
+                    if (y.role == role)
+                    {
+                        HMI_SEQ_INFO(req_num, "Role %s finish redraw", y.role.c_str());
+                        y.end_draw_finished = true;
+                        result = true;
+                    }
                 }
             }
         }
@@ -514,7 +612,7 @@ void AppList::reqDump()
         {
             DUMP(
                 "Action  : (APPID :%s, ROLE :%s, AREA :%s, VISIBLE : %s, END_DRAW_FINISHED: %d)",
-                y.appid.c_str(),
+                (y.client) ? y.client->appID().c_str() : "-",
                 y.role.c_str(),
                 y.area.c_str(),
                 (y.visible == TaskVisible::INVISIBLE) ? "invisible" : "visible",
@@ -523,4 +621,15 @@ void AppList::reqDump()
     }
     DUMP("======= req dump end =====");
 }
+
+void AppList::dumpFloatingSurfaces()
+{
+    DUMP("======= floating surface dump =====");
+    for (const auto &x : this->floating_surfaces)
+    {
+        DUMP("surface : %d, pid : %d", x.surface_id, x.pid);
+    }
+    DUMP("======= floating surface dump end =====\n");
+}
+
 } // namespace wm