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;
31 void AppList::addClient(const std::string &appid, const std::string &role){
32 shared_ptr<WMClient> client(new WMClient(appid, role));
33 client_list[appid] = client;
36 void AppList::removeClient(const string &appid){
37 client_list.erase(appid);
40 bool AppList::contains(const string &appid){
41 auto result = client_list.find(appid);
42 return (client_list.end() != result) ? true : false;
46 * Call contains before calling this function
48 shared_ptr <WMClient> AppList::lookUpClient(const string &appid)
50 /* auto result = client_list.find(appid);
51 return (client_list.end() != result) ?
52 &(result->second()) : nullptr; */
53 return client_list[appid];
56 unsigned AppList::currentSequenceNumber(){
60 unsigned AppList::getSequenceNumber(const string &appid){
61 for(auto x : req_list){
62 // Since app will not request twice and more, comparing appid is enough?
63 if( (x.appid == appid))
71 unsigned AppList::addAllocateRequest(WMRequest req){
72 req.seq_num = req_list.back().seq_num + 1;
73 req.allocating = false;
74 req.end_draw_finished = false;
75 req_list.push_back(req);
79 bool AppList::requestFinished(){
80 return req_list.empty();
83 unsigned AppList::lookUpAllocatingApp(const string &appid){
84 for(auto x: req_list){
86 if(false == x.allocating)
93 void AppList::setEndDrawFinished(unsigned request_seq, const string &role){
94 for(auto x: req_list){
95 if(request_seq == x.seq_num){
97 x.end_draw_finished = true;
103 bool AppList::endDrawFullfilled(unsigned request_seq){
105 for (auto x : req_list)
107 if(request_seq < x.seq_num){
110 if(request_seq == x.seq_num){
111 result = x.end_draw_finished && x.allocating;
120 void AppList::removeRequest(unsigned req_seq){
121 req_list.erase(remove_if(req_list.begin(), req_list.end(),
122 [req_seq](WMRequest x) { return x.seq_num == req_seq;}
126 void AppList::setCurrentSequence(unsigned req_seq){
127 this->current_seq = req_seq;
128 if(0 == this->current_seq){
129 this->current_seq = 1;
133 bool AppList::haveRequest(){