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 const char _afm_main[] = "afm-main";
24 * the callback function
27 * - closure : the user defined closure pointer 'closure'
28 * - object : a JSON object returned (can be NULL)
29 * - error : a string not NULL in case of error but NULL on success
30 * - info : a string handling some info (can be NULL)
37 static void api_callback(void *closure, struct json_object *object, const char *error, const char *info, afb_api_t api)
39 HMI_DEBUG("homescreen-service","asynchronous call, error=%s, info=%s, object=%s.", error, info, json_object_get_string(object));
43 * call api asynchronous
46 * - api : the api serving the request
47 * - service : the api name of service
48 * - verb : the verb of service
55 static void api_call(afb_api_t api, const char *service, const char *verb, struct json_object *args)
57 HMI_DEBUG("homescreen-service","service=%s verb=%s, args=%s.", service, verb, json_object_get_string(args));
58 afb_api_call(api, service, verb, args, api_callback, nullptr);
62 * call api synchronous
65 * - api : the api serving the request
66 * - service : the api name of service
67 * - verb : the verb of afm-main
69 * - object : return the details of application
76 static int api_call_sync(afb_api_t api, const char *service, const char *verb, struct json_object *args, struct json_object **object)
78 char *error = nullptr, *info = nullptr;
79 int ret = afb_api_call_sync(api, service, verb, args, object, &error, &info);
80 HMI_DEBUG("homescreen-service","synchronous call, error=%s, info=%s.", error, info);
85 * get runnables application list
88 * - api : the api serving the request
89 * - object : return the details of appid
96 int HS_AfmMainProxy::runnables(afb_api_t api, struct json_object **object)
98 return api_call_sync(api, _afm_main, __FUNCTION__, nullptr, object);
102 * get details of application
105 * - api : the api serving the request
106 * - id : the id to get details,liked "dashboard@0.1"
107 * - object : return the details of application
114 int HS_AfmMainProxy::detail(afb_api_t api, const std::string &id, struct json_object **object)
116 struct json_object *args = json_object_new_string(id.c_str());
117 return api_call_sync(api, _afm_main, __FUNCTION__, args, object);
124 * - request : the request
125 * - id : the application id liked "dashboard@0.1"
131 void HS_AfmMainProxy::start(afb_req_t request, const std::string &id)
133 struct json_object *args = json_object_new_string(id.c_str());
134 api_call(request->api, _afm_main, __FUNCTION__, args);