783b01ac842d58f08bd3d081acc2276cd45b77dd
[apps/agl-service-homescreen.git] / src / hs-periphery.cpp
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
17 #include "hs-periphery.h"
18 #include "hs-proxy.h"
19 #include "hmi-debug.h"
20 #include "hs-clientmanager.h"
21
22
23 /* -------------------------------------HS_PeripheryManager------------------------------------------ */
24
25 HS_PeripheryManager* HS_PeripheryManager::me = nullptr;
26
27 /**
28  * HS_PeripheryManager init function
29  *
30  * #### Parameters
31  *  - Nothing
32  *
33  * #### Return
34  * init result
35  *
36  */
37 int HS_PeripheryManager::init(afb_api_t api)
38 {
39     HS_Restriction* restriction = new HS_Restriction();
40     int ret = restriction->init(api);
41     if(ret) {
42         HMI_ERROR("homescreen-service","restriction init failed.");
43     }
44     else {
45         periphery_list[restriction->getAppid()] = restriction;
46     }
47     return ret;
48 }
49
50 /**
51  * get instance
52  *
53  * #### Parameters
54  *  - Nothing
55  *
56  * #### Return
57  * HS_PeripheryManager instance pointer
58  *
59  */
60 HS_PeripheryManager* HS_PeripheryManager::instance(void)
61 {
62     if(me == nullptr)
63         me = new HS_PeripheryManager();
64     return me;
65 }
66
67 /**
68  * event function
69  *
70  * #### Parameters
71  *  - api : the api serving the request
72  *  - event  : event name
73  *  - object : event json object
74  *
75  * #### Return
76  * None
77  *
78  */
79 void HS_PeripheryManager::onEvent(afb_api_t api, const char *event, struct json_object *object)
80 {
81     for(auto m : periphery_list)
82         m.second->onEvent(api, event, object);
83 }
84
85 /* -------------------------------------HS_Restriction------------------------------------------ */
86
87 /**
88  * HS_Restriction init function
89  *
90  * #### Parameters
91  *  - Nothing
92  *
93  * #### Return
94  * init result
95  *
96  */
97 int HS_Restriction::init(afb_api_t api)
98 {
99     HS_WmProxy wm_proxy;
100     // TBD
101     wm_proxy.subscribe(api, HS_WmProxy::Event_ScreenUpdated);
102     return 0;
103 }
104
105 /**
106  * event function
107  *
108  * #### Parameters
109  *  - api : the api serving the request
110  *  - event  : event name
111  *  - object : event json object
112  *
113  * #### Return
114  * None
115  *
116  */
117 void HS_Restriction::onEvent(afb_api_t api, const char *event, struct json_object *object)
118 {
119     auto ip = concerned_event_list.find(std::string(event));
120     if(ip != concerned_event_list.end()) {
121         HMI_NOTICE("homescreen-service","[%s] event received.", event);
122         (this->*(ip->second))(api, object);
123     }
124 }
125
126 /**
127  * restriction on function
128  *
129  * #### Parameters
130  *  - api : the api serving the request
131  *  - object : event json object
132  *
133  * #### Return
134  * None
135  *
136  */
137 void HS_Restriction::restrictionOn(afb_api_t api, struct json_object *object)
138 {
139
140 }
141
142 /**
143  * restriction off function
144  *
145  * #### Parameters
146  *  - api : the api serving the request
147  *  - object : event json object
148  *
149  * #### Return
150  * None
151  *
152  */
153 void HS_Restriction::restrictionOff(afb_api_t api, struct json_object *object)
154 {
155
156 }