Update windowmanager
[apps/agl-service-windowmanager.git] / src / applist.cpp
index a5ae9f0..644e41e 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& layer_name, unsigned surface, const string &role)
+{
+    std::lock_guard<std::mutex> lock(this->mtx);
+    shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, layer, layer_name, surface, 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;
         }
@@ -172,6 +180,75 @@ string AppList::getAppID(unsigned surface, const string& role, bool* found) cons
     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 ===================
+
+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());
+}
+
+WMError AppList::appendRole(const string &id, const string &role)
+{
+    WMError wm_err = WMError::NO_ENTRY;
+    if (this->contains(id))
+    {
+        auto x = this->lookUpClient(id);
+        x->appendRole(role);
+        wm_err = WMError::SUCCESS;
+    }
+    return wm_err;
+}
+
+
 // =================== Request Date container API ===================
 
 /**
@@ -523,4 +600,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