2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "applist.hpp"
19 #include "../include/hmi-debug.h"
21 using std::shared_ptr;
35 AppList::~AppList() {}
37 void AppList::addClient(const string &appid, const string &role)
39 shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, role);
40 this->app2client[appid] = client;
44 void AppList::addClient(const std::string &appid, unsigned layer, unsigned surface, const std::string &role)
46 shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, layer, surface, role);
47 this->app2client[appid] = client;
51 void AppList::removeClient(const string &appid)
53 this->app2client.erase(appid);
56 bool AppList::contains(const string &appid)
58 auto result = this->app2client.find(appid);
59 return (this->app2client.end() != result) ? true : false;
62 void AppList::removeSurface(unsigned surface_id){
63 // This function may be very slow
65 for (auto &x : this->app2client)
67 ret = x.second->removeSurfaceIfExist(surface_id);
69 HMI_DEBUG("wm", "remove surface %d from Client %s finish", surface_id, x.second->appID().c_str());
76 * @brief get WMClient object. Before call this function, must call "contains"
77 * to check the key is contained, otherwise, you have to take care of std::out_of_range.
78 * @param string[in] application id(key)
79 * @return WMClient object
81 shared_ptr<WMClient> AppList::lookUpClient(const string &appid)
83 return this->app2client.at(appid);
86 int AppList::countClient()
88 return this->app2client.size();
91 unsigned AppList::currentRequestNumber()
93 return this->current_req;
96 // Is this function necessary ?
97 unsigned AppList::getRequestNumber(const string &appid)
99 for (const auto &x : this->req_list)
101 // Since app will not request twice and more, comparing appid is enough?
102 if ((x.trigger.appid == appid))
110 unsigned AppList::addAllocateRequest(WMRequest req)
112 if (this->req_list.size() == 0)
114 req.req_num = current_req;
118 HMI_SEQ_DEBUG(this->current_req, "add: %d", this->req_list.back().req_num + 1);
119 req.req_num = this->req_list.back().req_num + 1;
121 this->req_list.push_back(req);
122 return req.req_num; // return 1; if you test time_expire
125 bool AppList::requestFinished()
127 return this->req_list.empty();
130 struct WMTrigger AppList::getRequest(unsigned req_num)
132 for (auto &x : this->req_list)
134 if (req_num == x.req_num)
141 const vector<struct WMAction> &AppList::getActions(unsigned req_num)
143 for (auto &x : this->req_list)
145 if (req_num == x.req_num)
147 return x.sync_draw_req;
152 bool AppList::setAction(unsigned req_num, const struct WMAction &action)
155 for (auto &x : this->req_list)
157 if (req_num != x.req_num)
161 x.sync_draw_req.push_back(action);
171 * This function set action with parameters.
172 * if visible is true, it means app should be visible, so enddraw_finished parameter should be false.
173 * otherwise (visible is false) app should be invisible. Then enddraw_finished param is set to true.
174 * This function doesn't support actions for focus yet.
176 bool AppList::setAction(unsigned req_num, const string &appid, const string &role, const string &area, bool visible)
179 for (auto &x : req_list)
181 if (req_num != x.req_num)
185 bool edraw_f = (visible) ? false : true;
186 WMAction action{appid, role, area, visible, edraw_f};
188 x.sync_draw_req.push_back(action);
196 * This function checks
197 * * req_num is equal to current request number
198 * * appid and role are equeal to the appid and role stored in action list(sync_draw_req)
200 bool AppList::setEndDrawFinished(unsigned req_num, const string &appid, const string &role)
203 for (auto &x : req_list)
205 if (req_num < x.req_num)
209 if (req_num == x.req_num)
211 for (auto &y : x.sync_draw_req)
213 if (y.appid == appid && y.role == role)
215 y.end_draw_finished = true;
226 * @brief check all actions of the requested sequence is finished
227 * @param unsigned request_number
228 * @return true if all action is set.
230 bool AppList::endDrawFullfilled(unsigned req_num)
233 for (const auto &x : req_list)
235 if (req_num < x.req_num)
239 if (req_num == x.req_num)
242 for (const auto &y : x.sync_draw_req)
244 result &= y.end_draw_finished;
255 void AppList::removeRequest(unsigned req_num)
257 this->req_list.erase(remove_if(this->req_list.begin(), this->req_list.end(),
258 [req_num](WMRequest x) {
259 return x.req_num == req_num;
266 if (0 == this->current_req)
268 this->current_req = 1;
272 bool AppList::haveRequest()
274 return !this->req_list.empty();
277 void AppList::clientDump()
279 DUMP("======= client dump =====");
280 for (const auto &x : this->app2client)
282 const auto &y = x.second;
285 DUMP("======= client dump end=====");
288 void AppList::reqDump()
290 DUMP("======= req dump =====");
291 DUMP("current request : %d", current_req);
292 for (const auto &x : req_list)
294 DUMP("requested with : %d", x.req_num);
295 DUMP("Trigger : (APPID :%s, ROLE :%s, AREA :%s, TASK: %d)",
296 x.trigger.appid.c_str(),
297 x.trigger.role.c_str(),
298 x.trigger.area.c_str(),
301 for (const auto &y : x.sync_draw_req)
304 "Action : (APPID :%s, ROLE :%s, AREA :%s, END_DRAW_FINISHED: %d)",
308 y.end_draw_finished);
311 DUMP("======= req dump end =====\n");