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) const
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() const
88 return this->app2client.size();
91 unsigned AppList::currentRequestNumber() const
93 return this->current_req;
96 // Is this function necessary ?
97 unsigned AppList::getRequestNumber(const string &appid) const
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 struct WMTrigger AppList::getRequest(unsigned req_num)
127 for (const auto &x : this->req_list)
129 if (req_num == x.req_num)
136 const vector<struct WMAction> &AppList::getActions(unsigned req_num)
138 for (auto &x : this->req_list)
140 if (req_num == x.req_num)
142 return x.sync_draw_req;
147 WMError AppList::setAction(unsigned req_num, const struct WMAction &action)
149 WMError result = WMError::FAIL;
150 for (auto &x : this->req_list)
152 if (req_num != x.req_num)
156 x.sync_draw_req.push_back(action);
157 result = WMError::SUCCESS;
166 * This function set action with parameters.
167 * if visible is true, it means app should be visible, so enddraw_finished parameter should be false.
168 * otherwise (visible is false) app should be invisible. Then enddraw_finished param is set to true.
169 * This function doesn't support actions for focus yet.
171 WMError AppList::setAction(unsigned req_num, const string &appid, const string &role, const string &area, bool visible)
173 WMError result = WMError::NOT_REGISTERED;
174 for (auto &x : req_list)
176 if (req_num != x.req_num)
180 bool edraw_f = (visible) ? false : true;
181 WMAction action{appid, role, area, visible, edraw_f};
183 x.sync_draw_req.push_back(action);
184 result = WMError::SUCCESS;
191 * This function checks
192 * * req_num is equal to current request number
193 * * appid and role are equeal to the appid and role stored in action list(sync_draw_req)
195 bool AppList::setEndDrawFinished(unsigned req_num, const string &appid, const string &role)
198 for (auto &x : req_list)
200 if (req_num < x.req_num)
204 if (req_num == x.req_num)
206 for (auto &y : x.sync_draw_req)
208 if (y.appid == appid && y.role == role)
210 y.end_draw_finished = true;
221 * @brief check all actions of the requested sequence is finished
222 * @param unsigned request_number
223 * @return true if all action is set.
225 bool AppList::endDrawFullfilled(unsigned req_num)
228 for (const auto &x : req_list)
230 if (req_num < x.req_num)
234 if (req_num == x.req_num)
237 for (const auto &y : x.sync_draw_req)
239 result &= y.end_draw_finished;
250 void AppList::removeRequest(unsigned req_num)
252 this->req_list.erase(remove_if(this->req_list.begin(), this->req_list.end(),
253 [req_num](WMRequest x) {
254 return x.req_num == req_num;
261 if (0 == this->current_req)
263 this->current_req = 1;
267 bool AppList::haveRequest() const
269 return !this->req_list.empty();
272 void AppList::clientDump()
274 DUMP("======= client dump =====");
275 for (const auto &x : this->app2client)
277 const auto &y = x.second;
280 DUMP("======= client dump end=====");
283 void AppList::reqDump()
285 DUMP("======= req dump =====");
286 DUMP("current request : %d", current_req);
287 for (const auto &x : req_list)
289 DUMP("requested with : %d", x.req_num);
290 DUMP("Trigger : (APPID :%s, ROLE :%s, AREA :%s, TASK: %d)",
291 x.trigger.appid.c_str(),
292 x.trigger.role.c_str(),
293 x.trigger.area.c_str(),
296 for (const auto &y : x.sync_draw_req)
299 "Action : (APPID :%s, ROLE :%s, AREA :%s, END_DRAW_FINISHED: %d)",
303 y.end_draw_finished);
306 DUMP("======= req dump end =====\n");