From e0163d2b8daae98ced81f4bc737998c00858e771 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Fri, 29 Sep 2017 20:42:53 +0900 Subject: Add agl-service-homescreen-2017 Add a new binding agl-service-homescreen-2017 for homescreen-2017. There is a gles sample how to use this binding in sample/simple-egl. A image about this see JIRA SPEC-871. [PatchSets2] Use aglwgt make package. Change-Id: I9ae89188f9eb2de4c98ec8baa2f05fccca8b2372 Signed-off-by: zheng_wenlong --- doc/api-ref/html/d0/d1e/homescreen_8c.html | 727 +++++++++++++++++++++ doc/api-ref/html/d0/d1e/homescreen_8c_source.html | 104 +++ doc/api-ref/html/d0/d8a/libhomescreen_8cpp.html | 549 ++++++++++++++++ .../html/d0/d8a/libhomescreen_8cpp_source.html | 112 ++++ 4 files changed, 1492 insertions(+) create mode 100644 doc/api-ref/html/d0/d1e/homescreen_8c.html create mode 100644 doc/api-ref/html/d0/d1e/homescreen_8c_source.html create mode 100644 doc/api-ref/html/d0/d8a/libhomescreen_8cpp.html create mode 100644 doc/api-ref/html/d0/d8a/libhomescreen_8cpp_source.html (limited to 'doc/api-ref/html/d0') diff --git a/doc/api-ref/html/d0/d1e/homescreen_8c.html b/doc/api-ref/html/d0/d1e/homescreen_8c.html new file mode 100644 index 0000000..8907a06 --- /dev/null +++ b/doc/api-ref/html/d0/d1e/homescreen_8c.html @@ -0,0 +1,727 @@ + + + + + + + +HomeScreenBinding: homescreen_service/homescreen.c File Reference + + + + + + + + + +
+
+ + + + + + +
+
HomeScreenBinding +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
homescreen.c File Reference
+
+
+
#include <afb/afb-binding.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <json-c/json.h>
+#include <glib.h>
+#include <pthread.h>
+#include "hs-helper.h"
+
+

Go to the source code of this file.

+ + + + +

+Classes

struct  event
 
+ + + + + + + + + +

+Macros

#define _GNU_SOURCE
 
#define AFB_BINDING_VERSION   2
 
#define COMMAND_EVENT_NUM   3
 
#define EVENT_SUBSCRIBE_ERROR_CODE   100
 
+ + + + + + + + + + + + + + + + + +

+Functions

static void pingSample (struct afb_req request)
 
static void tap_shortcut (struct afb_req request)
 
static void on_screen_message (struct afb_req request)
 
static void subscribe (struct afb_req request)
 
static void unsubscribe (struct afb_req request)
 
static int preinit ()
 
static int init ()
 
static void onevent (const char *event, struct json_object *object)
 
+ + + + + + + + + + + + + + + + + + + +

+Variables

static struct event event_list [COMMAND_EVENT_NUM]
 
static struct afb_event ev_tap_shortcut
 
static struct afb_event ev_on_screen_message
 
static struct afb_event ev_reserved
 
static const char _error [] = "error"
 
static const char _application_name [] = "application_name"
 
static const char _display_message [] = "display_message"
 
static const struct afb_verb_v2 verbs []
 
const struct afb_binding_v2 afbBindingV2
 
+

Macro Definition Documentation

+ +

◆ _GNU_SOURCE

+ +
+
+ + + + +
#define _GNU_SOURCE
+
+ +

Definition at line 17 of file homescreen.c.

+ +
+
+ +

◆ AFB_BINDING_VERSION

+ +
+
+ + + + +
#define AFB_BINDING_VERSION   2
+
+ +

Definition at line 18 of file homescreen.c.

+ +
+
+ +

◆ COMMAND_EVENT_NUM

+ +
+
+ + + + +
#define COMMAND_EVENT_NUM   3
+
+ +

Definition at line 31 of file homescreen.c.

+ +
+
+ +

◆ EVENT_SUBSCRIBE_ERROR_CODE

+ +
+
+ + + + +
#define EVENT_SUBSCRIBE_ERROR_CODE   100
+
+ +

Definition at line 32 of file homescreen.c.

+ +
+
+

Function Documentation

+ +

◆ init()

+ +
+
+ + + + + +
+ + + + + + + +
static int init ()
+
+static
+
+ +

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
+
const char * name
Definition: homescreen.c:36
+
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
+
+
+
+ +

◆ on_screen_message()

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

HomeScreenのOnScreenを表示する

+

Parameters

+

Request key

    +
  • display_message : 表示したい文字列
  • +
+

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
+
static struct afb_event ev_on_screen_message
Definition: homescreen.c:43
+
static const char _display_message[]
Definition: homescreen.c:49
+
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125
+
+
+
+ +

◆ onevent()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
static void onevent (const char * event,
struct json_object * object 
)
+
+static
+
+ +

Definition at line 258 of file homescreen.c.

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

◆ pingSample()

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

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

◆ preinit()

+ +
+
+ + + + + +
+ + + + + + + +
static int preinit ()
+
+static
+
+ +

Definition at line 232 of file homescreen.c.

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

◆ subscribe()

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

Subscribe event

+

Parameters

+ +

Return

+

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
+ +
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
+
#define EVENT_SUBSCRIBE_ERROR_CODE
Definition: homescreen.c:32
+
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125
+
+
+
+ +

◆ tap_shortcut()

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

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

+

Parameters

+

Request key

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

◆ unsubscribe()

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

Unsubscribe event

+

Parameters

+ +

Return

+

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
+ +
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
+
#define EVENT_SUBSCRIBE_ERROR_CODE
Definition: homescreen.c:32
+
void hs_add_object_to_json_object_func(struct json_object *j_obj, const char *verb_name, int count,...)
Definition: hs-helper.c:125
+
+
+
+

Variable Documentation

+ +

◆ _application_name

+ +
+
+ + + + + +
+ + + + +
const char _application_name[] = "application_name"
+
+static
+
+ +

Definition at line 48 of file homescreen.c.

+ +
+
+ +

◆ _display_message

+ +
+
+ + + + + +
+ + + + +
const char _display_message[] = "display_message"
+
+static
+
+ +

Definition at line 49 of file homescreen.c.

+ +
+
+ +

◆ _error

+ +
+
+ + + + + +
+ + + + +
const char _error[] = "error"
+
+static
+
+ +

Definition at line 46 of file homescreen.c.

+ +
+
+ +

◆ afbBindingV2

+ +
+
+ + + + +
const struct afb_binding_v2 afbBindingV2
+
+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
+
+

Definition at line 263 of file homescreen.c.

+ +
+
+ +

◆ ev_on_screen_message

+ +
+
+ + + + + +
+ + + + +
struct afb_event ev_on_screen_message
+
+static
+
+ +

Definition at line 43 of file homescreen.c.

+ +
+
+ +

◆ ev_reserved

+ +
+
+ + + + + +
+ + + + +
struct afb_event ev_reserved
+
+static
+
+ +

Definition at line 44 of file homescreen.c.

+ +
+
+ +

◆ ev_tap_shortcut

+ +
+
+ + + + + +
+ + + + +
struct afb_event ev_tap_shortcut
+
+static
+
+ +

Definition at line 42 of file homescreen.c.

+ +
+
+ +

◆ event_list

+ +
+
+ + + + + +
+ + + + +
struct event event_list[COMMAND_EVENT_NUM]
+
+static
+
+ +

Definition at line 40 of file homescreen.c.

+ +
+
+ +

◆ verbs

+ +
+
+ + + + + +
+ + + + +
const struct afb_verb_v2 verbs[]
+
+static
+
+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
+
+

Definition at line 222 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 new file mode 100644 index 0000000..ad66469 --- /dev/null +++ b/doc/api-ref/html/d0/d1e/homescreen_8c_source.html @@ -0,0 +1,104 @@ + + + + + + + +HomeScreenBinding: homescreen_service/homescreen.c Source File + + + + + + + + + +
+
+ + + + + + +
+
HomeScreenBinding +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
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
+
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
+ + +
static int init()
Definition: homescreen.c:238
+
static const char * evlist[]
Definition: hs-helper.h:33
+
const char * name
Definition: homescreen.c:36
+
static void unsubscribe(struct afb_req request)
Definition: homescreen.c:191
+
int hs_search_event_name_index(const char *value)
Definition: hs-helper.c:142
+
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 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
+
#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
+
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 new file mode 100644 index 0000000..0c33842 --- /dev/null +++ b/doc/api-ref/html/d0/d8a/libhomescreen_8cpp.html @@ -0,0 +1,549 @@ + + + + + + + +HomeScreenBinding: libhomescreen.cpp File Reference + + + + + + + + + +
+
+ + + + + + +
+
HomeScreenBinding +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
libhomescreen.cpp File Reference
+
+
+
#include <stdarg.h>
+#include <sys/socket.h>
+#include <iostream>
+#include <algorithm>
+#include <thread>
+#include <errno.h>
+#include <cassert>
+#include <cctype>
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <libhomescreen.hpp>
+
+

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__)
 
+ + + + + + + + + + + + + + + + + +

+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 void _on_call_static (void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
 
static void _on_event_static (void *closure, const char *event, struct afb_wsj1_msg *msg)
 
static void _on_reply_static (void *closure, struct afb_wsj1_msg *msg)
 
static void * event_loop_run (void *args)
 
+ + + +

+Variables

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()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
static void _on_call_static (void * closure,
const char * api,
const char * verb,
struct afb_wsj1_msg * msg 
)
+
+static
+
+ +

Definition at line 66 of file libhomescreen.cpp.

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

◆ _on_event_static()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
static void _on_event_static (void * closure,
const char * event,
struct afb_wsj1_msg * msg 
)
+
+static
+
+ +

Definition at line 71 of file libhomescreen.cpp.

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

◆ _on_hangup_static()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
static void _on_hangup_static (void * closure,
struct afb_wsj1 * wsj 
)
+
+static
+
+

websocket

+ +

Definition at line 61 of file libhomescreen.cpp.

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

◆ _on_reply_static()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
static void _on_reply_static (void * closure,
struct afb_wsj1_msg * msg 
)
+
+static
+
+ +

Definition at line 76 of file libhomescreen.cpp.

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

◆ event_loop_run()

+ +
+
+ + + + + +
+ + + + + + + + +
static void* event_loop_run (void * args)
+
+static
+
+ +

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,...)
+
+
+
+ +

◆ has_verb()

+ +
+
+ + + + + +
+ + + + + + + + +
static bool has_verb (const string & verb)
+
+static
+
+ +

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

Variable Documentation

+ +

◆ API

+ +
+
+ + + + + +
+ + + + +
const char API[] = "homescreen"
+
+static
+
+ +

Definition at line 40 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 new file mode 100644 index 0000000..9e93d6f --- /dev/null +++ b/doc/api-ref/html/d0/d8a/libhomescreen_8cpp_source.html @@ -0,0 +1,112 @@ + + + + + + + +HomeScreenBinding: libhomescreen/libhomescreen.cpp Source File + + + + + + + + + +
+
+ + + + + + +
+
HomeScreenBinding +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
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,...)
+ + +
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 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)
+
+ + + + -- cgit 1.2.3-korg