X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fapplist.cpp;h=e8557051cfe98c723a16c3026eec2e5969b40e7c;hb=7ab55d536e6985b9515c9f2d235a5ca6829df0fa;hp=be88977fd729a1858ae8e1b33c33f07b3e54a077;hpb=5ac52dc6412f8311b6cfbd0e99652c914d5c6168;p=apps%2Fagl-service-windowmanager.git diff --git a/src/applist.cpp b/src/applist.cpp index be88977..e855705 100644 --- a/src/applist.cpp +++ b/src/applist.cpp @@ -20,31 +20,61 @@ using std::shared_ptr; using std::string; -using std::unique_ptr; +using std::vector; -namespace wm { +const static int kReserveReqSize = 10; +const static int kReserveCLSize = 100; +namespace wm +{ AppList::AppList() - : req_list(0), - client_list(0), - current_seq(1) -{} - -AppList::~AppList(){} + : current_req(1) +{ + req_list.reserve(kReserveReqSize); + app2client.reserve(kReserveCLSize); +} -void AppList::addClient(const string &appid, const string &role){ +void AppList::addClient(const string &appid, const string &role) +{ shared_ptr client = std::make_shared(appid, role); - client_list[appid] = client; + this->app2client[appid] = client; + this->clientDump(); +} + +void AppList::addClient(const std::string &appid, unsigned layer, unsigned surface, const std::string &role) +{ + shared_ptr client = std::make_shared(appid, layer, surface, role); + this->app2client[appid] = client; + this->clientDump(); +} + +void AppList::removeClient(const string &appid) +{ + this->app2client.erase(appid); } -void AppList::removeClient(const string &appid){ - client_list.erase(appid); +bool AppList::contains(const string &appid) const +{ + auto result = this->app2client.find(appid); + return (this->app2client.end() != result) ? true : false; } -bool AppList::contains(const string &appid){ - auto result = client_list.find(appid); - return (client_list.end() != result) ? true : false; +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()); + break; + } + } } /** @@ -53,75 +83,202 @@ bool AppList::contains(const string &appid){ * @param string[in] application id(key) * @return WMClient object */ -shared_ptr AppList::lookUpClient(const string &appid) +shared_ptr AppList::lookUpClient(const string &appid) +{ + return this->app2client.at(appid); +} + +int AppList::countClient() const { - return client_list.at(appid); + return this->app2client.size(); } -int AppList::countClient() +unsigned AppList::currentRequestNumber() const { - return client_list.size(); + return this->current_req; } -unsigned AppList::currentSequenceNumber(){ - return current_seq; +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("wm", "pop floating surface: %d", *surface); + } + this->floating_surfaces.erase(fwd_itr, this->floating_surfaces.end()); + return ret; } -// Is this function necessary ? -unsigned AppList::getSequenceNumber(const string &appid){ - for(const auto& x : req_list){ +WMError AppList::popFloatingSurface(const std::string &appid, unsigned *surface) +{ + HMI_ERROR("wm", "This function is not implemented"); + return WMError::SUCCESS; +} + +void AppList::addFloatingClient(const std::string &appid, unsigned layer, const std::string &role) +{ +} + +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) +{ + 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) +{ + WMError wm_err = WMError::NO_ENTRY; + if (this->contains(id)) + { + auto x = this->lookUpClient(id); + x->addSurface(role, surface); + wm_err = WMError::SUCCESS; + } + return wm_err; +} + +unsigned AppList::getRequestNumber(const string &appid) const +{ + for (const auto &x : this->req_list) + { // Since app will not request twice and more, comparing appid is enough? - if( (x.trigger.appid == appid)) + if ((x.trigger.appid == appid)) { - return x.seq_num; + return x.req_num; } } return 0; } -unsigned AppList::addAllocateRequest(WMRequest req){ - if(req_list.size() == 0){ - req.seq_num = 1; +unsigned AppList::addAllocateRequest(WMRequest req) +{ + if (this->req_list.size() == 0) + { + req.req_num = current_req; + } + else + { + HMI_SEQ_DEBUG(this->current_req, "add: %d", this->req_list.back().req_num + 1); + req.req_num = this->req_list.back().req_num + 1; + } + this->req_list.push_back(req); + return req.req_num; // return 1; if you test time_expire +} + +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; + } } - else{ - req.seq_num = req_list.back().seq_num + 1; + return WMTrigger{"", "", "", Task::TASK_INVALID}; +} + +const vector &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; + } } - req_list.push_back(req); - return req.seq_num; } -bool AppList::requestFinished(){ - return req_list.empty(); +WMError AppList::setAction(unsigned req_num, const struct WMAction &action) +{ + WMError result = WMError::FAIL; + for (auto &x : this->req_list) + { + if (req_num != x.req_num) + { + continue; + } + x.sync_draw_req.push_back(action); + result = WMError::SUCCESS; + break; + } + + return result; } -bool AppList::setAction(unsigned request_seq, const string &appid, const string &role, const string &area){ - bool result = false; - for (auto& x : req_list) +/** + * Note: + * This function set action with parameters. + * if visible is true, it means app should be visible, so enddraw_finished parameter should be false. + * 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, bool visible) +{ + WMError result = WMError::NOT_REGISTERED; + for (auto &x : req_list) { - if (request_seq != x.seq_num) + if (req_num != x.req_num) { continue; } - WMAction action{appid, role, area, false}; + bool edraw_f = (visible) ? false : true; + WMAction action{appid, role, area, visible, edraw_f}; x.sync_draw_req.push_back(action); - result = true; + result = WMError::SUCCESS; break; } return result; } -bool AppList::setEndDrawFinished(unsigned request_seq, const string &appid, const string &role){ +/** + * This function checks + * * req_num is equal to current request number + * * appid and role are equeal to the appid and role stored in action list(sync_draw_req) + */ +bool AppList::setEndDrawFinished(unsigned req_num, const string &appid, const string &role) +{ bool result = false; - for (auto& x : req_list) + for (auto &x : req_list) { - if (request_seq < x.seq_num) + if (req_num < x.req_num) { break; } - if (request_seq == x.seq_num) + if (req_num == x.req_num) { - for(auto& y : x.sync_draw_req){ + for (auto &y : x.sync_draw_req) + { if (y.appid == appid && y.role == role) { y.end_draw_finished = true; @@ -130,27 +287,32 @@ bool AppList::setEndDrawFinished(unsigned request_seq, const string &appid, cons } } } - req_dump(); + this->reqDump(); return result; } /** * @brief check all actions of the requested sequence is finished - * @param unsigned sequence_num + * @param unsigned request_number * @return true if all action is set. */ -bool AppList::endDrawFullfilled(unsigned request_seq){ +bool AppList::endDrawFullfilled(unsigned req_num) +{ bool result = false; - for (const auto& x : req_list) + for (const auto &x : req_list) { - if(request_seq < x.seq_num){ + if (req_num < x.req_num) + { break; } - if(request_seq == x.seq_num){ + if (req_num == x.req_num) + { result = true; - for(const auto& y : x.sync_draw_req){ + for (const auto &y : x.sync_draw_req) + { result &= y.end_draw_finished; - if(!result){ + if (!result) + { break; } } @@ -159,49 +321,56 @@ bool AppList::endDrawFullfilled(unsigned request_seq){ return result; } -void AppList::removeRequest(unsigned req_seq){ - req_list.erase(remove_if(req_list.begin(), req_list.end(), - [req_seq](WMRequest x) { - return x.seq_num == req_seq; - })); +void AppList::removeRequest(unsigned req_num) +{ + this->req_list.erase(remove_if(this->req_list.begin(), this->req_list.end(), + [req_num](WMRequest x) { + return x.req_num == req_num; + })); } -void AppList::next(){ - ++this->current_seq; - if (0 == this->current_seq) +void AppList::next() +{ + ++this->current_req; + if (0 == this->current_req) { - this->current_seq = 1; + this->current_req = 1; } } -bool AppList::haveRequest(){ - return !req_list.empty(); +bool AppList::haveRequest() const +{ + return !this->req_list.empty(); } -void AppList::client_dump(){ +void AppList::clientDump() +{ DUMP("======= client dump ====="); - for(const auto& x : client_list){ - const auto& y = x.second; - DUMP("APPID : %s", y->appID().c_str()); + for (const auto &x : this->app2client) + { + const auto &y = x.second; + y->dumpInfo(); } DUMP("======= client dump end====="); } -void AppList::req_dump() +void AppList::reqDump() { DUMP("======= req dump ====="); - DUMP("current sequence: %d", current_seq); - for(const auto& x : req_list){ - DUMP("sequence number: %d", x.seq_num); + DUMP("current request : %d", current_req); + for (const auto &x : req_list) + { + DUMP("requested with : %d", x.req_num); DUMP("Trigger : (APPID :%s, ROLE :%s, AREA :%s, TASK: %d)", x.trigger.appid.c_str(), x.trigger.role.c_str(), x.trigger.area.c_str(), x.trigger.task); - for (const auto& y : x.sync_draw_req){ + for (const auto &y : x.sync_draw_req) + { DUMP( - "Action : (APPID :%s, ROLE :%s, AREA :%s, END_RAW_FINISHED: %d)", + "Action : (APPID :%s, ROLE :%s, AREA :%s, END_DRAW_FINISHED: %d)", y.appid.c_str(), y.role.c_str(), y.area.c_str(), @@ -210,4 +379,15 @@ void AppList::req_dump() } DUMP("======= req dump end =====\n"); } -} \ No newline at end of file + +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