06e95eada2a342ed679d8cf2cf36fc1f6c0508b1
[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 static const char _restriction_on[] = "RestrictionOn";
23 static const char _restriction_off[] = "RestrictionOff";
24
25 /* -------------------------------------HS_PeripheryManager------------------------------------------ */
26
27 HS_PeripheryManager* HS_PeripheryManager::me = nullptr;
28
29 /**
30  * HS_PeripheryManager init function
31  *
32  * #### Parameters
33  *  - Nothing
34  *
35  * #### Return
36  * init result
37  *
38  */
39 int HS_PeripheryManager::init(afb_api_t api)
40 {
41     HS_Restriction* restriction = new HS_Restriction();
42     int ret = restriction->init(api);
43     if(ret) {
44         HMI_ERROR("homescreen-service","restriction init failed.");
45     }
46     else {
47         periphery_list[std::string("restriction")] = restriction;
48     }
49     return ret;
50 }
51
52 /**
53  * get instance
54  *
55  * #### Parameters
56  *  - Nothing
57  *
58  * #### Return
59  * HS_PeripheryManager instance pointer
60  *
61  */
62 HS_PeripheryManager* HS_PeripheryManager::instance(void)
63 {
64     if(me == nullptr)
65         me = new HS_PeripheryManager();
66     return me;
67 }
68
69 /**
70  * event function
71  *
72  * #### Parameters
73  *  - api : the api serving the request
74  *  - event  : event name
75  *  - object : event json object
76  *
77  * #### Return
78  * None
79  *
80  */
81 void HS_PeripheryManager::onEvent(afb_api_t api, const char *event, struct json_object *object)
82 {
83     for(auto m : periphery_list)
84         m.second->onEvent(api, event, object);
85 }
86
87 /* -------------------------------------HS_Restriction------------------------------------------ */
88
89 /**
90  * HS_Restriction init function
91  *
92  * #### Parameters
93  *  - Nothing
94  *
95  * #### Return
96  * init result
97  *
98  */
99 int HS_Restriction::init(afb_api_t api)
100 {
101     HS_WmProxy wm_proxy;
102     // TBD
103     wm_proxy.subscribe(api, HS_WmProxy::Event_ScreenUpdated);
104     return 0;
105 }
106
107 /**
108  * event function
109  *
110  * #### Parameters
111  *  - api : the api serving the request
112  *  - event  : event name
113  *  - object : event json object
114  *
115  * #### Return
116  * None
117  *
118  */
119 void HS_Restriction::onEvent(afb_api_t api, const char *event, struct json_object *object)
120 {
121     if(!isConcernedEvent(event))
122         return;
123
124     std::string ev = event;
125     std::size_t pos = ev.find("/");
126     if(pos != std::string::npos) {
127         ev = ev.substr(pos + 1);
128     }
129     else {
130         HMI_ERROR("homescreen-service","received event is error.");
131         return;
132     }
133
134     if(ev == _restriction_on) {
135         restrictionOn(api, object);
136     }
137     else if(ev == _restriction_off) {
138         restrictionOff(api, object);
139     }
140     else {
141     }
142 }
143
144 /**
145  * restriction on function
146  *
147  * #### Parameters
148  *  - api : the api serving the request
149  *  - object : event json object
150  *
151  * #### Return
152  * None
153  *
154  */
155 void HS_Restriction::restrictionOn(afb_api_t api, struct json_object *object)
156 {
157
158 }
159
160 /**
161  * restriction off function
162  *
163  * #### Parameters
164  *  - api : the api serving the request
165  *  - object : event json object
166  *
167  * #### Return
168  * None
169  *
170  */
171 void HS_Restriction::restrictionOff(afb_api_t api, struct json_object *object)
172 {
173
174 }