2 * Copyright (c) 2018 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.
17 #include "hs-clientmanager.h"
18 #include "hmi-debug.h"
20 HS_ClientManager* HS_ClientManager::me = nullptr;
22 static void cbRemoveClientCtxt(void *data)
24 HS_ClientManager::instance()->removeClientCtxt(data);
28 * HS_ClientManager construction function
37 HS_ClientManager::HS_ClientManager()
48 * HS_ClientManager instance pointer
51 HS_ClientManager* HS_ClientManager::instance(void)
54 me = new HS_ClientManager();
60 * HS_ClientManager init function
69 int HS_ClientManager::init(void)
71 HMI_NOTICE("homescreen-service","called.");
72 // TODO : connect to windowmanger
73 // get applist from appfw
77 * find HS_Client in client_list
83 * found HS_Client pointer
86 HS_Client* HS_ClientManager::find(std::string appid)
88 std::lock_guard<std::mutex> lock(this->mtx);
89 HS_Client* p = nullptr;
90 auto ip = client_list.find(appid);
91 if(ip != client_list.end()) {
92 p = client_list[appid];
104 * found HS_Client pointer
107 HS_Client* HS_ClientManager::getClient(afb_req req, std::string appid)
109 std::lock_guard<std::mutex> lock(this->mtx);
110 HS_Client* p = nullptr;
111 auto ip = client_list.find(appid);
112 if(ip != client_list.end()) {
113 p = client_list[appid];
116 appid2ctxt[appid] = createClientCtxt(req, appid);
117 p = addClient(req, appid);
123 * get HS_Client pointers set
129 * HS_Client pointers set
132 std::vector<HS_Client*> HS_ClientManager::getAllClient(void)
134 std::lock_guard<std::mutex> lock(this->mtx);
135 std::vector<HS_Client*> v;
136 for(auto a : client_list)
137 v.push_back(a.second);
142 * create client's afb_req_context
148 * HS_ClientCtxt pointer
151 HS_ClientCtxt* HS_ClientManager::createClientCtxt(afb_req req, std::string appid)
153 HS_ClientCtxt *ctxt = (HS_ClientCtxt *)afb_req_context_get(req);
156 HMI_NOTICE("homescreen-service", "create new session for %s", appid.c_str());
157 HS_ClientCtxt *ctxt = new HS_ClientCtxt(appid.c_str());
158 afb_req_session_set_LOA(req, 1);
159 afb_req_context_set(req, ctxt, cbRemoveClientCtxt);
174 HS_Client* HS_ClientManager::addClient(afb_req req, std::string appid)
176 return (client_list[appid] = new HS_Client(req, appid));
189 void HS_ClientManager::removeClient(std::string appid)
191 delete client_list[appid];
192 client_list.erase(appid);
196 * remove Client from list
199 * - data: HS_ClientCtxt pointer
205 void HS_ClientManager::removeClientCtxt(void *data)
207 HS_ClientCtxt *ctxt = (HS_ClientCtxt *)data;
210 HMI_ERROR("homescreen-service", "data is nullptr");
214 HMI_NOTICE("homescreen-service", "remove app %s", ctxt->id.c_str());
215 std::lock_guard<std::mutex> lock(this->mtx);
216 removeClient(ctxt->id);
217 delete appid2ctxt[ctxt->id];
218 appid2ctxt.erase(ctxt->id);