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.
18 #include "hmi-debug.h"
20 static const char _windowmanager[] = "windowmanager";
21 static const char _event[] = "event";
25 * the callback function
28 * - closure : the user defined closure pointer 'closure'
29 * - object : a JSON object returned (can be NULL)
30 * - error : a string not NULL in case of error but NULL on success
31 * - info : a string handling some info (can be NULL)
38 static void api_callback(void *closure, struct json_object *object, const char *error, const char *info, afb_api_t api)
40 HMI_NOTICE("homescreen-service","asynchronous call, error=%s, info=%s, object=%s.", error, info, json_object_get_string(object));
41 callback_func* f = (callback_func*)closure;
47 * call api asynchronous
50 * - api : the api serving the request
51 * - service : the api name of service
52 * - verb : the verb of service
59 static void api_call(afb_api_t api, const char *service, const char *verb, struct json_object *args, callback_func *f = nullptr)
61 HMI_NOTICE("homescreen-service","service=%s verb=%s, args=%s.", service, verb, json_object_get_string(args));
62 afb_api_call(api, service, verb, args, api_callback, (void*)f);
66 * call api synchronous
69 * - api : the api serving the request
70 * - service : the api name of service
71 * - verb : the verb of afm-main
73 * - object : return the details of application
80 static int api_call_sync(afb_api_t api, const char *service, const char *verb, struct json_object *args, struct json_object **object)
82 char *error = nullptr, *info = nullptr;
83 int ret = afb_api_call_sync(api, service, verb, args, object, &error, &info);
84 HMI_NOTICE("homescreen-service","synchronous call, error=%s, info=%s.", error, info);
89 * subscribe windowmanager event
92 * - api : the api serving the request
93 * - event : windowmanager event
99 void HS_WmProxy::subscribe(afb_api_t api, EventType event)
101 struct json_object* push_obj = json_object_new_object();
102 json_object_object_add(push_obj, _event, json_object_new_int(event));
103 api_call(api, _windowmanager, "wm_subscribe", push_obj);