2 * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "hs-periphery.h"
19 #include "hmi-debug.h"
20 #include "hs-clientmanager.h"
22 static const char _restriction_on[] = "RestrictionOn";
23 static const char _restriction_off[] = "RestrictionOff";
25 /* -------------------------------------HS_PeripheryManager------------------------------------------ */
27 HS_PeripheryManager* HS_PeripheryManager::me = nullptr;
30 * HS_PeripheryManager init function
39 int HS_PeripheryManager::init(afb_api_t api)
41 HS_Restriction* restriction = new HS_Restriction();
42 int ret = restriction->init(api);
44 HMI_ERROR("homescreen-service","restriction init failed.");
47 periphery_list[std::string("restriction")] = restriction;
59 * HS_PeripheryManager instance pointer
62 HS_PeripheryManager* HS_PeripheryManager::instance(void)
65 me = new HS_PeripheryManager();
73 * - api : the api serving the request
74 * - event : event name
75 * - object : event json object
81 void HS_PeripheryManager::onEvent(afb_api_t api, const char *event, struct json_object *object)
83 for(auto m : periphery_list)
84 m.second->onEvent(api, event, object);
87 /* -------------------------------------HS_Restriction------------------------------------------ */
90 * HS_Restriction init function
99 int HS_Restriction::init(afb_api_t api)
103 wm_proxy.subscribe(api, HS_WmProxy::Event_ScreenUpdated);
111 * - api : the api serving the request
112 * - event : event name
113 * - object : event json object
119 void HS_Restriction::onEvent(afb_api_t api, const char *event, struct json_object *object)
121 if(!isConcernedEvent(event))
124 std::string ev = event;
125 std::size_t pos = ev.find("/");
126 if(pos != std::string::npos) {
127 ev = ev.substr(pos + 1);
130 HMI_ERROR("homescreen-service","received event is error.");
134 if(ev == _restriction_on) {
135 restrictionOn(api, object);
137 else if(ev == _restriction_off) {
138 restrictionOff(api, object);
145 * restriction on function
148 * - api : the api serving the request
149 * - object : event json object
155 void HS_Restriction::restrictionOn(afb_api_t api, struct json_object *object)
161 * restriction off function
164 * - api : the api serving the request
165 * - object : event json object
171 void HS_Restriction::restrictionOff(afb_api_t api, struct json_object *object)