HomeScreenBinding
Classes | Macros | Functions | Variables
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   4
 
#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 on_screen_reply (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_on_screen_reply
 
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 char _reply_message [] = "reply_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   4

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

◆ on_screen_message()

static void on_screen_message ( struct afb_req  request)
static

HomeScreen OnScreen message

Parameters

Request key

  • display_message : message for display

Return

Nothing

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

◆ onevent()

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

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

◆ pingSample()

static void pingSample ( struct afb_req  request)
static

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

◆ preinit()

static int preinit ( )
static

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

◆ subscribe()

static void subscribe ( struct afb_req  request)
static

Subscribe event

Parameters

Return

Nothing

Note

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

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

Parameters

Request key

  • application_name : application name

Return

Nothing

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

◆ unsubscribe()

static void unsubscribe ( struct afb_req  request)
static

Unsubscribe event

Parameters

Return

Nothing

Note

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
#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 49 of file homescreen.c.

◆ _display_message

const char _display_message[] = "display_message"
static

Definition at line 50 of file homescreen.c.

◆ _error

const char _error[] = "error"
static

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.

◆ 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: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 306 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_on_screen_reply

struct afb_event ev_on_screen_reply
static

Definition at line 44 of file homescreen.c.

◆ ev_reserved

struct afb_event ev_reserved
static

Definition at line 45 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 = "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 260 of file homescreen.c.