d2da39eaa6f73d4cc47d8453978edb759e25a55d
[apps/agl-service-homescreen.git] / src / hs-periphery.h
1 /*
2  * Copyright (c) 2019 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 #ifndef HOMESCREEN_PERIPHERY_H
17 #define HOMESCREEN_PERIPHERY_H
18
19 #include <unordered_set>
20 #include <unordered_map>
21 #include "hs-helper.h"
22
23 class HS_Periphery {
24 public:
25     virtual int init(afb_api_t api) = 0;
26     virtual void onEvent(afb_api_t api, const char *event, struct json_object *object) = 0;
27 };
28
29 class HS_Restriction : public HS_Periphery {
30 public:
31     HS_Restriction() = default;
32     ~HS_Restriction() = default;
33
34     int init(afb_api_t api);
35     void onEvent(afb_api_t api, const char *event, struct json_object *object);
36
37 private:
38     const std::unordered_set<const char*> concerned_event_list {
39         "windowmanager/RestrictionOn",
40         "windowmanager/RestrictionOff"
41     };
42     inline bool isConcernedEvent(const char* event) const {
43         return (concerned_event_list.find(event) != concerned_event_list.end()) ? true : false;
44     }
45
46     void restrictionOn(afb_api_t api, struct json_object *object);
47     void restrictionOff(afb_api_t api, struct json_object *object);
48
49     std::string m_appid = "restriction";
50 };
51
52 class HS_PeripheryManager {
53 public:
54     HS_PeripheryManager() = default;
55     ~HS_PeripheryManager() = default;
56
57     int init(afb_api_t api);
58     static HS_PeripheryManager* instance(void);
59     void onEvent(afb_api_t api, const char *event, struct json_object *object);
60
61     inline bool isPeripheryApp(const char* name) const {
62         return (periphery_app_list.find(name) != periphery_app_list.end()) ? true : false;
63     }
64
65 private:
66     const std::unordered_set<const char*> periphery_app_list {
67         "launcher",
68         "homescreen",
69         "onscreenapp",
70         "restriction"
71     };
72
73     static HS_PeripheryManager* me;
74     std::unordered_map<std::string, HS_Periphery*> periphery_list;
75     // HS_Restriction m_restriction;
76 };
77
78 #endif // HOMESCREEN_PERIPHERY_H