From 599de8d3f35cb0fe56c7e27591862d61944b456b Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Mon, 23 Oct 2017 14:06:12 +0900 Subject: Add a new OnScreenReply api to agl-service-homescreen Add a new event named OnScreenReply. Applications can use this event to reply to the homescreen. Also update the documentation for this event. [Patch Sets 8,9] Update ApplicationGuide.md. For details: Use master source build agl-service-homescreen-2017. Change agl version to EE. Add libhomescreen sample code path. [Patch Sets 10] Delete tailing space. BUG-AGL: SPEC-985 Change-Id: Iea0c321731fa62cd94fc08fc5e303c20847fd525 Signed-off-by: zheng_wenlong --- doc/api-ref/html/d0/d1e/homescreen_8c.html | 195 ++++++--- doc/api-ref/html/d0/d1e/homescreen_8c_source.html | 40 +- doc/api-ref/html/d0/d8a/libhomescreen_8cpp.html | 204 +--------- .../html/d0/d8a/libhomescreen_8cpp_source.html | 59 ++- doc/api-ref/html/d3/d3d/hs-helper_8h.html | 47 +-- doc/api-ref/html/d3/d3d/hs-helper_8h_source.html | 19 +- .../html/d7/df4/class_lib_home_screen-members.html | 35 +- doc/api-ref/html/dd/d1d/hs-helper_8c.html | 30 +- doc/api-ref/html/dd/d1d/hs-helper_8c_source.html | 16 +- doc/api-ref/html/de/dd0/class_lib_home_screen.html | 211 +++++----- doc/api-ref/html/df/d43/libhomescreen_8hpp.html | 2 +- .../html/df/d43/libhomescreen_8hpp_source.html | 43 +- doc/api-ref/html/df/d76/hmi-debug_8h.html | 435 +++++++++++++++++++++ doc/api-ref/html/df/d76/hmi-debug_8h_source.html | 87 +++++ doc/api-ref/html/df/d7d/structevent.html | 2 +- doc/api-ref/html/df/dac/test_8cpp.html | 14 +- doc/api-ref/html/df/dac/test_8cpp_source.html | 14 +- .../html/dir_68267d1309a1af8e8297ef4c3efbcdba.html | 87 +++++ .../html/dir_d44c64559bbebec7f509842c48db8b23.html | 8 +- doc/api-ref/html/files.html | 22 +- doc/api-ref/html/functions.html | 11 +- doc/api-ref/html/functions_eval.html | 3 + doc/api-ref/html/functions_func.html | 6 +- doc/api-ref/html/functions_type.html | 2 +- doc/api-ref/html/globals.html | 84 +++- doc/api-ref/html/globals_defs.html | 21 +- doc/api-ref/html/globals_enum.html | 3 + doc/api-ref/html/globals_eval.html | 21 + doc/api-ref/html/globals_func.html | 10 +- doc/api-ref/html/globals_vars.html | 9 + doc/api-ref/html/menudata.js | 2 +- doc/api-ref/html/search/all_0.js | 6 +- doc/api-ref/html/search/all_10.js | 3 +- doc/api-ref/html/search/all_11.js | 2 +- doc/api-ref/html/search/all_3.js | 15 +- doc/api-ref/html/search/all_4.js | 15 +- doc/api-ref/html/search/all_5.js | 19 +- doc/api-ref/html/search/all_6.js | 11 +- doc/api-ref/html/search/all_7.js | 12 +- doc/api-ref/html/search/all_8.js | 4 +- doc/api-ref/html/search/all_9.js | 3 +- doc/api-ref/html/search/all_a.js | 15 +- doc/api-ref/html/search/all_b.js | 13 +- doc/api-ref/html/search/all_c.js | 6 +- doc/api-ref/html/search/all_d.js | 8 +- doc/api-ref/html/search/all_e.js | 6 +- doc/api-ref/html/search/all_f.js | 5 +- doc/api-ref/html/search/defines_3.js | 2 +- doc/api-ref/html/search/defines_4.js | 7 +- doc/api-ref/html/search/enums_1.js | 2 +- doc/api-ref/html/search/enums_2.html | 26 ++ doc/api-ref/html/search/enums_2.js | 4 + doc/api-ref/html/search/enumvalues_0.js | 1 + doc/api-ref/html/search/enumvalues_1.js | 8 +- doc/api-ref/html/search/enumvalues_2.js | 2 +- doc/api-ref/html/search/enumvalues_3.js | 3 +- doc/api-ref/html/search/enumvalues_4.html | 26 ++ doc/api-ref/html/search/enumvalues_4.js | 5 + doc/api-ref/html/search/files_0.js | 1 + doc/api-ref/html/search/functions_0.js | 3 +- doc/api-ref/html/search/functions_8.js | 2 + doc/api-ref/html/search/functions_a.js | 3 +- doc/api-ref/html/search/searchdata.js | 8 +- doc/api-ref/html/search/typedefs_0.js | 2 +- doc/api-ref/html/search/variables_0.js | 3 +- doc/api-ref/html/search/variables_2.js | 2 + 66 files changed, 1368 insertions(+), 627 deletions(-) create mode 100644 doc/api-ref/html/df/d76/hmi-debug_8h.html create mode 100644 doc/api-ref/html/df/d76/hmi-debug_8h_source.html create mode 100644 doc/api-ref/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html create mode 100644 doc/api-ref/html/search/enums_2.html create mode 100644 doc/api-ref/html/search/enums_2.js create mode 100644 doc/api-ref/html/search/enumvalues_4.html create mode 100644 doc/api-ref/html/search/enumvalues_4.js (limited to 'doc/api-ref/html') diff --git a/doc/api-ref/html/d0/d1e/homescreen_8c.html b/doc/api-ref/html/d0/d1e/homescreen_8c.html index 8907a06..2ea52e3 100644 --- a/doc/api-ref/html/d0/d1e/homescreen_8c.html +++ b/doc/api-ref/html/d0/d1e/homescreen_8c.html @@ -5,7 +5,7 @@ -HomeScreenBinding: homescreen_service/homescreen.c File Reference +HomeScreenBinding: src/homescreen.c File Reference @@ -58,7 +58,7 @@ $(function() {
@@ -95,7 +95,7 @@ Macros   #define AFB_BINDING_VERSION   2   -#define COMMAND_EVENT_NUM   3 +#define COMMAND_EVENT_NUM   4   #define EVENT_SUBSCRIBE_ERROR_CODE   100   @@ -108,6 +108,8 @@ Functions   static void on_screen_message (struct afb_req request)   +static void on_screen_reply (struct afb_req request) +  static void subscribe (struct afb_req request)   static void unsubscribe (struct afb_req request) @@ -127,6 +129,8 @@ Variables   static struct afb_event ev_on_screen_message   +static struct afb_event ev_on_screen_reply +  static struct afb_event ev_reserved   static const char _error [] = "error" @@ -135,6 +139,8 @@ Variables   static const char _display_message [] = "display_message"   +static const char _reply_message [] = "reply_message" +  static const struct afb_verb_v2 verbs []   const struct afb_binding_v2 afbBindingV2 @@ -180,7 +186,7 @@ Variables
- +
#define COMMAND_EVENT_NUM   3#define COMMAND_EVENT_NUM   4
@@ -229,11 +235,13 @@ Variables
-

Definition at line 238 of file homescreen.c.

-
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 }
struct afb_event * event
Definition: homescreen.c:37
-
static struct afb_event ev_reserved
Definition: homescreen.c:44
-
static const char * evlist[]
Definition: hs-helper.h:33
+

Definition at line 277 of file homescreen.c.

+
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 }
struct afb_event * event
Definition: homescreen.c:37
+
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
static struct afb_event ev_reserved
Definition: homescreen.c:45
+
static const char * evlist[]
Definition: hs-helper.h:34
const char * name
Definition: homescreen.c:36
+
static struct afb_event ev_on_screen_reply
Definition: homescreen.c:44
static struct afb_event ev_on_screen_message
Definition: homescreen.c:43
static struct event event_list[COMMAND_EVENT_NUM]
Definition: homescreen.c:40
static struct afb_event ev_tap_shortcut
Definition: homescreen.c:42
@@ -263,19 +271,61 @@ Variables
-

HomeScreenのOnScreenを表示する

+

HomeScreen OnScreen message

Parameters

Request key

    -
  • display_message : 表示したい文字列
  • +
  • display_message : message for display

Return

Nothing

-

Definition at line 113 of file homescreen.c.

-
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 }
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:110
-
static const char _error[]
Definition: homescreen.c:46
+

Definition at line 114 of file homescreen.c.

+
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 }
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:110
+
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
static const char _error[]
Definition: homescreen.c:47
static struct afb_event ev_on_screen_message
Definition: homescreen.c:43
-
static const char _display_message[]
Definition: homescreen.c:49
+
static const char _display_message[]
Definition: homescreen.c:50
+
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125
+
+
+
+ +

◆ on_screen_reply()

+ +
+
+ + + + + +
+ + + + + + + + +
static void on_screen_reply (struct afb_req request)
+
+static
+
+

HomeScreen OnScreen Reply

+

Parameters

+

Request key

    +
  • reply_message : message for reply
  • +
+

Return

+

Nothing

+ +

Definition at line 151 of file homescreen.c.

+
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 }
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:110
+
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
static const char _error[]
Definition: homescreen.c:47
+
static struct afb_event ev_on_screen_reply
Definition: homescreen.c:44
+
static const char _reply_message[]
Definition: homescreen.c:51
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125
@@ -314,8 +364,9 @@ Variables
-

Definition at line 258 of file homescreen.c.

-
259 {
260  AFB_NOTICE("on_event %s", event);
261 }
+

Definition at line 301 of file homescreen.c.

+
302 {
303  HMI_NOTICE("homescreen-service","on_event %s", event);
304 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
@@ -343,8 +394,9 @@ Variables
-

Definition at line 55 of file homescreen.c.

-
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 }
+

Definition at line 57 of file homescreen.c.

+
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 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
@@ -370,8 +422,9 @@ Variables
-

Definition at line 232 of file homescreen.c.

-
233 {
234  AFB_NOTICE("binding preinit (was register)");
235  return 0;
236 }
+

Definition at line 271 of file homescreen.c.

+
272 {
273  HMI_NOTICE("homescreen-service","binding preinit (was register)");
274  return 0;
275 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
@@ -406,8 +459,9 @@ Variables

Nothing

Note

-

Definition at line 151 of file homescreen.c.

-
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 }
static const char _error[]
Definition: homescreen.c:46
+

Definition at line 189 of file homescreen.c.

+
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 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
static const char _error[]
Definition: homescreen.c:47
int hs_search_event_name_index(const char *value)
Definition: hs-helper.c:142
static struct event event_list[COMMAND_EVENT_NUM]
Definition: homescreen.c:40
@@ -439,18 +493,19 @@ Variables
-

HomeScreenから呼ばれる ショートカットがタップされたことをアプリケーションに通知するために使用する アプリケーションからは使用されない

+

tap_shortcut notify for homescreen When Shortcut area is tapped, notify these applciations

Parameters

Request key

    -
  • application_name : アプリケーション名
  • +
  • application_name : application name

Return

Nothing

-

Definition at line 76 of file homescreen.c.

-
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 }
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:110
-
static const char _application_name[]
Definition: homescreen.c:48
-
static const char _error[]
Definition: homescreen.c:46
+

Definition at line 77 of file homescreen.c.

+
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 }
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:110
+
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
static const char _application_name[]
Definition: homescreen.c:49
+
static const char _error[]
Definition: homescreen.c:47
static struct afb_event ev_tap_shortcut
Definition: homescreen.c:42
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125
@@ -488,8 +543,9 @@ Variables

Nothing

Note

-

Definition at line 191 of file homescreen.c.

-
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 }
static const char _error[]
Definition: homescreen.c:46
+

Definition at line 229 of file homescreen.c.

+
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 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:20
+
static const char _error[]
Definition: homescreen.c:47
int hs_search_event_name_index(const char *value)
Definition: hs-helper.c:142
static struct event event_list[COMMAND_EVENT_NUM]
Definition: homescreen.c:40
@@ -519,7 +575,7 @@ Variables
-

Definition at line 48 of file homescreen.c.

+

Definition at line 49 of file homescreen.c.

@@ -543,7 +599,7 @@ Variables
-

Definition at line 49 of file homescreen.c.

+

Definition at line 50 of file homescreen.c.

@@ -567,7 +623,31 @@ Variables
-

Definition at line 46 of file homescreen.c.

+

Definition at line 47 of file homescreen.c.

+ +
+ + +

◆ _reply_message

+ +
+
+ + + + + +
+ + + + +
const char _reply_message[] = "reply_message"
+
+static
+
+ +

Definition at line 51 of file homescreen.c.

@@ -582,12 +662,12 @@ Variables
-Initial value:
= {
.api = "homescreen",
.specification = NULL,
.verbs = verbs,
.preinit = preinit,
.init = init,
.onevent = onevent
}
static int preinit()
Definition: homescreen.c:232
-
static void onevent(const char *event, struct json_object *object)
Definition: homescreen.c:258
-
static int init()
Definition: homescreen.c:238
-
static const struct afb_verb_v2 verbs[]
Definition: homescreen.c:222
+Initial value:
= {
.api = "homescreen",
.specification = NULL,
.verbs = verbs,
.preinit = preinit,
.init = init,
.onevent = onevent
}
static int preinit()
Definition: homescreen.c:271
+
static void onevent(const char *event, struct json_object *object)
Definition: homescreen.c:301
+
static int init()
Definition: homescreen.c:277
+
static const struct afb_verb_v2 verbs[]
Definition: homescreen.c:260
-

Definition at line 263 of file homescreen.c.

+

Definition at line 306 of file homescreen.c.

@@ -613,6 +693,30 @@ Variables

Definition at line 43 of file homescreen.c.

+ + + +

◆ ev_on_screen_reply

+ +
+
+ + + + + +
+ + + + +
struct afb_event ev_on_screen_reply
+
+static
+
+ +

Definition at line 44 of file homescreen.c.

+
@@ -635,7 +739,7 @@ Variables
-

Definition at line 44 of file homescreen.c.

+

Definition at line 45 of file homescreen.c.

@@ -706,13 +810,14 @@ Variables
-Initial value:
= {
{ .verb = "ping", .session = AFB_SESSION_NONE, .callback = pingSample, .auth = NULL },
{ .verb = "tap_shortcut", .session = AFB_SESSION_NONE, .callback = tap_shortcut, .auth = NULL },
{ .verb = "on_screen_message", .session = AFB_SESSION_NONE, .callback = on_screen_message, .auth = NULL },
{ .verb = "subscribe", .session = AFB_SESSION_NONE, .callback = subscribe, .auth = NULL },
{ .verb = "unsubscribe", .session = AFB_SESSION_NONE, .callback = unsubscribe, .auth = NULL },
{NULL }
}
static void tap_shortcut(struct afb_req request)
Definition: homescreen.c:76
-
static void pingSample(struct afb_req request)
Definition: homescreen.c:55
-
static void unsubscribe(struct afb_req request)
Definition: homescreen.c:191
-
static void on_screen_message(struct afb_req request)
Definition: homescreen.c:113
-
static void subscribe(struct afb_req request)
Definition: homescreen.c:151
+Initial value:
= {
{ .verb = "ping", .session = AFB_SESSION_NONE, .callback = pingSample, .auth = NULL },
{ .verb = "tap_shortcut", .session = AFB_SESSION_NONE, .callback = tap_shortcut, .auth = NULL },
{ .verb = "on_screen_message", .session = AFB_SESSION_NONE, .callback = on_screen_message, .auth = NULL },
{ .verb = "on_screen_reply", .session = AFB_SESSION_NONE, .callback = on_screen_reply, .auth = NULL },
{ .verb = "subscribe", .session = AFB_SESSION_NONE, .callback = subscribe, .auth = NULL },
{ .verb = "unsubscribe", .session = AFB_SESSION_NONE, .callback = unsubscribe, .auth = NULL },
{NULL }
}
static void tap_shortcut(struct afb_req request)
Definition: homescreen.c:77
+
static void pingSample(struct afb_req request)
Definition: homescreen.c:57
+
static void on_screen_reply(struct afb_req request)
Definition: homescreen.c:151
+
static void unsubscribe(struct afb_req request)
Definition: homescreen.c:229
+
static void on_screen_message(struct afb_req request)
Definition: homescreen.c:114
+
static void subscribe(struct afb_req request)
Definition: homescreen.c:189
-

Definition at line 222 of file homescreen.c.

+

Definition at line 260 of file homescreen.c.

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
diff --git a/doc/api-ref/html/d0/d8a/libhomescreen_8cpp.html b/doc/api-ref/html/d0/d8a/libhomescreen_8cpp.html index 0c33842..1aec416 100644 --- a/doc/api-ref/html/d0/d8a/libhomescreen_8cpp.html +++ b/doc/api-ref/html/d0/d8a/libhomescreen_8cpp.html @@ -5,7 +5,7 @@ -HomeScreenBinding: libhomescreen.cpp File Reference +HomeScreenBinding: libhomescreen/libhomescreen.cpp File Reference @@ -63,7 +63,6 @@ $(function() {
@@ -83,22 +82,12 @@ $(function() { #include <cstdlib>
#include <cstring>
#include <libhomescreen.hpp>
+#include "hmi-debug.h"

Go to the source code of this file.

- - - - - -

-Macros

#define ELOG(args, ...)   _ELOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__)
 
#define DLOG(args, ...)   _DLOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__)
 
- - - - @@ -117,168 +106,7 @@ Variables

Functions

static void _DLOG (const char *func, const int line, const char *log,...)
 
static void _ELOG (const char *func, const int line, const char *log,...)
 
static bool has_verb (const string &verb)
 
static void _on_hangup_static (void *closure, struct afb_wsj1 *wsj)
static const char API [] = "homescreen"
 
-

Macro Definition Documentation

- -

◆ DLOG

- -
-
- - - - - - - - - - - - - - - - - - -
#define DLOG( args,
 ... 
)   _DLOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__)
-
- -

Definition at line 33 of file libhomescreen.cpp.

- -
-
- -

◆ ELOG

- -
-
- - - - - - - - - - - - - - - - - - -
#define ELOG( args,
 ... 
)   _ELOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__)
-
- -

Definition at line 32 of file libhomescreen.cpp.

- -
-

Function Documentation

- -

◆ _DLOG()

- -
-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void _DLOG (const char * func,
const int line,
const char * log,
 ... 
)
-
-static
-
- -

Definition at line 545 of file libhomescreen.cpp.

-
546 {
547  char *message;
548  va_list args;
549  va_start(args, log);
550  if (log == NULL || vasprintf(&message, log, args) < 0)
551  message = NULL;
552  cout << "[libhomescreen DEBUG]" << func << "(" << line << "):" << message << endl;
553  va_end(args);
554  free(message);
555 }
-
-
- -

◆ _ELOG()

- -
-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void _ELOG (const char * func,
const int line,
const char * log,
 ... 
)
-
-static
-
- -

Definition at line 533 of file libhomescreen.cpp.

-
534 {
535  char *message;
536  va_list args;
537  va_start(args, log);
538  if (log == NULL || vasprintf(&message, log, args) < 0)
539  message = NULL;
540  cout << "[libhomescreen ERROR]" << func << "(" << line << "):" << message << endl;
541  va_end(args);
542  free(message);
543 }
-
-

◆ _on_call_static()

@@ -325,8 +153,8 @@ Variables
-

Definition at line 66 of file libhomescreen.cpp.

-
67 {
68  /* LibHomeScreen is not called from other process */
69 }
+

Definition at line 64 of file libhomescreen.cpp.

+
65 {
66  /* LibHomeScreen is not called from other process */
67 }
@@ -369,8 +197,8 @@ Variables
-

Definition at line 71 of file libhomescreen.cpp.

-
72 {
73  static_cast<LibHomeScreen*>(closure)->on_event(NULL,event,msg);
74 }
+

Definition at line 69 of file libhomescreen.cpp.

+
70 {
71  static_cast<LibHomeScreen*>(closure)->on_event(NULL,event,msg);
72 }
@@ -410,8 +238,8 @@ Variables

websocket

-

Definition at line 61 of file libhomescreen.cpp.

-
62 {
63  static_cast<LibHomeScreen*>(closure)->on_hangup(NULL,wsj);
64 }
+

Definition at line 59 of file libhomescreen.cpp.

+
60 {
61  static_cast<LibHomeScreen*>(closure)->on_hangup(NULL,wsj);
62 }
@@ -449,8 +277,8 @@ Variables
-

Definition at line 76 of file libhomescreen.cpp.

-
77 {
78  static_cast<LibHomeScreen*>(closure)->on_reply(NULL,msg);
79 }
+

Definition at line 74 of file libhomescreen.cpp.

+
75 {
76  static_cast<LibHomeScreen*>(closure)->on_reply(NULL,msg);
77 }
@@ -478,8 +306,8 @@ Variables
-

Definition at line 204 of file libhomescreen.cpp.

-
205 {
206  struct sd_event* loop = (struct sd_event*)(args);
207  DLOG("start eventloop");
208  for(;;)
209  sd_event_run(loop, 30000000);
210 }
#define DLOG(args,...)
+

Definition at line 201 of file libhomescreen.cpp.

+
202 {
203  struct sd_event* loop = (struct sd_event*)(args);
204  HMI_DEBUG("libhomescreen","start eventloop");
205  for(;;)
206  sd_event_run(loop, 30000000);
207 }
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:22
@@ -507,9 +335,9 @@ Variables
-

Definition at line 557 of file libhomescreen.cpp.

-
558 {
559  DLOG("verb is %s", verb.c_str());
560  if(find(LibHomeScreen::api_list.begin(), LibHomeScreen::api_list.end(), verb) != LibHomeScreen::api_list.end())
561  return true;
562  else
563  return false;
564 }
#define DLOG(args,...)
-
static const std::vector< std::string > api_list
+

Definition at line 518 of file libhomescreen.cpp.

+
519 {
520  HMI_DEBUG("libhomescreen","verb is %s", verb.c_str());
521  if(find(LibHomeScreen::api_list.begin(), LibHomeScreen::api_list.end(), verb) != LibHomeScreen::api_list.end())
522  return true;
523  else
524  return false;
525 }
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:22
+
static const std::vector< std::string > api_list
@@ -534,7 +362,7 @@ Variables
-

Definition at line 40 of file libhomescreen.cpp.

+

Definition at line 36 of file libhomescreen.cpp.

diff --git a/doc/api-ref/html/d0/d8a/libhomescreen_8cpp_source.html b/doc/api-ref/html/d0/d8a/libhomescreen_8cpp_source.html index 9e93d6f..621f8d4 100644 --- a/doc/api-ref/html/d0/d8a/libhomescreen_8cpp_source.html +++ b/doc/api-ref/html/d0/d8a/libhomescreen_8cpp_source.html @@ -66,41 +66,40 @@ $(function() {
libhomescreen.cpp
-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 #include <stdarg.h>
18 #include <sys/socket.h>
19 #include <iostream>
20 #include <algorithm>
21 #include <thread>
22 #include <errno.h>
23 #include <cassert>
24 #include <cctype>
25 #include <cerrno>
26 #include <cstdio>
27 #include <cstdlib>
28 #include <cstring>
29 
30 #include <libhomescreen.hpp>
31 
32 #define ELOG(args,...) _ELOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__)
33 #define DLOG(args,...) _DLOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__)
34 
35 using namespace std;
36 
37 static void _DLOG(const char* func, const int line, const char* log, ...);
38 static void _ELOG(const char* func, const int line, const char* log, ...);
39 static bool has_verb(const string& verb);
40 static const char API[] = "homescreen";
41 
42 const std::vector<std::string> LibHomeScreen::api_list {
43  std::string("ping"), // debug do not use
44  std::string("tap_shortcut"), // HomeScreen Application only
45  std::string("on_screen_message"),
46  std::string("subscribe"),
47  std::string("unsubscribe")
48 };
49 
50 const std::vector<std::string> LibHomeScreen::event_list {
51  std::string("tap_shortcut"),
52  std::string("on_screen_message"),
53  std::string("none")
54 };
55 
56 
61 static void _on_hangup_static(void *closure, struct afb_wsj1 *wsj)
62 {
63  static_cast<LibHomeScreen*>(closure)->on_hangup(NULL,wsj);
64 }
65 
66 static void _on_call_static(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
67 {
68  /* LibHomeScreen is not called from other process */
69 }
70 
71 static void _on_event_static(void* closure, const char* event, struct afb_wsj1_msg *msg)
72 {
73  static_cast<LibHomeScreen*>(closure)->on_event(NULL,event,msg);
74 }
75 
76 static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
77 {
78  static_cast<LibHomeScreen*>(closure)->on_reply(NULL,msg);
79 }
80 
81 
86 {
87 
88 }
89 
94 {
95  if(mploop)
96  {
97  sd_event_unref(mploop);
98  }
99  if(sp_websock != NULL)
100  {
101  free(sp_websock);
102  }
103 }
104 
119 int LibHomeScreen::init(const int port, const string& token)
120 {
121  int ret = 0;
122  if(port > 0 && token.size() > 0)
123  {
124  mport = port;
125  mtoken = token;
126  }
127  else
128  {
129  ELOG("port and token should be > 0, Initial port and token uses.");
130  }
131 
132  ret = initialize_websocket();
133  if(ret != 0 )
134  {
135  ELOG("Failed to initialize websocket");
136  }
137  else{
138  DLOG("Initialized");
139  }
140 
141  return ret;
142 }
143 
159  void (*event_cb)(const std::string& event, struct json_object* event_contents),
160  void (*reply_cb)(struct json_object* reply_contents),
161  void (*hangup_cb)(void))
162 {
163  onEvent = event_cb;
164  onReply = reply_cb;
165  onHangup = hangup_cb;
166 }
167 
168 int LibHomeScreen::initialize_websocket()
169 {
170  mploop = NULL;
171  onEvent = nullptr;
172  onReply = nullptr;
173  int ret = sd_event_default(&mploop);
174  if(ret < 0)
175  {
176  ELOG("Failed to create event loop");
177  goto END;
178  }
179 
180  /* Initialize interface from websocket */
181  minterface.on_hangup = _on_hangup_static;
182  minterface.on_call = _on_call_static; /* Is this necessary? */
183  minterface.on_event = _on_event_static;
184  muri += "ws://localhost:" + to_string(mport) + "/api?token=" + mtoken; /*To be modified*/
185  sp_websock = afb_ws_client_connect_wsj1(mploop, muri.c_str(), &minterface, this);
186  if(sp_websock == NULL)
187  {
188  ELOG("Failed to create websocket connection");
189  goto END;
190  }
191 
192  /* creates the evsrc */
193  //ret = sd_event_add_io(mploop,&mevent_src, sp_websock->fd, EPOLLIN, event_callback, NULL);
194 
195  return 0;
196 END:
197  if(mploop)
198  {
199  sd_event_unref(mploop);
200  }
201  return -1;
202 }
203 
204 static void *event_loop_run(void *args)
205 {
206  struct sd_event* loop = (struct sd_event*)(args);
207  DLOG("start eventloop");
208  for(;;)
209  sd_event_run(loop, 30000000);
210 }
211 
225 {
226  if(mploop && sp_websock)
227  {
228  pthread_t thread_id;
229  int ret = pthread_create(&thread_id, NULL, event_loop_run, mploop);
230  if(ret != 0)
231  {
232  ELOG("Cannot run eventloop due to error:%d", errno);
233  return -1;
234  }
235  else
236  return thread_id;
237  }
238  else
239  {
240  ELOG("Connecting is not established yet");
241  return -1;
242  }
243 }
244 
256 int LibHomeScreen::tapShortcut(const char* application_name)
257 {
258  if(!sp_websock)
259  {
260  return -1;
261  }
262 
263  struct json_object* j_obj = json_object_new_object();
264  struct json_object* val = json_object_new_string(application_name);
265  json_object_object_add(j_obj, "application_name", val);
266  return this->call("tap_shortcut", j_obj);
267 }
268 
280 int LibHomeScreen::onScreenMessage(const char* display_message)
281 {
282  if(!sp_websock)
283  {
284  return -1;
285  }
286 
287  struct json_object* j_obj = json_object_new_object();
288  struct json_object* val = json_object_new_string(display_message);
289  json_object_object_add(j_obj, "display_message", val);
290  return this->call("on_screen_message", j_obj);
291 }
292 
306 {
307  if (et >= 1 && et <= 2) {
308  switch (et) {
309  case Event_TapShortcut:
311  break;
312  case Event_OnScreenMessage:
314  break;
315  }
316 
317  this->handlers[et] = std::move(f);
318  }
319 }
320 
335 int LibHomeScreen::call(const string& verb, struct json_object* arg)
336 {
337  int ret;
338  if(!sp_websock)
339  {
340  return -1;
341  }
342  if (!has_verb(verb))
343  {
344  ELOG("verb doesn't exit");
345  return -1;
346  }
347  ret = afb_wsj1_call_j(sp_websock, API, verb.c_str(), arg, _on_reply_static, this);
348  if (ret < 0) {
349  ELOG("Failed to call verb:%s",verb.c_str());
350  }
351  return ret;
352 }
353 
369 int LibHomeScreen::call(const char* verb, struct json_object* arg)
370 {
371  int ret;
372  if(!sp_websock)
373  {
374  return -1;
375  }
376  if (!has_verb(string(verb)))
377  {
378  ELOG("verb doesn't exit");
379  return -1;
380  }
381  ret = afb_wsj1_call_j(sp_websock, API, verb, arg, _on_reply_static, this);
382  if (ret < 0) {
383  ELOG("Failed to call verb:%s",verb);
384  }
385  return ret;
386 }
387 
401 int LibHomeScreen::subscribe(const string& event_name)
402 {
403  if(!sp_websock)
404  {
405  return -1;
406  }
407  struct json_object* j_obj = json_object_new_object();
408  json_object_object_add(j_obj, "event", json_object_new_string(event_name.c_str()));
409 
410  int ret = afb_wsj1_call_j(sp_websock, API, "subscribe", j_obj, _on_reply_static, this);
411  if (ret < 0) {
412  ELOG("Failed to call verb:%s",__FUNCTION__);
413  }
414  return ret;
415 }
416 
430 int LibHomeScreen::unsubscribe(const string& event_name)
431 {
432  if(!sp_websock)
433  {
434  return -1;
435  }
436  struct json_object* j_obj = json_object_new_object();
437  json_object_object_add(j_obj, "event", json_object_new_string(event_name.c_str()));
438 
439  int ret = afb_wsj1_call_j(sp_websock, API, "unsubscribe", j_obj, _on_reply_static, this);
440  if (ret < 0) {
441  ELOG("Failed to call verb:%s",__FUNCTION__);
442  }
443  return ret;
444 }
445 
446 /************* Callback Function *************/
447 
448 void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj)
449 {
450  DLOG("%s called", __FUNCTION__);
451  if(onHangup != nullptr)
452  {
453  onHangup();
454  }
455 }
456 
457 void LibHomeScreen::on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
458 {
459 }
460 
461 /*
462 * event is like "homescreen/tap_shortcut"
463 * msg is like {"event":"homescreen\/tap_shortcut","data":{"application_name":"hoge"},"jtype":"afb-event"}
464 * so you can get
465  event name : struct json_object obj = json_object_object_get(msg,"event")
466 */
467 void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)
468 {
469  cout << "[libhomescreen on_event]: " << event << " (" << afb_wsj1_msg_object_s(msg) << ")" << endl;
470 
471  if (strstr(event, API) == NULL) {
472  return;
473  }
474 
475  struct json_object* ev_contents = afb_wsj1_msg_object_j(msg);
476  struct json_object *json_data = json_object_object_get(ev_contents, "data");
477 
478  if(onEvent != nullptr)
479  {
480  const string ev(event);
481  onEvent(ev, ev_contents);
482  }
483 
484  const char* event_only = strchr(event, '/');
485  if (event_only != nullptr) {
486  event_only = event_only + 1;
487  }
488 
489  if (strcasecmp(event_only, LibHomeScreen::event_list[0].c_str()) == 0) {
490  auto i = this->handlers.find(Event_TapShortcut);
491 
492  struct json_object *json_application_name = json_object_object_get(json_data, "application_name");
493  const char* application_name = json_object_get_string(json_application_name);
494 
495  if ( i != this->handlers.end() ) {
496  i->second(application_name);
497  }
498  }
499  else if (strcasecmp(event_only, LibHomeScreen::event_list[1].c_str()) == 0) {
500 
501  auto i = this->handlers.find(Event_OnScreenMessage);
502 
503  struct json_object *json_display_message = json_object_object_get(json_data, "display_message");
504  const char* display_message = json_object_get_string(json_display_message);
505 
506  if ( i != this->handlers.end() ) {
507  i->second(display_message);
508  }
509 
510  }
511 
512  json_object_put(ev_contents);
513 }
514 
519 void LibHomeScreen::on_reply(void *closure, struct afb_wsj1_msg *msg)
520 {
521  cout << "[libhomescreen on_reply]: " << " (" << afb_wsj1_msg_object_s(msg) << ")" << endl;
522  if(onReply != nullptr)
523  {
524  struct json_object* reply = afb_wsj1_msg_object_j(msg);
525  onReply(reply);
526 
527  json_object_put(reply);
528  }
529 }
530 
531 /* Internal Function in libhomescreen */
532 
533 static void _ELOG(const char* func, const int line, const char* log, ...)
534 {
535  char *message;
536  va_list args;
537  va_start(args, log);
538  if (log == NULL || vasprintf(&message, log, args) < 0)
539  message = NULL;
540  cout << "[libhomescreen ERROR]" << func << "(" << line << "):" << message << endl;
541  va_end(args);
542  free(message);
543 }
544 
545 static void _DLOG(const char* func, const int line, const char* log, ...)
546 {
547  char *message;
548  va_list args;
549  va_start(args, log);
550  if (log == NULL || vasprintf(&message, log, args) < 0)
551  message = NULL;
552  cout << "[libhomescreen DEBUG]" << func << "(" << line << "):" << message << endl;
553  va_end(args);
554  free(message);
555 }
556 
557 static bool has_verb(const string& verb)
558 {
559  DLOG("verb is %s", verb.c_str());
560  if(find(LibHomeScreen::api_list.begin(), LibHomeScreen::api_list.end(), verb) != LibHomeScreen::api_list.end())
561  return true;
562  else
563  return false;
564 }
void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)
-
static void _on_hangup_static(void *closure, struct afb_wsj1 *wsj)
-
void on_reply(void *closure, struct afb_wsj1_msg *msg)
-
void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
-
#define DLOG(args,...)
+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 #include <stdarg.h>
18 #include <sys/socket.h>
19 #include <iostream>
20 #include <algorithm>
21 #include <thread>
22 #include <errno.h>
23 #include <cassert>
24 #include <cctype>
25 #include <cerrno>
26 #include <cstdio>
27 #include <cstdlib>
28 #include <cstring>
29 
30 #include <libhomescreen.hpp>
31 #include "hmi-debug.h"
32 
33 using namespace std;
34 
35 static bool has_verb(const string& verb);
36 static const char API[] = "homescreen";
37 
38 const std::vector<std::string> LibHomeScreen::api_list {
39  std::string("ping"), // debug do not use
40  std::string("tap_shortcut"), // HomeScreen Application only
41  std::string("on_screen_message"),
42  std::string("on_screen_reply"),
43  std::string("subscribe"),
44  std::string("unsubscribe")
45 };
46 
47 const std::vector<std::string> LibHomeScreen::event_list {
48  std::string("tap_shortcut"),
49  std::string("on_screen_message"),
50  std::string("on_screen_reply"),
51  std::string("none")
52 };
53 
54 
59 static void _on_hangup_static(void *closure, struct afb_wsj1 *wsj)
60 {
61  static_cast<LibHomeScreen*>(closure)->on_hangup(NULL,wsj);
62 }
63 
64 static void _on_call_static(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
65 {
66  /* LibHomeScreen is not called from other process */
67 }
68 
69 static void _on_event_static(void* closure, const char* event, struct afb_wsj1_msg *msg)
70 {
71  static_cast<LibHomeScreen*>(closure)->on_event(NULL,event,msg);
72 }
73 
74 static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
75 {
76  static_cast<LibHomeScreen*>(closure)->on_reply(NULL,msg);
77 }
78 
79 
84 {
85 }
86 
91 {
92  if(mploop)
93  {
94  sd_event_unref(mploop);
95  }
96  if(sp_websock != NULL)
97  {
98  afb_wsj1_unref(sp_websock);
99  }
100 }
101 
116 int LibHomeScreen::init(const int port, const string& token)
117 {
118  int ret = 0;
119  if(port > 0 && token.size() > 0)
120  {
121  mport = port;
122  mtoken = token;
123  }
124  else
125  {
126  HMI_ERROR("libhomescreen","port and token should be > 0, Initial port and token uses.");
127  }
128 
129  ret = initialize_websocket();
130  if(ret != 0 )
131  {
132  HMI_ERROR("libhomescreen","Failed to initialize websocket");
133  }
134  else{
135  HMI_DEBUG("libhomescreen","Initialized");
136  }
137 
138  return ret;
139 }
140 
156  void (*event_cb)(const std::string& event, struct json_object* event_contents),
157  void (*reply_cb)(struct json_object* reply_contents),
158  void (*hangup_cb)(void))
159 {
160  onEvent = event_cb;
161  onReply = reply_cb;
162  onHangup = hangup_cb;
163 }
164 
165 int LibHomeScreen::initialize_websocket()
166 {
167  mploop = NULL;
168  onEvent = nullptr;
169  onReply = nullptr;
170  int ret = sd_event_default(&mploop);
171  if(ret < 0)
172  {
173  HMI_ERROR("libhomescreen","Failed to create event loop");
174  goto END;
175  }
176 
177  /* Initialize interface from websocket */
178  minterface.on_hangup = _on_hangup_static;
179  minterface.on_call = _on_call_static; /* Is this necessary? */
180  minterface.on_event = _on_event_static;
181  muri += "ws://localhost:" + to_string(mport) + "/api?token=" + mtoken; /*To be modified*/
182  sp_websock = afb_ws_client_connect_wsj1(mploop, muri.c_str(), &minterface, this);
183  if(sp_websock == NULL)
184  {
185  HMI_ERROR("libhomescreen","Failed to create websocket connection");
186  goto END;
187  }
188 
189  /* creates the evsrc */
190  //ret = sd_event_add_io(mploop,&mevent_src, sp_websock->fd, EPOLLIN, event_callback, NULL);
191 
192  return 0;
193 END:
194  if(mploop)
195  {
196  sd_event_unref(mploop);
197  }
198  return -1;
199 }
200 
201 static void *event_loop_run(void *args)
202 {
203  struct sd_event* loop = (struct sd_event*)(args);
204  HMI_DEBUG("libhomescreen","start eventloop");
205  for(;;)
206  sd_event_run(loop, 30000000);
207 }
208 
220 int LibHomeScreen::tapShortcut(const char* application_name)
221 {
222  if(!sp_websock)
223  {
224  return -1;
225  }
226 
227  struct json_object* j_obj = json_object_new_object();
228  struct json_object* val = json_object_new_string(application_name);
229  json_object_object_add(j_obj, "application_name", val);
230  return this->call("tap_shortcut", j_obj);
231 }
232 
244 int LibHomeScreen::onScreenMessage(const char* display_message)
245 {
246  if(!sp_websock)
247  {
248  return -1;
249  }
250 
251  struct json_object* j_obj = json_object_new_object();
252  struct json_object* val = json_object_new_string(display_message);
253  json_object_object_add(j_obj, "display_message", val);
254  return this->call("on_screen_message", j_obj);
255 }
256 
268 int LibHomeScreen::onScreenReply(const char* reply_message)
269 {
270  if(!sp_websock)
271  {
272  return -1;
273  }
274 
275  struct json_object* j_obj = json_object_new_object();
276  struct json_object* val = json_object_new_string(reply_message);
277  json_object_object_add(j_obj, "reply_message", val);
278  return this->call("on_screen_reply", j_obj);
279 }
280 
294 {
295  if (et >= 1 && et <= 3) {
296  switch (et) {
297  case Event_TapShortcut:
299  break;
300  case Event_OnScreenMessage:
302  break;
303  case Event_OnScreenReply:
305  break;
306  }
307 
308  this->handlers[et] = std::move(f);
309  }
310 }
311 
326 int LibHomeScreen::call(const string& verb, struct json_object* arg)
327 {
328  int ret;
329  if(!sp_websock)
330  {
331  return -1;
332  }
333  if (!has_verb(verb))
334  {
335  HMI_ERROR("libhomescreen","verb doesn't exit");
336  return -1;
337  }
338  ret = afb_wsj1_call_j(sp_websock, API, verb.c_str(), arg, _on_reply_static, this);
339  if (ret < 0) {
340  HMI_ERROR("libhomescreen","Failed to call verb:%s",verb.c_str());
341  }
342  return ret;
343 }
344 
360 int LibHomeScreen::call(const char* verb, struct json_object* arg)
361 {
362  int ret;
363  if(!sp_websock)
364  {
365  return -1;
366  }
367  if (!has_verb(string(verb)))
368  {
369  HMI_ERROR("libhomescreen","verb doesn't exit");
370  return -1;
371  }
372  ret = afb_wsj1_call_j(sp_websock, API, verb, arg, _on_reply_static, this);
373  if (ret < 0) {
374  HMI_ERROR("libhomescreen","Failed to call verb:%s",verb);
375  }
376  return ret;
377 }
378 
392 int LibHomeScreen::subscribe(const string& event_name)
393 {
394  if(!sp_websock)
395  {
396  return -1;
397  }
398  struct json_object* j_obj = json_object_new_object();
399  json_object_object_add(j_obj, "event", json_object_new_string(event_name.c_str()));
400 
401  int ret = afb_wsj1_call_j(sp_websock, API, "subscribe", j_obj, _on_reply_static, this);
402  if (ret < 0) {
403  HMI_ERROR("libhomescreen","Failed to call verb:%s",__FUNCTION__);
404  }
405  return ret;
406 }
407 
421 int LibHomeScreen::unsubscribe(const string& event_name)
422 {
423  if(!sp_websock)
424  {
425  return -1;
426  }
427  struct json_object* j_obj = json_object_new_object();
428  json_object_object_add(j_obj, "event", json_object_new_string(event_name.c_str()));
429 
430  int ret = afb_wsj1_call_j(sp_websock, API, "unsubscribe", j_obj, _on_reply_static, this);
431  if (ret < 0) {
432  HMI_ERROR("libhomescreen","Failed to call verb:%s",__FUNCTION__);
433  }
434  return ret;
435 }
436 
437 /************* Callback Function *************/
438 
439 void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj)
440 {
441  HMI_DEBUG("libhomescreen","%s called", __FUNCTION__);
442  if(onHangup != nullptr)
443  {
444  onHangup();
445  }
446 }
447 
448 void LibHomeScreen::on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
449 {
450 }
451 
452 /*
453 * event is like "homescreen/tap_shortcut"
454 * msg is like {"event":"homescreen\/tap_shortcut","data":{"application_name":"hoge"},"jtype":"afb-event"}
455 * so you can get
456  event name : struct json_object obj = json_object_object_get(msg,"event")
457 */
458 void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)
459 {
460  HMI_DEBUG("libhomescreen","event: (%s) msg: (%s).", event, afb_wsj1_msg_object_s(msg));
461 
462  if (strstr(event, API) == NULL) {
463  return;
464  }
465 
466  struct json_object* ev_contents = afb_wsj1_msg_object_j(msg);
467  struct json_object *json_data = json_object_object_get(ev_contents, "data");
468 
469  if(onEvent != nullptr)
470  {
471  const string ev(event);
472  onEvent(ev, ev_contents);
473  }
474 
475  const char* event_only = strchr(event, '/');
476  if (event_only != nullptr) {
477  event_only = event_only + 1;
478  }
479 
480  if (strcasecmp(event_only, LibHomeScreen::event_list[0].c_str()) == 0) {
481  auto i = this->handlers.find(Event_TapShortcut);
482  if ( i != this->handlers.end() ) {
483  i->second(json_data);
484  }
485  }
486  else if (strcasecmp(event_only, LibHomeScreen::event_list[1].c_str()) == 0) {
487  auto i = this->handlers.find(Event_OnScreenMessage);
488  if ( i != this->handlers.end() ) {
489  i->second(json_data);
490  }
491  }
492  else if (strcasecmp(event_only, LibHomeScreen::event_list[2].c_str()) == 0) {
493  auto i = this->handlers.find(Event_OnScreenReply);
494  if ( i != this->handlers.end() ) {
495  i->second(json_data);
496  }
497  }
498 
499  json_object_put(ev_contents);
500 }
501 
506 void LibHomeScreen::on_reply(void *closure, struct afb_wsj1_msg *msg)
507 {
508  HMI_DEBUG("libhomescreen","msg: (%s)", afb_wsj1_msg_object_s(msg));
509  if(onReply != nullptr)
510  {
511  struct json_object* reply = afb_wsj1_msg_object_j(msg);
512  onReply(reply);
513 
514  json_object_put(reply);
515  }
516 }
517 
518 static bool has_verb(const string& verb)
519 {
520  HMI_DEBUG("libhomescreen","verb is %s", verb.c_str());
521  if(find(LibHomeScreen::api_list.begin(), LibHomeScreen::api_list.end(), verb) != LibHomeScreen::api_list.end())
522  return true;
523  else
524  return false;
525 }
void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)
+
#define HMI_ERROR(prefix, args,...)
Definition: hmi-debug.h:18
+
static void _on_hangup_static(void *closure, struct afb_wsj1 *wsj)
+
void on_reply(void *closure, struct afb_wsj1_msg *msg)
+
int onScreenReply(const char *reply_message)
+
std::function< void(json_object *)> handler_func
+
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:22
+
void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
-
static void _on_call_static(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
-
static const char API[]
+
static void _on_call_static(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
+
static const char API[]
-
#define ELOG(args,...)
int call(const std::string &verb, struct json_object *arg)
-
static void * event_loop_run(void *args)
-
void on_hangup(void *closure, struct afb_wsj1 *wsj)
-
int tapShortcut(const char *application_name)
-
static void _ELOG(const char *func, const int line, const char *log,...)
-
int subscribe(const std::string &event_name)
- - - -
static const std::vector< std::string > event_list
-
static void subscribe(struct afb_req request)
Definition: homescreen.c:151
-
std::function< void(const char *)> handler_func
-
int init(const int port, const std::string &token)
-
static bool has_verb(const string &verb)
-
static void _on_event_static(void *closure, const char *event, struct afb_wsj1_msg *msg)
-
int onScreenMessage(const char *display_message)
+
static void * event_loop_run(void *args)
+
void on_hangup(void *closure, struct afb_wsj1 *wsj)
+
int tapShortcut(const char *application_name)
+
int subscribe(const std::string &event_name)
+ + +
static const std::vector< std::string > event_list
+
static void subscribe(struct afb_req request)
Definition: homescreen.c:189
+ +
int init(const int port, const std::string &token)
+
static bool has_verb(const string &verb)
+
static void _on_event_static(void *closure, const char *event, struct afb_wsj1_msg *msg)
+
int onScreenMessage(const char *display_message)
- -
static const std::vector< std::string > api_list
-
int unsubscribe(const std::string &event_name)
-
static void _DLOG(const char *func, const int line, const char *log,...)
-
void set_event_handler(enum EventType et, handler_func f)
-
void registerCallback(void(*event_cb)(const std::string &event, struct json_object *event_contents), void(*reply_cb)(struct json_object *reply_contents), void(*hangup_cb)(void)=nullptr)
-
static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
+ +
static const std::vector< std::string > api_list
+
int unsubscribe(const std::string &event_name)
+
void set_event_handler(enum EventType et, handler_func f)
+
void registerCallback(void(*event_cb)(const std::string &event, struct json_object *event_contents), void(*reply_cb)(struct json_object *reply_contents), void(*hangup_cb)(void)=nullptr)
+
static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
@@ -76,6 +76,7 @@ $(function() { #include <stdint.h>
#include <glib.h>
#include <errno.h>
+#include "hmi-debug.h"

Go to the source code of this file.

@@ -171,12 +172,12 @@ Variables
OUT_RANGE 
-

Definition at line 25 of file hs-helper.h.

-
26 {
27  REQ_FAIL = -1,
28  REQ_OK=0,
29  NOT_NUMBER,
30  OUT_RANGE
31 }REQ_ERROR;
- - - -
REQ_ERROR
Definition: hs-helper.h:25
+

Definition at line 26 of file hs-helper.h.

+
27 {
28  REQ_FAIL = -1,
29  REQ_OK=0,
30  NOT_NUMBER,
31  OUT_RANGE
32 }REQ_ERROR;
+ + + +
REQ_ERROR
Definition: hs-helper.h:26
@@ -214,10 +215,10 @@ Variables

Definition at line 48 of file hs-helper.c.

-
49 {
50  char* endptr;
51  const char* tmp = afb_req_value (request, source);
52  if(!tmp)
53  {
54  return REQ_FAIL;
55  }
56  long tmp_id = strtol(tmp,&endptr,10);
57 
58  /* error check of range */
59  if( (tmp_id > INT16_MAX) || (tmp_id < INT16_MIN) )
60  {
61  return OUT_RANGE;
62  }
63  if(*endptr != '\0')
64  {
65  return NOT_NUMBER;
66  }
67 
68  *out_id = (int16_t)tmp_id;
69  return REQ_OK;
70 }
- - - +
49 {
50  char* endptr;
51  const char* tmp = afb_req_value (request, source);
52  if(!tmp)
53  {
54  return REQ_FAIL;
55  }
56  long tmp_id = strtol(tmp,&endptr,10);
57 
58  /* error check of range */
59  if( (tmp_id > INT16_MAX) || (tmp_id < INT16_MIN) )
60  {
61  return OUT_RANGE;
62  }
63  if(*endptr != '\0')
64  {
65  return NOT_NUMBER;
66  }
67 
68  *out_id = (int16_t)tmp_id;
69  return REQ_OK;
70 }
+ + +
@@ -254,10 +255,10 @@ Variables

Definition at line 72 of file hs-helper.c.

-
73 {
74  char* endptr;
75  const char* tmp = afb_req_value (request, source);
76  if(!tmp)
77  {
78  return REQ_FAIL;
79  }
80  long tmp_id = strtol(tmp,&endptr,10);
81 
82  /* error check of range */
83  if( (tmp_id > INT32_MAX) || (tmp_id < INT32_MIN) )
84  {
85  return OUT_RANGE;
86  }
87  if(*endptr != '\0')
88  {
89  return NOT_NUMBER;
90  }
91 
92  *out_id = (int32_t)tmp_id;
93  return REQ_OK;
94 }
- - - +
73 {
74  char* endptr;
75  const char* tmp = afb_req_value (request, source);
76  if(!tmp)
77  {
78  return REQ_FAIL;
79  }
80  long tmp_id = strtol(tmp,&endptr,10);
81 
82  /* error check of range */
83  if( (tmp_id > INT32_MAX) || (tmp_id < INT32_MIN) )
84  {
85  return OUT_RANGE;
86  }
87  if(*endptr != '\0')
88  {
89  return NOT_NUMBER;
90  }
91 
92  *out_id = (int32_t)tmp_id;
93  return REQ_OK;
94 }
+ + +
@@ -294,10 +295,10 @@ Variables

Definition at line 24 of file hs-helper.c.

-
25 {
26  char* endptr;
27  const char* tmp = afb_req_value (request, source);
28  if(!tmp)
29  {
30  return REQ_FAIL;
31  }
32  long tmp_id = strtol(tmp,&endptr,10);
33 
34  /* error check of range */
35  if( (tmp_id > UINT16_MAX) || (tmp_id < 0) )
36  {
37  return OUT_RANGE;
38  }
39  if(*endptr != '\0')
40  {
41  return NOT_NUMBER;
42  }
43 
44  *out_id = (uint16_t)tmp_id;
45  return REQ_OK;
46 }
- - - +
25 {
26  char* endptr;
27  const char* tmp = afb_req_value (request, source);
28  if(!tmp)
29  {
30  return REQ_FAIL;
31  }
32  long tmp_id = strtol(tmp,&endptr,10);
33 
34  /* error check of range */
35  if( (tmp_id > UINT16_MAX) || (tmp_id < 0) )
36  {
37  return OUT_RANGE;
38  }
39  if(*endptr != '\0')
40  {
41  return NOT_NUMBER;
42  }
43 
44  *out_id = (uint16_t)tmp_id;
45  return REQ_OK;
46 }
+ + +
@@ -432,7 +433,7 @@ Variables

Definition at line 142 of file hs-helper.c.

-
143 {
144  size_t buf_size = 50;
145  size_t size = sizeof evlist / sizeof *evlist;
146  int ret = -1;
147  for(size_t i = 0 ; i < size ; ++i)
148  {
149  if(!strncmp(value, evlist[i], buf_size))
150  {
151  ret = i;
152  break;
153  }
154  }
155  return ret;
156 }
static const char * evlist[]
Definition: hs-helper.h:33
+
143 {
144  size_t buf_size = 50;
145  size_t size = sizeof evlist / sizeof *evlist;
146  int ret = -1;
147  for(size_t i = 0 ; i < size ; ++i)
148  {
149  if(!strncmp(value, evlist[i], buf_size))
150  {
151  ret = i;
152  break;
153  }
154  }
155  return ret;
156 }
static const char * evlist[]
Definition: hs-helper.h:34
@@ -456,8 +457,8 @@ Variables
-Initial value:
= {
"tap_shortcut",
"on_screen_message",
"reserved"
}
-

Definition at line 33 of file hs-helper.h.

+Initial value:
= {
"tap_shortcut",
"on_screen_message",
"on_screen_reply",
"reserved"
}
+

Definition at line 34 of file hs-helper.h.

diff --git a/doc/api-ref/html/d3/d3d/hs-helper_8h_source.html b/doc/api-ref/html/d3/d3d/hs-helper_8h_source.html index 84f32cf..f0a581a 100644 --- a/doc/api-ref/html/d3/d3d/hs-helper_8h_source.html +++ b/doc/api-ref/html/d3/d3d/hs-helper_8h_source.html @@ -5,7 +5,7 @@ -HomeScreenBinding: homescreen_service/hs-helper.h Source File +HomeScreenBinding: src/hs-helper.h Source File @@ -58,7 +58,7 @@ $(function() {
@@ -66,18 +66,19 @@ $(function() {
hs-helper.h
-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 #ifndef HOMESCREEN_HELPER_H
18 #define HOMESCREEN_HELPER_H
19 #define AFB_BINDING_VERSION 2
20 #include <afb/afb-binding.h>
21 #include <stdint.h>
22 #include <glib.h>
23 #include <errno.h>
24 
25 typedef enum REQ_ERROR
26 {
27  REQ_FAIL = -1,
28  REQ_OK=0,
31 }REQ_ERROR;
32 
33 static const char* evlist[] = {
34  "tap_shortcut",
35  "on_screen_message",
36  "reserved"
37  };
38 
39 REQ_ERROR get_value_uint16(const struct afb_req request, const char *source, uint16_t *out_id);
40 REQ_ERROR get_value_int16(const struct afb_req request, const char *source, int16_t *out_id);
41 REQ_ERROR get_value_int32(const struct afb_req request, const char *source, int32_t *out_id);
42 void hs_add_object_to_json_object(struct json_object* j_obj, int count, ...);
43 void hs_add_object_to_json_object_str(struct json_object* j_obj, int count, ...);
44 void hs_add_object_to_json_object_func(struct json_object* j_obj, const char* verb_name, int count, ...);
45 int hs_search_event_name_index(const char* value);
46 
47 #endif /*HOMESCREEN_HELPER_H*/
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125
+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 #ifndef HOMESCREEN_HELPER_H
18 #define HOMESCREEN_HELPER_H
19 #define AFB_BINDING_VERSION 2
20 #include <afb/afb-binding.h>
21 #include <stdint.h>
22 #include <glib.h>
23 #include <errno.h>
24 #include "hmi-debug.h"
25 
26 typedef enum REQ_ERROR
27 {
28  REQ_FAIL = -1,
29  REQ_OK=0,
32 }REQ_ERROR;
33 
34 static const char* evlist[] = {
35  "tap_shortcut",
36  "on_screen_message",
37  "on_screen_reply",
38  "reserved"
39  };
40 
41 REQ_ERROR get_value_uint16(const struct afb_req request, const char *source, uint16_t *out_id);
42 REQ_ERROR get_value_int16(const struct afb_req request, const char *source, int16_t *out_id);
43 REQ_ERROR get_value_int32(const struct afb_req request, const char *source, int32_t *out_id);
44 void hs_add_object_to_json_object(struct json_object* j_obj, int count, ...);
45 void hs_add_object_to_json_object_str(struct json_object* j_obj, int count, ...);
46 void hs_add_object_to_json_object_func(struct json_object* j_obj, const char* verb_name, int count, ...);
47 int hs_search_event_name_index(const char* value);
48 
49 #endif /*HOMESCREEN_HELPER_H*/
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125
REQ_ERROR get_value_uint16(const struct afb_req request, const char *source, uint16_t *out_id)
Definition: hs-helper.c:24
void hs_add_object_to_json_object(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:96
REQ_ERROR get_value_int32(const struct afb_req request, const char *source, int32_t *out_id)
Definition: hs-helper.c:72
REQ_ERROR get_value_int16(const struct afb_req request, const char *source, int16_t *out_id)
Definition: hs-helper.c:48
int hs_search_event_name_index(const char *value)
Definition: hs-helper.c:142
-
static const char * evlist[]
Definition: hs-helper.h:33
- - - - -
REQ_ERROR
Definition: hs-helper.h:25
+
static const char * evlist[]
Definition: hs-helper.h:34
+ + + + +
REQ_ERROR
Definition: hs-helper.h:26
+
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.c:110
diff --git a/doc/api-ref/html/d7/df4/class_lib_home_screen-members.html b/doc/api-ref/html/d7/df4/class_lib_home_screen-members.html index 01e073d..6171ad9 100644 --- a/doc/api-ref/html/d7/df4/class_lib_home_screen-members.html +++ b/doc/api-ref/html/d7/df4/class_lib_home_screen-members.html @@ -70,25 +70,26 @@ $(function() { call(const char *verb, struct json_object *arg)LibHomeScreen event_listLibHomeScreenstatic Event_OnScreenMessage enum valueLibHomeScreen - Event_TapShortcut enum valueLibHomeScreen - EventType enum nameLibHomeScreen - handler_func typedefLibHomeScreen - init(const int port, const std::string &token)LibHomeScreen - LibHomeScreen()LibHomeScreen - LibHomeScreen(const LibHomeScreen &)=deleteLibHomeScreen - on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)LibHomeScreen - on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)LibHomeScreen - on_hangup(void *closure, struct afb_wsj1 *wsj)LibHomeScreen - on_reply(void *closure, struct afb_wsj1_msg *msg)LibHomeScreen - onScreenMessage(const char *display_message)LibHomeScreen + Event_OnScreenReply enum valueLibHomeScreen + Event_TapShortcut enum valueLibHomeScreen + EventType enum nameLibHomeScreen + handler_func typedefLibHomeScreen + init(const int port, const std::string &token)LibHomeScreen + LibHomeScreen()LibHomeScreen + LibHomeScreen(const LibHomeScreen &)=deleteLibHomeScreen + on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)LibHomeScreen + on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)LibHomeScreen + on_hangup(void *closure, struct afb_wsj1 *wsj)LibHomeScreen + on_reply(void *closure, struct afb_wsj1_msg *msg)LibHomeScreen + onScreenMessage(const char *display_message)LibHomeScreen + onScreenReply(const char *reply_message)LibHomeScreen operator=(const LibHomeScreen &)=deleteLibHomeScreen registerCallback(void(*event_cb)(const std::string &event, struct json_object *event_contents), void(*reply_cb)(struct json_object *reply_contents), void(*hangup_cb)(void)=nullptr)LibHomeScreen - runEventloop()LibHomeScreen - set_event_handler(enum EventType et, handler_func f)LibHomeScreen - subscribe(const std::string &event_name)LibHomeScreen - tapShortcut(const char *application_name)LibHomeScreen - unsubscribe(const std::string &event_name)LibHomeScreen - ~LibHomeScreen()LibHomeScreen + set_event_handler(enum EventType et, handler_func f)LibHomeScreen + subscribe(const std::string &event_name)LibHomeScreen + tapShortcut(const char *application_name)LibHomeScreen + unsubscribe(const std::string &event_name)LibHomeScreen + ~LibHomeScreen()LibHomeScreen