Output log if removing floating surface
[apps/agl-service-windowmanager.git] / src / applist.cpp
index b5c1681..e855705 100644 (file)
@@ -22,14 +22,17 @@ using std::shared_ptr;
 using std::string;
 using std::vector;
 
+const static int kReserveReqSize = 10;
+const static int kReserveCLSize = 100;
+
 namespace wm
 {
 
 AppList::AppList()
-    : req_list(0),
-      app2client(0),
-      current_req(1)
+    : current_req(1)
 {
+    req_list.reserve(kReserveReqSize);
+    app2client.reserve(kReserveCLSize);
 }
 
 void AppList::addClient(const string &appid, const string &role)
@@ -59,9 +62,13 @@ bool AppList::contains(const string &appid) const
 
 void AppList::removeSurface(unsigned surface_id){
     // This function may be very slow
+    this->clientDump();
+    for (int i = 0; i < 1000; i++)
+        ;
     bool ret = false;
     for (auto &x : this->app2client)
     {
+        HMI_DEBUG("wm", "app: %s", x.second->appID());
         ret = x.second->removeSurfaceIfExist(surface_id);
         if(ret){
             HMI_DEBUG("wm", "remove surface %d from Client %s finish", surface_id, x.second->appID().c_str());
@@ -95,16 +102,22 @@ WMError AppList::popFloatingSurface(unsigned pid, unsigned *surface)
 {
     WMError ret = WMError::NO_ENTRY;
 
-    for (auto itr = this->floating_surfaces.begin(); itr != this->floating_surfaces.end(); ++itr)
+    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())
     {
-        if(pid == itr->pid){
-            *surface = itr->surface_id;
-            itr = this->floating_surfaces.erase(itr);
-            ret = WMError::SUCCESS;
-            HMI_DEBUG("wm", "Erase surface %d", *surface);
-            break;
-        }
+        HMI_INFO("wm", "pop floating surface: %d", *surface);
     }
+    this->floating_surfaces.erase(fwd_itr, this->floating_surfaces.end());
     return ret;
 }
 
@@ -122,19 +135,20 @@ void AppList::addFloatingSurface(unsigned surface, unsigned pid)
 {
     struct FloatingSurface fsurface{surface, pid};
     this->floating_surfaces.push_back(fsurface);
+    this->dumpFloatingSurfaces();
 }
 
 void AppList::removeFloatingSurface(unsigned surface)
 {
-    for (auto itr = this->floating_surfaces.begin(); itr != this->floating_surfaces.end(); ++itr)
-    {
-        if (surface == itr->surface_id)
-        {
-            HMI_DEBUG("wm", "Erase surface %d", itr->surface_id);
-            itr = this->floating_surfaces.erase(itr);
-            break;
-        }
+    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("wm", "remove floating surface: %d", surface);
     }
+    this->floating_surfaces.erase(fwd_itr, this->floating_surfaces.end());
 }
 
 WMError AppList::appendRole(const std::string &id, const std::string &role, unsigned surface)
@@ -177,23 +191,28 @@ unsigned AppList::addAllocateRequest(WMRequest req)
     return req.req_num; // return 1; if you test time_expire
 }
 
-struct WMTrigger AppList::getRequest(unsigned req_num)
+struct WMTrigger AppList::getRequest(unsigned req_num, bool *found)
 {
+    *found = false;
     for (const auto &x : this->req_list)
     {
         if (req_num == x.req_num)
         {
+            *found = true;
             return x.trigger;
         }
     }
+    return WMTrigger{"", "", "", Task::TASK_INVALID};
 }
 
-const vector<struct WMAction> &AppList::getActions(unsigned req_num)
+const vector<struct WMAction> &AppList::getActions(unsigned req_num, bool* found)
 {
+    *found = false;
     for (auto &x : this->req_list)
     {
         if (req_num == x.req_num)
         {
+            *found = true;
             return x.sync_draw_req;
         }
     }
@@ -360,4 +379,15 @@ void AppList::reqDump()
     }
     DUMP("======= req dump end =====\n");
 }
+
+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
\ No newline at end of file