X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=doc%2Fapi-ref%2Fhtml%2Fd0%2Fd1e%2Fhomescreen_8c_source.html;h=6a4f516e2d5edf86fdfcefc9d623f198743243bc;hb=599de8d3f35cb0fe56c7e27591862d61944b456b;hp=ad664697719c766be61460331155a3176fb1f045;hpb=26ec25e2f9271396328c208ae1a256fdf1a92c91;p=apps%2Fagl-service-homescreen.git diff --git a/doc/api-ref/html/d0/d1e/homescreen_8c_source.html b/doc/api-ref/html/d0/d1e/homescreen_8c_source.html index ad66469..6a4f516 100644 --- a/doc/api-ref/html/d0/d1e/homescreen_8c_source.html +++ b/doc/api-ref/html/d0/d1e/homescreen_8c_source.html @@ -5,7 +5,7 @@ -HomeScreenBinding: homescreen_service/homescreen.c Source File +HomeScreenBinding: src/homescreen.c Source File @@ -58,7 +58,7 @@ $(function() {
@@ -66,32 +66,36 @@ $(function() {
homescreen.c
-Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 #define _GNU_SOURCE
18 #define AFB_BINDING_VERSION 2
19 #include <afb/afb-binding.h>
20 
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdint.h>
25 #include <unistd.h>
26 #include <json-c/json.h>
27 #include <glib.h>
28 #include <pthread.h>
29 #include "hs-helper.h"
30 
31 #define COMMAND_EVENT_NUM 3
32 #define EVENT_SUBSCRIBE_ERROR_CODE 100
33 
34 /* To Do hash table is better */
35 struct event{
36  const char* name;
37  struct afb_event* event;
38  };
39 
41 
42 static struct afb_event ev_tap_shortcut;
43 static struct afb_event ev_on_screen_message;
44 static struct afb_event ev_reserved;
45 
46 static const char _error[] = "error";
47 
48 static const char _application_name[] = "application_name";
49 static const char _display_message[] = "display_message";
50 
51 /*
52 ********** Method of HomeScreen Service (API) **********
53 */
54 
55 static void pingSample(struct afb_req request)
56 {
57  static int pingcount = 0;
58  afb_req_success_f(request, json_object_new_int(pingcount), "Ping count = %d", pingcount);
59  AFB_NOTICE("Verbosity macro at level notice invoked at ping invocation count = %d", pingcount);
60  pingcount++;
61 }
62 
76 static void tap_shortcut (struct afb_req request)
77 {
78  AFB_NOTICE("%s is called.", __FUNCTION__);
79 
80  int ret = 0;
81  const char* value = afb_req_value(request, _application_name);
82  if (value) {
83 
84  AFB_NOTICE("request params = %s.", value);
85 
86  struct json_object* push_obj = json_object_new_object();
88  _application_name, value);
89  afb_event_push(ev_tap_shortcut, push_obj);
90  } else {
91  afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
92  return;
93  }
94 
95  // HomeScreenに返すレスポンス
96  struct json_object *res = json_object_new_object();
97  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
98  _error, ret);
99  afb_req_success(request, res, "afb_event_push event [tap_shortcut]");
100 }
101 
113 static void on_screen_message (struct afb_req request)
114 {
115  AFB_NOTICE("%s is called.", __FUNCTION__);
116 
117  int ret = 0;
118  const char* value = afb_req_value(request, _display_message);
119  if (value) {
120 
121  AFB_NOTICE("request params = %s.", value);
122 
123  struct json_object* push_obj = json_object_new_object();
125  _display_message, value);
126  afb_event_push(ev_on_screen_message, push_obj);
127  } else {
128  afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
129  return;
130  }
131 
132  // HomeScreenに返すレスポンス
133  struct json_object *res = json_object_new_object();
134  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
135  _error, ret);
136  afb_req_success(request, res, "afb_event_push event [on_screen_message]");
137 }
138 
151 static void subscribe(struct afb_req request)
152 {
153  const char *value = afb_req_value(request, "event");
154  AFB_NOTICE("value is %s", value);
155  int ret = 0;
156  if(value) {
157  int index = hs_search_event_name_index(value);
158  if(index < 0)
159  {
160  AFB_NOTICE("dedicated event doesn't exist");
162  }
163  else
164  {
165  afb_req_subscribe(request, *event_list[index].event);
166  }
167  }
168  else{
169  AFB_NOTICE("Please input event name");
171  }
172  /*create response json object*/
173  struct json_object *res = json_object_new_object();
174  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
175  _error, ret);
176  afb_req_success_f(request, res, "homescreen binder subscribe event name [%s]", value);
177 }
178 
191 static void unsubscribe(struct afb_req request)
192 {
193  const char *value = afb_req_value(request, "event");
194  AFB_NOTICE("value is %s", value);
195  int ret = 0;
196  if(value) {
197  int index = hs_search_event_name_index(value);
198  if(index < 0)
199  {
200  AFB_NOTICE("dedicated event doesn't exist");
202  }
203  else
204  {
205  afb_req_unsubscribe(request, *event_list[index].event);
206  }
207  }
208  else{
209  AFB_NOTICE("Please input event name");
211  }
212  /*create response json object*/
213  struct json_object *res = json_object_new_object();
214  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
215  _error, ret);
216  afb_req_success_f(request, res, "homescreen binder unsubscribe event name [%s]", value);
217 }
218 
219 /*
220  * array of the verbs exported to afb-daemon
221  */
222 static const struct afb_verb_v2 verbs[]= {
223  /* VERB'S NAME SESSION MANAGEMENT FUNCTION TO CALL */
224  { .verb = "ping", .session = AFB_SESSION_NONE, .callback = pingSample, .auth = NULL },
225  { .verb = "tap_shortcut", .session = AFB_SESSION_NONE, .callback = tap_shortcut, .auth = NULL },
226  { .verb = "on_screen_message", .session = AFB_SESSION_NONE, .callback = on_screen_message, .auth = NULL },
227  { .verb = "subscribe", .session = AFB_SESSION_NONE, .callback = subscribe, .auth = NULL },
228  { .verb = "unsubscribe", .session = AFB_SESSION_NONE, .callback = unsubscribe, .auth = NULL },
229  {NULL } /* marker for end of the array */
230 };
231 
232 static int preinit()
233 {
234  AFB_NOTICE("binding preinit (was register)");
235  return 0;
236 }
237 
238 static int init()
239 {
240  AFB_NOTICE("binding init");
241 
242  ev_tap_shortcut = afb_daemon_make_event(evlist[0]);
243  ev_on_screen_message = afb_daemon_make_event(evlist[1]);
244  ev_reserved = afb_daemon_make_event(evlist[2]);
245 
246  event_list[0].name = evlist[0];
248 
249  event_list[1].name = evlist[1];
251 
252  event_list[2].name = evlist[2];
254 
255  return 0;
256 }
257 
258 static void onevent(const char *event, struct json_object *object)
259 {
260  AFB_NOTICE("on_event %s", event);
261 }
262 
263 const struct afb_binding_v2 afbBindingV2 = {
264  .api = "homescreen",
265  .specification = NULL,
266  .verbs = verbs,
267  .preinit = preinit,
268  .init = init,
269  .onevent = onevent
270 };
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:110
+Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 #define _GNU_SOURCE
18 #define AFB_BINDING_VERSION 2
19 #include <afb/afb-binding.h>
20 
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdint.h>
25 #include <unistd.h>
26 #include <json-c/json.h>
27 #include <glib.h>
28 #include <pthread.h>
29 #include "hs-helper.h"
30 
31 #define COMMAND_EVENT_NUM 4
32 #define EVENT_SUBSCRIBE_ERROR_CODE 100
33 
34 /* To Do hash table is better */
35 struct event{
36  const char* name;
37  struct afb_event* event;
38  };
39 
41 
42 static struct afb_event ev_tap_shortcut;
43 static struct afb_event ev_on_screen_message;
44 static struct afb_event ev_on_screen_reply;
45 static struct afb_event ev_reserved;
46 
47 static const char _error[] = "error";
48 
49 static const char _application_name[] = "application_name";
50 static const char _display_message[] = "display_message";
51 static const char _reply_message[] = "reply_message";
52 
53 /*
54 ********** Method of HomeScreen Service (API) **********
55 */
56 
57 static void pingSample(struct afb_req request)
58 {
59  static int pingcount = 0;
60  afb_req_success_f(request, json_object_new_int(pingcount), "Ping count = %d", pingcount);
61  HMI_NOTICE("homescreen-service","Verbosity macro at level notice invoked at ping invocation count = %d", pingcount);
62  pingcount++;
63 }
64 
77 static void tap_shortcut (struct afb_req request)
78 {
79  HMI_NOTICE("homescreen-service","is called.");
80 
81  int ret = 0;
82  const char* value = afb_req_value(request, _application_name);
83  if (value) {
84 
85  HMI_NOTICE("homescreen-service","request params = %s.", value);
86 
87  struct json_object* push_obj = json_object_new_object();
89  _application_name, value);
90  afb_event_push(ev_tap_shortcut, push_obj);
91  } else {
92  afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
93  return;
94  }
95 
96  // response to HomeScreen
97  struct json_object *res = json_object_new_object();
98  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
99  _error, ret);
100  afb_req_success(request, res, "afb_event_push event [tap_shortcut]");
101 }
102 
114 static void on_screen_message (struct afb_req request)
115 {
116  HMI_NOTICE("homescreen-service","is called.");
117 
118  int ret = 0;
119  const char* value = afb_req_value(request, _display_message);
120  if (value) {
121 
122  HMI_NOTICE("homescreen-service","request params = %s.", value);
123 
124  struct json_object* push_obj = json_object_new_object();
126  _display_message, value);
127  afb_event_push(ev_on_screen_message, push_obj);
128  } else {
129  afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
130  return;
131  }
132 
133  // response to HomeScreen
134  struct json_object *res = json_object_new_object();
135  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
136  _error, ret);
137  afb_req_success(request, res, "afb_event_push event [on_screen_message]");
138 }
139 
151 static void on_screen_reply (struct afb_req request)
152 {
153  HMI_NOTICE("homescreen-service","is called.");
154 
155  int ret = 0;
156  const char* value = afb_req_value(request, _reply_message);
157  if (value) {
158 
159  HMI_NOTICE("homescreen-service","request params = %s.", value);
160 
161  struct json_object* push_obj = json_object_new_object();
163  _reply_message, value);
164  afb_event_push(ev_on_screen_reply, push_obj);
165  } else {
166  afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
167  return;
168  }
169 
170  // response to HomeScreen
171  struct json_object *res = json_object_new_object();
172  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
173  _error, ret);
174  afb_req_success(request, res, "afb_event_push event [on_screen_reply]");
175 }
176 
189 static void subscribe(struct afb_req request)
190 {
191  const char *value = afb_req_value(request, "event");
192  HMI_NOTICE("homescreen-service","value is %s", value);
193  int ret = 0;
194  if(value) {
195  int index = hs_search_event_name_index(value);
196  if(index < 0)
197  {
198  HMI_NOTICE("homescreen-service","dedicated event doesn't exist");
200  }
201  else
202  {
203  afb_req_subscribe(request, *event_list[index].event);
204  }
205  }
206  else{
207  HMI_NOTICE("homescreen-service","Please input event name");
209  }
210  /*create response json object*/
211  struct json_object *res = json_object_new_object();
212  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
213  _error, ret);
214  afb_req_success_f(request, res, "homescreen binder subscribe event name [%s]", value);
215 }
216 
229 static void unsubscribe(struct afb_req request)
230 {
231  const char *value = afb_req_value(request, "event");
232  HMI_NOTICE("homescreen-service","value is %s", value);
233  int ret = 0;
234  if(value) {
235  int index = hs_search_event_name_index(value);
236  if(index < 0)
237  {
238  HMI_NOTICE("homescreen-service","dedicated event doesn't exist");
240  }
241  else
242  {
243  afb_req_unsubscribe(request, *event_list[index].event);
244  }
245  }
246  else{
247  HMI_NOTICE("homescreen-service","Please input event name");
249  }
250  /*create response json object*/
251  struct json_object *res = json_object_new_object();
252  hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
253  _error, ret);
254  afb_req_success_f(request, res, "homescreen binder unsubscribe event name [%s]", value);
255 }
256 
257 /*
258  * array of the verbs exported to afb-daemon
259  */
260 static const struct afb_verb_v2 verbs[]= {
261  /* VERB'S NAME SESSION MANAGEMENT FUNCTION TO CALL */
262  { .verb = "ping", .session = AFB_SESSION_NONE, .callback = pingSample, .auth = NULL },
263  { .verb = "tap_shortcut", .session = AFB_SESSION_NONE, .callback = tap_shortcut, .auth = NULL },
264  { .verb = "on_screen_message", .session = AFB_SESSION_NONE, .callback = on_screen_message, .auth = NULL },
265  { .verb = "on_screen_reply", .session = AFB_SESSION_NONE, .callback = on_screen_reply, .auth = NULL },
266  { .verb = "subscribe", .session = AFB_SESSION_NONE, .callback = subscribe, .auth = NULL },
267  { .verb = "unsubscribe", .session = AFB_SESSION_NONE, .callback = unsubscribe, .auth = NULL },
268  {NULL } /* marker for end of the array */
269 };
270 
271 static int preinit()
272 {
273  HMI_NOTICE("homescreen-service","binding preinit (was register)");
274  return 0;
275 }
276 
277 static int init()
278 {
279  HMI_NOTICE("homescreen-service","binding init");
280 
281  ev_tap_shortcut = afb_daemon_make_event(evlist[0]);
282  ev_on_screen_message = afb_daemon_make_event(evlist[1]);
283  ev_on_screen_reply = afb_daemon_make_event(evlist[2]);
284  ev_reserved = afb_daemon_make_event(evlist[3]);
285 
286  event_list[0].name = evlist[0];
288 
289  event_list[1].name = evlist[1];
291 
292  event_list[2].name = evlist[2];
294 
295  event_list[3].name = evlist[3];
297 
298  return 0;
299 }
300 
301 static void onevent(const char *event, struct json_object *object)
302 {
303  HMI_NOTICE("homescreen-service","on_event %s", event);
304 }
305 
306 const struct afb_binding_v2 afbBindingV2 = {
307  .api = "homescreen",
308  .specification = NULL,
309  .verbs = verbs,
310  .preinit = preinit,
311  .init = init,
312  .onevent = onevent
313 };
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:110
struct afb_event * event
Definition: homescreen.c:37
-
static int preinit()
Definition: homescreen.c:232
-
static void tap_shortcut(struct afb_req request)
Definition: homescreen.c:76
-
static const char _application_name[]
Definition: homescreen.c:48
-
static struct afb_event ev_reserved
Definition: homescreen.c:44
-
static const char _error[]
Definition: homescreen.c:46
-
static void pingSample(struct afb_req request)
Definition: homescreen.c:55
-
static void onevent(const char *event, struct json_object *object)
Definition: homescreen.c:258
+
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
static int preinit()
Definition: homescreen.c:271
+
static void tap_shortcut(struct afb_req request)
Definition: homescreen.c:77
+
static const char _application_name[]
Definition: homescreen.c:49
+
static struct afb_event ev_reserved
Definition: homescreen.c:45
+
static const char _error[]
Definition: homescreen.c:47
+
static void pingSample(struct afb_req request)
Definition: homescreen.c:57
+
static void onevent(const char *event, struct json_object *object)
Definition: homescreen.c:301
-
static int init()
Definition: homescreen.c:238
-
static const char * evlist[]
Definition: hs-helper.h:33
+
static void on_screen_reply(struct afb_req request)
Definition: homescreen.c:151
+
static int init()
Definition: homescreen.c:277
+
static const char * evlist[]
Definition: hs-helper.h:34
const char * name
Definition: homescreen.c:36
-
static void unsubscribe(struct afb_req request)
Definition: homescreen.c:191
+
static void unsubscribe(struct afb_req request)
Definition: homescreen.c:229
int hs_search_event_name_index(const char *value)
Definition: hs-helper.c:142
+
static struct afb_event ev_on_screen_reply
Definition: homescreen.c:44
static struct afb_event ev_on_screen_message
Definition: homescreen.c:43
#define COMMAND_EVENT_NUM
Definition: homescreen.c:31
-
static void on_screen_message(struct afb_req request)
Definition: homescreen.c:113
-
static const struct afb_verb_v2 verbs[]
Definition: homescreen.c:222
+
static void on_screen_message(struct afb_req request)
Definition: homescreen.c:114
+
static const struct afb_verb_v2 verbs[]
Definition: homescreen.c:260
static struct event event_list[COMMAND_EVENT_NUM]
Definition: homescreen.c:40
-
static const char _display_message[]
Definition: homescreen.c:49
-
static void subscribe(struct afb_req request)
Definition: homescreen.c:151
+
static const char _display_message[]
Definition: homescreen.c:50
+
static void subscribe(struct afb_req request)
Definition: homescreen.c:189
#define EVENT_SUBSCRIBE_ERROR_CODE
Definition: homescreen.c:32
static struct afb_event ev_tap_shortcut
Definition: homescreen.c:42
-
const struct afb_binding_v2 afbBindingV2
Definition: homescreen.c:263
+
static const char _reply_message[]
Definition: homescreen.c:51
+
const struct afb_binding_v2 afbBindingV2
Definition: homescreen.c:306
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125