X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fapplist.cpp;h=365c48573c4c6ae89fb95c24c695dff15fdc7f68;hb=cfcac41c81325ded349489ec5cfc24bdaa56d405;hp=6b608d0ace42313ad5e747ccec1f38ac594aa79b;hpb=1e55798ce66d927f649284441202bc6ae1df328b;p=apps%2Fagl-service-windowmanager.git diff --git a/src/applist.cpp b/src/applist.cpp index 6b608d0..365c485 100644 --- a/src/applist.cpp +++ b/src/applist.cpp @@ -20,50 +20,59 @@ using std::shared_ptr; using std::string; -using std::unique_ptr; using std::vector; namespace wm { +const static int kReserveClientSize = 100; +const static int kReserveReqSize = 10; + AppList::AppList() - : req_list(0), - client_list(0), - current_seq(1) + : req_list(), + app2client(), + current_req(1) { + app2client.reserve(kReserveClientSize); + req_list.reserve(kReserveReqSize); } AppList::~AppList() {} void AppList::addClient(const string &appid, const string &role) { + std::lock_guard lock(mtx); shared_ptr client = std::make_shared(appid, role); - client_list[appid] = client; - client_dump(); + this->app2client[appid] = client; + this->clientDump(); } void AppList::addClient(const std::string &appid, unsigned layer, unsigned surface, const std::string &role) { + std::lock_guard lock(mtx); shared_ptr client = std::make_shared(appid, layer, surface, role); - client_list[appid] = client; - client_dump(); + this->app2client[appid] = client; + this->clientDump(); } void AppList::removeClient(const string &appid) { - client_list.erase(appid); + std::lock_guard lock(mtx); + this->app2client.erase(appid); + HMI_INFO("wm", "Remove client %s", appid.c_str()); } -WMError AppList::contains(const string &appid) +bool AppList::contains(const string &appid) const { - auto result = client_list.find(appid); - return (client_list.end() != result) ? WMError::SUCCESS : WMError::NOT_REGISTERED; + auto result = this->app2client.find(appid); + return (this->app2client.end() != result) ? true : false; } void AppList::removeSurface(unsigned surface_id){ // This function may be very slow + std::lock_guard lock(mtx); bool ret = false; - for (auto &x : client_list) + for (auto &x : this->app2client) { ret = x.second->removeSurfaceIfExist(surface_id); if(ret){ @@ -71,6 +80,7 @@ void AppList::removeSurface(unsigned surface_id){ break; } } + } /** @@ -81,28 +91,27 @@ void AppList::removeSurface(unsigned surface_id){ */ shared_ptr AppList::lookUpClient(const string &appid) { - return client_list.at(appid); + return this->app2client.at(appid); } -int AppList::countClient() +int AppList::countClient() const { - return client_list.size(); + return this->app2client.size(); } -unsigned AppList::currentSequenceNumber() +unsigned AppList::currentRequestNumber() const { - return current_seq; + return this->current_req; } -// Is this function necessary ? -unsigned AppList::getSequenceNumber(const string &appid) +unsigned AppList::getRequestNumber(const string &appid) const { - for (const auto &x : req_list) + for (const auto &x : this->req_list) { // Since app will not request twice and more, comparing appid is enough? if ((x.trigger.appid == appid)) { - return x.seq_num; + return x.req_num; } } return 0; @@ -110,52 +119,56 @@ unsigned AppList::getSequenceNumber(const string &appid) unsigned AppList::addAllocateRequest(WMRequest req) { - if (req_list.size() == 0) + std::lock_guard lock(mtx); + if (this->req_list.size() == 0) { - req.seq_num = current_seq; + req.req_num = current_req; } else { - HMI_SEQ_DEBUG(current_seq, "real: %d", req_list.back().seq_num + 1); - req.seq_num = req_list.back().seq_num + 1; + HMI_SEQ_INFO(this->current_req, "add: %d", this->req_list.back().req_num + 1); + req.req_num = this->req_list.back().req_num + 1; } - req_list.push_back(req); - return req.seq_num; // return 1; if you test time_expire + this->req_list.push_back(req); + return req.req_num; } -bool AppList::requestFinished() +struct WMTrigger AppList::getRequest(unsigned req_num, bool *found) { - return req_list.empty(); -} - -struct WMTrigger AppList::getRequest(unsigned req_num) -{ - for (auto &x : req_list) + *found = false; + for (const auto &x : this->req_list) { - if (req_num == x.seq_num) + if (req_num == x.req_num) { + *found = true; return x.trigger; } } + HMI_SEQ_ERROR(req_num, "Couldn't get request : %d", req_num); + return WMTrigger{"", "", "", Task::TASK_INVALID}; } -const vector &AppList::getActions(unsigned req_num) +const vector &AppList::getActions(unsigned req_num, bool* found) { - for (auto &x : req_list) + *found = false; + for (auto &x : this->req_list) { - if (req_num == x.seq_num) + if (req_num == x.req_num) { + *found = true; return x.sync_draw_req; } } + HMI_SEQ_ERROR(req_num, "Couldn't get action with the request : %d", req_num); } WMError AppList::setAction(unsigned req_num, const struct WMAction &action) { + std::lock_guard lock(mtx); WMError result = WMError::FAIL; - for (auto &x : req_list) + for (auto &x : this->req_list) { - if (req_num != x.seq_num) + if (req_num != x.req_num) { continue; } @@ -163,20 +176,28 @@ WMError AppList::setAction(unsigned req_num, const struct WMAction &action) result = WMError::SUCCESS; break; } - return result; } +/** + * 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) { + std::lock_guard lock(mtx); WMError result = WMError::NOT_REGISTERED; for (auto &x : req_list) { - if (req_num != x.seq_num) + if (req_num != x.req_num) { continue; } - WMAction action{appid, role, area, visible, false}; + bool edraw_f = (visible) ? false : true; + WMAction action{appid, role, area, visible, edraw_f}; x.sync_draw_req.push_back(action); result = WMError::SUCCESS; @@ -185,16 +206,22 @@ WMError AppList::setAction(unsigned req_num, const string &appid, const string & return result; } +/** + * 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) { + std::lock_guard lock(mtx); bool result = false; for (auto &x : req_list) { - if (req_num < x.seq_num) + if (req_num < x.req_num) { break; } - if (req_num == x.seq_num) + if (req_num == x.req_num) { for (auto &y : x.sync_draw_req) { @@ -206,13 +233,13 @@ bool AppList::setEndDrawFinished(unsigned req_num, const string &appid, const st } } } - 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 req_num) @@ -220,11 +247,11 @@ bool AppList::endDrawFullfilled(unsigned req_num) bool result = false; for (const auto &x : req_list) { - if (req_num < x.seq_num) + if (req_num < x.req_num) { break; } - if (req_num == x.seq_num) + if (req_num == x.req_num) { result = true; for (const auto &y : x.sync_draw_req) @@ -240,32 +267,34 @@ bool AppList::endDrawFullfilled(unsigned req_num) return result; } -void AppList::removeRequest(unsigned req_seq) +void AppList::removeRequest(unsigned req_num) { - req_list.erase(remove_if(req_list.begin(), req_list.end(), - [req_seq](WMRequest x) { - return x.seq_num == req_seq; - })); + std::lock_guard lock(mtx); + 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) + std::lock_guard lock(mtx); + ++this->current_req; + if (0 == this->current_req) { - this->current_seq = 1; + this->current_req = 1; } } -bool AppList::haveRequest() +bool AppList::haveRequest() const { - return !req_list.empty(); + return !this->req_list.empty(); } -void AppList::client_dump() +void AppList::clientDump() { DUMP("======= client dump ====="); - for (const auto &x : client_list) + for (const auto &x : this->app2client) { const auto &y = x.second; y->dumpInfo(); @@ -273,13 +302,13 @@ void AppList::client_dump() DUMP("======= client dump end====="); } -void AppList::req_dump() +void AppList::reqDump() { DUMP("======= req dump ====="); - DUMP("current request : %d", current_seq); + DUMP("current request : %d", current_req); for (const auto &x : req_list) { - DUMP("requested with : %d", x.seq_num); + 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(),