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;
37 void AppList::addClient(const string &appid, const string &role){
38 shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, role);
39 client_list[appid] = client;
43 void AppList::removeClient(const string &appid){
44 client_list.erase(appid);
47 bool AppList::contains(const string &appid){
48 auto result = client_list.find(appid);
49 return (client_list.end() != result) ? true : false;
53 * @brief get WMClient object. Before call this function, must call "contains"
54 * to check the key is contained, otherwise, you have to take care of std::out_of_range.
55 * @param string[in] application id(key)
56 * @return WMClient object
58 shared_ptr <WMClient> AppList::lookUpClient(const string &appid)
60 return client_list.at(appid);
63 int AppList::countClient()
65 return client_list.size();
68 unsigned AppList::currentSequenceNumber(){
72 // Is this function necessary ?
73 unsigned AppList::getSequenceNumber(const string &appid){
74 for(const auto& x : req_list){
75 // Since app will not request twice and more, comparing appid is enough?
76 if( (x.trigger.appid == appid))
84 unsigned AppList::addAllocateRequest(WMRequest req){
85 if(req_list.size() == 0){
86 req.seq_num = current_seq;
89 HMI_SEQ_DEBUG(current_seq, "real: %d", req_list.back().seq_num + 1);
90 req.seq_num = req_list.back().seq_num + 1;
92 req_list.push_back(req);
93 return req.seq_num; // return 1; if you test time_expire
96 bool AppList::requestFinished(){
97 return req_list.empty();
100 struct WMTrigger AppList::getRequest(unsigned request_seq){
101 for(auto& x : req_list){
102 if (request_seq == x.seq_num)
109 const vector<struct WMAction>& AppList::getActions(unsigned request_seq){
110 for (auto &x : req_list)
112 if (request_seq == x.seq_num)
114 return x.sync_draw_req;
119 bool AppList::setAction(unsigned request_seq, const string &appid, const string &role, const string &area){
121 for (auto& x : req_list)
123 if (request_seq != x.seq_num)
127 WMAction action{appid, role, area, false};
129 x.sync_draw_req.push_back(action);
136 bool AppList::setEndDrawFinished(unsigned request_seq, const string &appid, const string &role){
138 for (auto& x : req_list)
140 if (request_seq < x.seq_num)
144 if (request_seq == x.seq_num)
146 for(auto& y : x.sync_draw_req){
147 if (y.appid == appid && y.role == role)
149 y.end_draw_finished = true;
160 * @brief check all actions of the requested sequence is finished
161 * @param unsigned sequence_num
162 * @return true if all action is set.
164 bool AppList::endDrawFullfilled(unsigned request_seq){
166 for (const auto& x : req_list)
168 if(request_seq < x.seq_num){
171 if(request_seq == x.seq_num){
173 for(const auto& y : x.sync_draw_req){
174 result &= y.end_draw_finished;
184 void AppList::removeRequest(unsigned req_seq){
185 req_list.erase(remove_if(req_list.begin(), req_list.end(),
186 [req_seq](WMRequest x) {
187 return x.seq_num == req_seq;
191 void AppList::next(){
193 if (0 == this->current_seq)
195 this->current_seq = 1;
199 bool AppList::haveRequest(){
200 return !req_list.empty();
203 void AppList::client_dump(){
204 DUMP("======= client dump =====");
205 for(const auto& x : client_list){
206 const auto& y = x.second;
207 DUMP("APPID : %s", y->appID().c_str());
209 DUMP("======= client dump end=====");
212 void AppList::req_dump()
214 DUMP("======= req dump =====");
215 DUMP("current request : %d", current_seq);
216 for(const auto& x : req_list){
217 DUMP("requested with : %d", x.seq_num);
218 DUMP("Trigger : (APPID :%s, ROLE :%s, AREA :%s, TASK: %d)",
219 x.trigger.appid.c_str(),
220 x.trigger.role.c_str(),
221 x.trigger.area.c_str(),
224 for (const auto& y : x.sync_draw_req){
226 "Action : (APPID :%s, ROLE :%s, AREA :%s, END_DRAW_FINISHED: %d)",
230 y.end_draw_finished);
233 DUMP("======= req dump end =====\n");