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 #ifndef HOMESCREEN_CLIENTMANAGER_H
18 #define HOMESCREEN_CLIENTMANAGER_H
23 #include <unordered_map>
26 #include "hs-helper.h"
27 #include "hs-client.h"
30 class listener_interface {
32 listener_interface(std::string uid, std::set<std::string> listen_appid = std::set<std::string>()) : m_uid(uid), m_listen_appid(listen_appid) {}
33 virtual ~listener_interface() {}
34 virtual void notify(afb_api_t api, std::string appid = "") = 0;
35 std::string myUid(void) {return m_uid;}
36 void addListenAppId(const std::string &appid) {m_listen_appid.insert(appid);}
37 void removeListenAppId(const std::string &appid) {m_listen_appid.erase(appid);}
38 bool isListenAppId(const std::string &appid) {
39 auto it = m_listen_appid.find(appid);
40 return it != m_listen_appid.end() ? true : false;
42 bool listenAppEmpty(void) {return m_listen_appid.empty();}
43 void clearListenAppSet(void) {m_listen_appid.clear();}
46 std::set<std::string> m_listen_appid;
49 typedef struct HS_ClientCtxt
52 HS_ClientCtxt(const char *appid)
59 class HS_ClientManager {
62 ~HS_ClientManager() = default;
63 HS_ClientManager(HS_ClientManager const &) = delete;
64 HS_ClientManager &operator=(HS_ClientManager const &) = delete;
65 HS_ClientManager(HS_ClientManager &&) = delete;
66 HS_ClientManager &operator=(HS_ClientManager &&) = delete;
68 static HS_ClientManager* instance(void);
70 int handleRequest(afb_req_t request, const char *verb, const char *appid = nullptr);
71 int pushEvent(const char *event, struct json_object *param, std::string appid = "");
72 void removeClientCtxt(void *data); // don't use, internal only
73 void setStartupAppidAndArea(const std::pair<std::string, std::string> pair) {startup_appid = pair.first;startup_area = pair.second;}
74 bool isAppStarted(const std::string &appid);
75 void addListener(listener_interface* listener);
76 void removeListener(listener_interface* listener);
79 HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid);
80 HS_Client* addClient(afb_req_t req, std::string appid);
81 void removeClient(std::string appid);
82 void notifyListener(afb_api_t api, const std::string &appid);
85 static HS_ClientManager* me;
86 std::unordered_map<std::string, listener_interface*> listener_list;
87 std::unordered_map<std::string, HS_Client*> client_list;
88 std::unordered_map<std::string, HS_ClientCtxt*> appid2ctxt;
90 std::string startup_appid, startup_area;
93 #endif // HOMESCREEN_CLIENTMANAGER_H