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;
23 using std::unique_ptr;
36 AppList::~AppList() {}
38 void AppList::addClient(const string &appid, const string &role)
40 shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, role);
41 client_list[appid] = client;
45 void AppList::addClient(const std::string &appid, unsigned layer, unsigned surface, const std::string &role)
47 shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, layer, surface, role);
48 client_list[appid] = client;
52 void AppList::removeClient(const string &appid)
54 client_list.erase(appid);
57 bool AppList::contains(const string &appid)
59 auto result = client_list.find(appid);
60 return (client_list.end() != result) ? true : false;
63 void AppList::removeSurface(unsigned surface_id){
64 // This function may be very slow
66 for (auto &x : client_list)
68 ret = x.second->removeSurfaceIfExist(surface_id);
70 HMI_DEBUG("wm", "remove surface %d from Client %s finish", surface_id, x.second->appID().c_str());
77 * @brief get WMClient object. Before call this function, must call "contains"
78 * to check the key is contained, otherwise, you have to take care of std::out_of_range.
79 * @param string[in] application id(key)
80 * @return WMClient object
82 shared_ptr<WMClient> AppList::lookUpClient(const string &appid)
84 return client_list.at(appid);
87 int AppList::countClient()
89 return client_list.size();
92 unsigned AppList::currentSequenceNumber()
97 // Is this function necessary ?
98 unsigned AppList::getSequenceNumber(const string &appid)
100 for (const auto &x : req_list)
102 // Since app will not request twice and more, comparing appid is enough?
103 if ((x.trigger.appid == appid))
111 unsigned AppList::addAllocateRequest(WMRequest req)
113 if (req_list.size() == 0)
115 req.seq_num = current_seq;
119 HMI_SEQ_DEBUG(current_seq, "real: %d", req_list.back().seq_num + 1);
120 req.seq_num = req_list.back().seq_num + 1;
122 req_list.push_back(req);
123 return req.seq_num; // return 1; if you test time_expire
126 bool AppList::requestFinished()
128 return req_list.empty();
131 struct WMTrigger AppList::getRequest(unsigned req_num)
133 for (auto &x : req_list)
135 if (req_num == x.seq_num)
142 const vector<struct WMAction> &AppList::getActions(unsigned req_num)
144 for (auto &x : req_list)
146 if (req_num == x.seq_num)
148 return x.sync_draw_req;
153 bool AppList::setAction(unsigned req_num, const struct WMAction &action)
156 for (auto &x : req_list)
158 if (req_num != x.seq_num)
162 x.sync_draw_req.push_back(action);
170 bool AppList::setAction(unsigned req_num, const string &appid, const string &role, const string &area, bool visible)
173 for (auto &x : req_list)
175 if (req_num != x.seq_num)
179 WMAction action{appid, role, area, visible, false};
181 x.sync_draw_req.push_back(action);
188 bool AppList::setEndDrawFinished(unsigned req_num, const string &appid, const string &role)
191 for (auto &x : req_list)
193 if (req_num < x.seq_num)
197 if (req_num == x.seq_num)
199 for (auto &y : x.sync_draw_req)
201 if (y.appid == appid && y.role == role)
203 y.end_draw_finished = true;
214 * @brief check all actions of the requested sequence is finished
215 * @param unsigned sequence_num
216 * @return true if all action is set.
218 bool AppList::endDrawFullfilled(unsigned req_num)
221 for (const auto &x : req_list)
223 if (req_num < x.seq_num)
227 if (req_num == x.seq_num)
230 for (const auto &y : x.sync_draw_req)
232 result &= y.end_draw_finished;
243 void AppList::removeRequest(unsigned req_seq)
245 req_list.erase(remove_if(req_list.begin(), req_list.end(),
246 [req_seq](WMRequest x) {
247 return x.seq_num == req_seq;
254 if (0 == this->current_seq)
256 this->current_seq = 1;
260 bool AppList::haveRequest()
262 return !req_list.empty();
265 void AppList::client_dump()
267 DUMP("======= client dump =====");
268 for (const auto &x : client_list)
270 const auto &y = x.second;
273 DUMP("======= client dump end=====");
276 void AppList::req_dump()
278 DUMP("======= req dump =====");
279 DUMP("current request : %d", current_seq);
280 for (const auto &x : req_list)
282 DUMP("requested with : %d", x.seq_num);
283 DUMP("Trigger : (APPID :%s, ROLE :%s, AREA :%s, TASK: %d)",
284 x.trigger.appid.c_str(),
285 x.trigger.role.c_str(),
286 x.trigger.area.c_str(),
289 for (const auto &y : x.sync_draw_req)
292 "Action : (APPID :%s, ROLE :%s, AREA :%s, END_DRAW_FINISHED: %d)",
296 y.end_draw_finished);
299 DUMP("======= req dump end =====\n");