From 1024e4747621cb4b45384afef671df6d15a9e2c0 Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Tue, 12 Jun 2018 18:16:26 +0900 Subject: Bug Fix : vector contents vanishes When Window Manager handles applist as pointer(smart pointer), the contents of vector vanishes when callback function accesses it. I don't know how to fix, then move applist out to global variable in app.cpp In this way, vecotr contents doesn't vanish Change-Id: Ic1cbb12279c82b6debbd608dbb7fb37089f92538 Signed-off-by: Kazumasa Mitsunari --- src/applist.cpp | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) (limited to 'src/applist.cpp') diff --git a/src/applist.cpp b/src/applist.cpp index 06c1d86..7249130 100644 --- a/src/applist.cpp +++ b/src/applist.cpp @@ -62,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()); @@ -98,16 +102,18 @@ 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) - { - 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; - } - } + auto rmv_begin = 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; + } + }); + this->floating_surfaces.erase(rmv_begin, this->floating_surfaces.end()); return ret; } @@ -125,19 +131,17 @@ 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 rmv_begin = std::remove_if(this->floating_surfaces.begin(), this->floating_surfaces.end(), + [surface](FloatingSurface x) { + return x.surface_id == surface; + }); + this->floating_surfaces.erase(rmv_begin, this->floating_surfaces.end()); } WMError AppList::appendRole(const std::string &id, const std::string &role, unsigned surface) @@ -368,4 +372,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 -- cgit 1.2.3-korg