X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fapplist.cpp;h=25758498c6a8d685a22738d06c55cf4dac2523b4;hb=7f6ceaf920b5cb0d5984b8e8294f8ce0f52dfbbb;hp=477a51b19ff04a352b76db80680184fa218d2638;hpb=973a7123c0bced7c7e7d9dc6dc5e990a0e2838ac;p=apps%2Fagl-service-windowmanager.git diff --git a/src/applist.cpp b/src/applist.cpp index 477a51b..2575849 100644 --- a/src/applist.cpp +++ b/src/applist.cpp @@ -13,125 +13,301 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include #include "applist.hpp" #include "../include/hmi-debug.h" using std::shared_ptr; using std::string; -using std::unique_ptr; +using std::vector; -namespace wm { +namespace wm +{ +AppList::AppList() + : req_list(0), + app2client(0), + current_req(1) +{ +} -AppList::AppList(){} -AppList::~AppList(){} +AppList::~AppList() {} -void AppList::addClient(const std::string &appid, const std::string &role){ - shared_ptr client(new WMClient(appid, role)); - client_list[appid] = client; +void AppList::addClient(const string &appid, const string &role) +{ + shared_ptr client = std::make_shared(appid, role); + this->app2client[appid] = client; + this->clientDump(); } -void AppList::removeClient(const string &appid){ - client_list.erase(appid); +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(); } -bool AppList::contains(const string &appid){ - auto result = client_list.find(appid); - return (client_list.end() != result) ? true : false; +void AppList::removeClient(const string &appid) +{ + this->app2client.erase(appid); } -/* -* Call contains before calling this function -*/ -shared_ptr AppList::lookUpClient(const string &appid) +bool AppList::contains(const string &appid) const { - /* auto result = client_list.find(appid); - return (client_list.end() != result) ? - &(result->second()) : nullptr; */ - return client_list[appid]; + auto result = this->app2client.find(appid); + return (this->app2client.end() != result) ? true : false; } -unsigned AppList::currentSequenceNumber(){ - return current_seq; +void AppList::removeSurface(unsigned surface_id){ + // This function may be very slow + bool ret = false; + for (auto &x : this->app2client) + { + 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; + } + } } -unsigned AppList::getSequenceNumber(const string &appid){ - for(auto x : req_list){ +/** + * @brief get WMClient object. Before call this function, must call "contains" + * to check the key is contained, otherwise, you have to take care of std::out_of_range. + * @param string[in] application id(key) + * @return WMClient object + */ +shared_ptr AppList::lookUpClient(const string &appid) +{ + return this->app2client.at(appid); +} + +int AppList::countClient() const +{ + return this->app2client.size(); +} + +unsigned AppList::currentRequestNumber() const +{ + return this->current_req; +} + +// Is this function necessary ? +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.appid == appid)) + if ((x.trigger.appid == appid)) { - return x.seq_num; + return x.req_num; } } return 0; } -unsigned AppList::addAllocateRequest(WMRequest req){ - req.seq_num = req_list.back().seq_num + 1; - req.allocating = false; - req.end_draw_finished = false; - req_list.push_back(req); - return req.seq_num; +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 } -bool AppList::requestFinished(){ - return req_list.empty(); +bool AppList::requestFinished() const +{ + return this->req_list.empty(); } -unsigned AppList::lookUpAllocatingApp(const string &appid){ - for(auto x: req_list){ - if(appid == x.appid){ - if(false == x.allocating) - return x.seq_num; +struct WMTrigger AppList::getRequest(unsigned req_num) +{ + for (const auto &x : this->req_list) + { + if (req_num == x.req_num) + { + return x.trigger; } } - return 0; } -void AppList::setEndDrawFinished(unsigned request_seq, const string &role){ - for(auto x: req_list){ - if(request_seq == x.seq_num){ - if(role == x.role){ - x.end_draw_finished = true; +const vector &AppList::getActions(unsigned req_num) +{ + for (auto &x : this->req_list) + { + if (req_num == x.req_num) + { + return x.sync_draw_req; + } + } +} + +bool AppList::setAction(unsigned req_num, const struct WMAction &action) +{ + bool result = false; + for (auto &x : this->req_list) + { + if (req_num != x.req_num) + { + continue; + } + x.sync_draw_req.push_back(action); + result = true; + 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. + */ +bool AppList::setAction(unsigned req_num, const string &appid, const string &role, const string &area, bool visible) +{ + bool result = false; + for (auto &x : req_list) + { + if (req_num != x.req_num) + { + continue; + } + bool edraw_f = (visible) ? false : true; + WMAction action{appid, role, area, visible, edraw_f}; + + x.sync_draw_req.push_back(action); + result = true; + break; + } + 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) +{ + bool result = false; + for (auto &x : req_list) + { + if (req_num < x.req_num) + { + break; + } + if (req_num == x.req_num) + { + for (auto &y : x.sync_draw_req) + { + if (y.appid == appid && y.role == role) + { + y.end_draw_finished = true; + result = true; + } } } } + this->reqDump(); + return result; } -bool AppList::endDrawFullfilled(unsigned request_seq){ +/** + * @brief check all actions of the requested sequence is finished + * @param unsigned request_number + * @return true if all action is set. + */ +bool AppList::endDrawFullfilled(unsigned req_num) +{ bool result = false; - for (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){ - result = x.end_draw_finished && x.allocating; - if(result == false){ - break; + if (req_num == x.req_num) + { + result = true; + for (const auto &y : x.sync_draw_req) + { + result &= y.end_draw_finished; + if (!result) + { + break; + } } } } 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::setCurrentSequence(unsigned req_seq){ - this->current_seq = req_seq; - if(0 == this->current_seq){ - this->current_seq = 1; - } +void AppList::next() +{ + ++this->current_req; + if (0 == this->current_req) + { + this->current_req = 1; + } } -bool AppList::haveRequest(){ - return true; +bool AppList::haveRequest() const +{ + return !this->req_list.empty(); } -} \ No newline at end of file +void AppList::clientDump() +{ + DUMP("======= client dump ====="); + for (const auto &x : this->app2client) + { + const auto &y = x.second; + y->dumpInfo(); + } + DUMP("======= client dump end====="); +} + +void AppList::reqDump() +{ + DUMP("======= req dump ====="); + 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) + { + DUMP( + "Action : (APPID :%s, ROLE :%s, AREA :%s, END_DRAW_FINISHED: %d)", + y.appid.c_str(), + y.role.c_str(), + y.area.c_str(), + y.end_draw_finished); + } + } + DUMP("======= req dump end =====\n"); +} +} // namespace wm \ No newline at end of file