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::removeClient(const string &appid)
47 client_list.erase(appid);
50 bool AppList::contains(const string &appid)
52 auto result = client_list.find(appid);
53 return (client_list.end() != result) ? true : false;
57 * @brief get WMClient object. Before call this function, must call "contains"
58 * to check the key is contained, otherwise, you have to take care of std::out_of_range.
59 * @param string[in] application id(key)
60 * @return WMClient object
62 shared_ptr<WMClient> AppList::lookUpClient(const string &appid)
64 return client_list.at(appid);
67 int AppList::countClient()
69 return client_list.size();
72 unsigned AppList::currentSequenceNumber()
77 // Is this function necessary ?
78 unsigned AppList::getSequenceNumber(const string &appid)
80 for (const auto &x : req_list)
82 // Since app will not request twice and more, comparing appid is enough?
83 if ((x.trigger.appid == appid))
91 unsigned AppList::addAllocateRequest(WMRequest req)
93 if (req_list.size() == 0)
95 req.seq_num = current_seq;
99 HMI_SEQ_DEBUG(current_seq, "real: %d", req_list.back().seq_num + 1);
100 req.seq_num = req_list.back().seq_num + 1;
102 req_list.push_back(req);
103 return req.seq_num; // return 1; if you test time_expire
106 bool AppList::requestFinished()
108 return req_list.empty();
111 struct WMTrigger AppList::getRequest(unsigned req_num)
113 for (auto &x : req_list)
115 if (req_num == x.seq_num)
122 const vector<struct WMAction> &AppList::getActions(unsigned req_num)
124 for (auto &x : req_list)
126 if (req_num == x.seq_num)
128 return x.sync_draw_req;
133 bool AppList::setAction(unsigned req_num, const struct WMAction &action)
136 for (auto &x : req_list)
138 if (req_num != x.seq_num)
142 x.sync_draw_req.push_back(action);
150 bool AppList::setAction(unsigned req_num, const string &appid, const string &role, const string &area, bool visible)
153 for (auto &x : req_list)
155 if (req_num != x.seq_num)
159 WMAction action{appid, role, area, visible, false};
161 x.sync_draw_req.push_back(action);
168 bool AppList::setEndDrawFinished(unsigned req_num, const string &appid, const string &role)
171 for (auto &x : req_list)
173 if (req_num < x.seq_num)
177 if (req_num == x.seq_num)
179 for (auto &y : x.sync_draw_req)
181 if (y.appid == appid && y.role == role)
183 y.end_draw_finished = true;
194 * @brief check all actions of the requested sequence is finished
195 * @param unsigned sequence_num
196 * @return true if all action is set.
198 bool AppList::endDrawFullfilled(unsigned req_num)
201 for (const auto &x : req_list)
203 if (req_num < x.seq_num)
207 if (req_num == x.seq_num)
210 for (const auto &y : x.sync_draw_req)
212 result &= y.end_draw_finished;
223 void AppList::removeRequest(unsigned req_seq)
225 req_list.erase(remove_if(req_list.begin(), req_list.end(),
226 [req_seq](WMRequest x) {
227 return x.seq_num == req_seq;
234 if (0 == this->current_seq)
236 this->current_seq = 1;
240 bool AppList::haveRequest()
242 return !req_list.empty();
245 void AppList::client_dump()
247 DUMP("======= client dump =====");
248 for (const auto &x : client_list)
250 const auto &y = x.second;
251 DUMP("APPID : %s", y->appID().c_str());
253 DUMP("======= client dump end=====");
256 void AppList::req_dump()
258 DUMP("======= req dump =====");
259 DUMP("current request : %d", current_seq);
260 for (const auto &x : req_list)
262 DUMP("requested with : %d", x.seq_num);
263 DUMP("Trigger : (APPID :%s, ROLE :%s, AREA :%s, TASK: %d)",
264 x.trigger.appid.c_str(),
265 x.trigger.role.c_str(),
266 x.trigger.area.c_str(),
269 for (const auto &y : x.sync_draw_req)
272 "Action : (APPID :%s, ROLE :%s, AREA :%s, END_DRAW_FINISHED: %d)",
276 y.end_draw_finished);
279 DUMP("======= req dump end =====\n");