Improve homescreen-service
[apps/agl-service-homescreen.git] / src / hs-client.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_CLIENT_H
18 #define HOMESCREEN_CLIENT_H
19
20 #include <string>
21 #include <unordered_set>
22 #include <unordered_map>
23 #include "hs-helper.h"
24
25
26 class HS_Client {
27 public:
28     HS_Client(afb_req_t request, const char* id) : HS_Client(request, std::string(id)){}
29     HS_Client(afb_req_t request, std::string id);
30     HS_Client(HS_Client&) = delete;
31     HS_Client &operator=(HS_Client&) = delete;
32     ~HS_Client();
33
34     int handleRequest(afb_req_t request, const char *verb);
35
36 private:
37     int tap_shortcut(afb_req_t request);
38     int on_screen_message (afb_req_t request);
39     int on_screen_reply (afb_req_t request);
40     int showWindow(afb_req_t request);
41     int hideWindow(afb_req_t request);
42     int replyShowWindow(afb_req_t request);
43     int subscribe(afb_req_t request);
44     int unsubscribe(afb_req_t request);
45     int showNotification(afb_req_t request);
46     int showInformation(afb_req_t request);
47
48     typedef int (HS_Client::*func_handler)(afb_req_t);
49     const std::unordered_map<std::string, func_handler> func_list {
50         {"tap_shortcut",        &HS_Client::tap_shortcut},
51         {"showWindow",          &HS_Client::showWindow},
52         {"hideWindow",          &HS_Client::hideWindow},
53         {"replyShowWindow",     &HS_Client::replyShowWindow},
54         {"on_screen_message",   &HS_Client::on_screen_message},
55         {"on_screen_reply",     &HS_Client::on_screen_reply},
56         {"subscribe",           &HS_Client::subscribe},
57         {"unsubscribe",         &HS_Client::unsubscribe},
58         {"showNotification",    &HS_Client::showNotification},
59         {"showInformation",     &HS_Client::showInformation}
60     };
61     bool checkEvent(const char* event);
62     bool isSupportEvent(const char* event);
63
64 private:
65     std::string my_id;
66     afb_event_t my_event;
67     bool subscription = false;
68     std::unordered_set<std::string> event_list;
69
70 };
71
72 #endif // HOMESCREEN_CLIENT_H