add event tabble
[apps/agl-service-homescreen.git] / src / hs-clientmanager.h
1 /*
2  * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef HOMESCREEN_CLIENTMANAGER_H
18 #define HOMESCREEN_CLIENTMANAGER_H
19
20 #include <string>
21 #include <mutex>
22 #include <memory>
23 #include <unordered_map>
24 #include "hs-helper.h"
25 #include "hs-client.h"
26
27 typedef struct HS_ClientCtxt
28 {
29     std::string id;
30     HS_ClientCtxt(const char *appid)
31     {
32         id = appid;
33     }
34 } HS_ClientCtxt;
35
36
37 class HS_ClientManager {
38 public:
39     HS_ClientManager();
40     ~HS_ClientManager() = default;
41     HS_ClientManager(HS_ClientManager const &) = delete;
42     HS_ClientManager &operator=(HS_ClientManager const &) = delete;
43     HS_ClientManager(HS_ClientManager &&) = delete;
44     HS_ClientManager &operator=(HS_ClientManager &&) = delete;
45
46     static HS_ClientManager* instance(void);
47     int init(void);
48     void removeClientCtxt(void *data);
49
50     int tap_shortcut(afb_req_t request);
51     int showWindow(afb_req_t request);
52     int hideWindow(afb_req_t request);
53     int replyShowWindow(afb_req_t request);
54     int on_screen_message(afb_req_t request);
55     int on_screen_reply(afb_req_t request);
56     int subscribe(afb_req_t request);
57     int unsubscribe(afb_req_t request);
58     int showNotification(afb_req_t request);
59     int showInformation(afb_req_t request);
60     int handleRequest(const char *verb, afb_req_t request);
61     int pushEvent(const char *event, struct json_object *param, std::string appid = "");
62
63 private:
64     HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid);
65     HS_Client* addClient(afb_req_t req, std::string appid);
66     void removeClient(std::string appid);
67
68     typedef int (HS_ClientManager::*func_handler)(afb_req_t);
69     const std::unordered_map<std::string, func_handler> func_list {
70         {"tap_shortcut",        &HS_ClientManager::tap_shortcut},
71         {"showWindow",          &HS_ClientManager::showWindow},
72         {"hideWindow",          &HS_ClientManager::hideWindow},
73         {"replyShowWindow",     &HS_ClientManager::replyShowWindow},
74         {"on_screen_message",   &HS_ClientManager::on_screen_message},
75         {"on_screen_reply",     &HS_ClientManager::on_screen_reply},
76         {"subscribe",           &HS_ClientManager::subscribe},
77         {"unsubscribe",         &HS_ClientManager::unsubscribe},
78         {"showNotification",    &HS_ClientManager::showNotification},
79         {"showInformation",     &HS_ClientManager::showInformation}
80     };
81
82 private:
83     static HS_ClientManager* me;
84     std::unordered_map<std::string, HS_Client*> client_list;
85     std::unordered_map<std::string, HS_ClientCtxt*> appid2ctxt;
86     std::mutex mtx;
87 };
88
89 #endif // HOMESCREEN_CLIENTMANAGER_H