HomeScreenBinding
Public Member Functions | List of all members
HS_Client Class Reference

#include <hs-client.h>

Public Member Functions

 HS_Client (afb_req_t request, const char *id)
 
 HS_Client (afb_req_t request, std::string id)
 
 HS_Client (HS_Client &)=delete
 
HS_Clientoperator= (HS_Client &)=delete
 
 ~HS_Client ()
 
int tap_shortcut (const char *appid)
 
int showWindow (afb_req_t request, const char *appid)
 
int hideWindow (afb_req_t request)
 
int replyShowWindow (afb_req_t request, const char *appid)
 
int on_screen_message (afb_req_t request, const char *message)
 
int on_screen_reply (afb_req_t request, const char *message)
 
int subscribe (afb_req_t request, const char *event)
 
int unsubscribe (afb_req_t request, const char *event)
 
int showNotification (afb_req_t request)
 
int showInformation (afb_req_t request)
 

Detailed Description

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

Constructor & Destructor Documentation

HS_Client::HS_Client ( afb_req_t  request,
const char *  id 
)
inline

Definition at line 27 of file hs-client.h.

27 : HS_Client(request, std::string(id)){}
HS_Client(afb_req_t request, const char *id)
Definition: hs-client.h:27
HS_Client::HS_Client ( afb_req_t  request,
std::string  id 
)

HS_Client construction function

Parameters

  • id: app's id

Return

None

Definition at line 38 of file hs-client.cpp.

38  : my_id(id)
39 {
40  HMI_NOTICE("homescreen-service","called.");
41  my_event = afb_api_make_event(request->api, id.c_str());
42 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
HS_Client::HS_Client ( HS_Client )
delete
HS_Client::~HS_Client ( )

HS_Client destruction function

Parameters

  • null

Return

None

Definition at line 54 of file hs-client.cpp.

55 {
56  HMI_NOTICE("homescreen-service","called.");
57  afb_event_unref(my_event);
58 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40

Member Function Documentation

int HS_Client::hideWindow ( afb_req_t  request)

hideWindow event

input contents : {"application_id":"the appid that want to hide"}

Parameters

  • request : the request

Return

0 : success others : fail

Definition at line 245 of file hs-client.cpp.

246 {
247  if(!checkEvent(__FUNCTION__))
248  return 0;
249 
250  HMI_NOTICE("homescreen-service","%s application_id = %s.", __FUNCTION__);
251  const char* req_appid = afb_req_get_application_id(request);
252  struct json_object* push_obj = json_object_new_object();
253  hs_add_object_to_json_object_str( push_obj, 4, _application_id, req_appid,
254  _type, __FUNCTION__);
255  afb_event_push(my_event, push_obj);
256  return 0;
257 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
static const char _type[]
Definition: hs-client.cpp:21
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.cpp:180
const char _application_id[]
Definition: homescreen.cpp:28
int HS_Client::on_screen_message ( afb_req_t  request,
const char *  message 
)

push on_screen_message event

Parameters

  • message: post message.

Return

result

Definition at line 93 of file hs-client.cpp.

94 {
95  if(!checkEvent(__FUNCTION__))
96  return 0;
97 
98  HMI_NOTICE("homescreen-service","push %s event message [%s].", __FUNCTION__, message);
99  struct json_object* push_obj = json_object_new_object();
100  hs_add_object_to_json_object_str( push_obj, 4, _display_message, message,
101  _type, __FUNCTION__);
102  afb_event_push(my_event, push_obj);
103  return 0;
104 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
static const char _type[]
Definition: hs-client.cpp:21
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.cpp:180
const char _display_message[]
Definition: homescreen.cpp:29
int HS_Client::on_screen_reply ( afb_req_t  request,
const char *  message 
)

push on_screen_reply event

Parameters

  • message: reply message.

Return

result

Definition at line 116 of file hs-client.cpp.

117 {
118  if(!checkEvent(__FUNCTION__))
119  return 0;
120 
121  HMI_NOTICE("homescreen-service","push %s event message [%s].", __FUNCTION__, message);
122  struct json_object* push_obj = json_object_new_object();
123  hs_add_object_to_json_object_str( push_obj, 4, _reply_message, message,
124  _type, __FUNCTION__);
125  afb_event_push(my_event, push_obj);
126  return 0;
127 }
const char _reply_message[]
Definition: homescreen.cpp:30
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
static const char _type[]
Definition: hs-client.cpp:21
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.cpp:180
HS_Client& HS_Client::operator= ( HS_Client )
delete
int HS_Client::replyShowWindow ( afb_req_t  request,
const char *  appid 
)

replyShowWindow event

input contens : {"application_id": "the appid that want to reply", "parameter": {...}}

Parameters

  • request : the request
  • appid : the appid that want to reply

Return

0 : success others : fail

Definition at line 273 of file hs-client.cpp.

274 {
275  if(!checkEvent(__FUNCTION__))
276  return 0;
277 
278  HMI_NOTICE("homescreen-service","%s application_id = %s.", __FUNCTION__, appid);
279  struct json_object* push_obj = json_object_new_object();
280  hs_add_object_to_json_object_str( push_obj, 4, _application_id, appid, _type, __FUNCTION__);
281  const char* param = afb_req_value(request, _parameter);
282  if(param) {
283  json_object_object_add(push_obj, _parameter, json_tokener_parse(param));
284  }
285  else {
286  HMI_ERROR("homescreen-service","please input correct parameter.");
287  return AFB_EVENT_BAD_REQUEST;
288  }
289 
290  afb_event_push(my_event, push_obj);
291  return 0;
292 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
static const char _parameter[]
Definition: hs-client.cpp:25
static const char _type[]
Definition: hs-client.cpp:21
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.cpp:180
#define HMI_ERROR(prefix, args,...)
Definition: hmi-debug.h:38
const char _application_id[]
Definition: homescreen.cpp:28
#define AFB_EVENT_BAD_REQUEST
Definition: hs-helper.h:23
int HS_Client::showInformation ( afb_req_t  request)

showInformation event

input contents : {"info": "information contents"}

Parameters

  • request : the request

Return

0 : success others : fail

Definition at line 350 of file hs-client.cpp.

351 {
352  int ret = 0;
353  const char *value = afb_req_value(request, _info);
354  if(value) {
355  HMI_NOTICE("homescreen-service","info is %s", value);
356  const char* appid = afb_req_get_application_id(request);
357  struct json_object* param_obj = json_object_new_object();
358  json_object_object_add(param_obj, _info, json_object_new_string(value));
359  struct json_object* push_obj = json_object_new_object();
360  hs_add_object_to_json_object_str( push_obj, 4, _application_id, appid, _type, __FUNCTION__);
361  json_object_object_add(push_obj, _parameter, param_obj);
362  afb_event_push(my_event, push_obj);
363  }
364  else {
365  HMI_NOTICE("homescreen-service","please input information.");
367  }
368 
369  return ret;
370 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
static const char _parameter[]
Definition: hs-client.cpp:25
static const char _type[]
Definition: hs-client.cpp:21
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.cpp:180
static const char _info[]
Definition: hs-client.cpp:23
const char _application_id[]
Definition: homescreen.cpp:28
#define AFB_REQ_SHOWINFORMATION_ERROR
Definition: hs-helper.h:27
int HS_Client::showNotification ( afb_req_t  request)

showNotification event

input contents : {"icon": "icon path", "text": "message contents"}

Parameters

  • request : the request

Return

0 : success others : fail

Definition at line 307 of file hs-client.cpp.

308 {
309  int ret = 0;
310  const char *value = afb_req_value(request, _text);
311  if(value) {
312  HMI_NOTICE("homescreen-service","text is %s", value);
313  const char* appid = afb_req_get_application_id(request);
314  struct json_object* param_obj = json_object_new_object();
315  const char *icon = afb_req_value(request, _icon);
316  if(icon) {
317  json_object_object_add(param_obj, _icon, json_object_new_string(icon));
318  json_object_object_add(param_obj, _text, json_object_new_string(value));
319  struct json_object* push_obj = json_object_new_object();
320  hs_add_object_to_json_object_str( push_obj, 4, _application_id, appid, _type, __FUNCTION__);
321  json_object_object_add(push_obj, _parameter, param_obj);
322  afb_event_push(my_event, push_obj);
323  }
324  else {
325  HMI_NOTICE("homescreen-service","please input icon.");
327  }
328  }
329  else {
330  HMI_NOTICE("homescreen-service","please input text.");
332  }
333 
334  return ret;
335 }
static const char _text[]
Definition: hs-client.cpp:22
#define AFB_REQ_SHOWNOTIFICATION_ERROR
Definition: hs-helper.h:26
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
static const char _parameter[]
Definition: hs-client.cpp:25
static const char _type[]
Definition: hs-client.cpp:21
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.cpp:180
static const char _icon[]
Definition: hs-client.cpp:24
const char _application_id[]
Definition: homescreen.cpp:28
int HS_Client::showWindow ( afb_req_t  request,
const char *  appid 
)

showWindow event

input contents : {"application_id":"the appid that want to display", "parameter":{"area": "display area", ...}}

Parameters

  • request : the request
  • appid : the appid that want to display

Return

0 : success others : fail

Definition at line 209 of file hs-client.cpp.

210 {
211  if(!checkEvent(__FUNCTION__))
212  return 0;
213 
214  HMI_NOTICE("homescreen-service","%s application_id = %s.", __FUNCTION__, appid);
215  struct json_object* push_obj = json_object_new_object();
216  hs_add_object_to_json_object_str( push_obj, 4, _application_id, appid, _type, __FUNCTION__);
217  const char* param = afb_req_value(request, _parameter);
218  if(param) {
219  const char* req_appid = afb_req_get_application_id(request);
220  struct json_object* param_obj = json_tokener_parse(param);
221  json_object_object_add(param_obj, _replyto, json_object_new_string(req_appid));
222  json_object_object_add(push_obj, _parameter, param_obj);
223  }
224  else {
225  HMI_ERROR("homescreen-service","please input correct parameter.");
226  return AFB_EVENT_BAD_REQUEST;
227  }
228  afb_event_push(my_event, push_obj);
229  return 0;
230 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
static const char _parameter[]
Definition: hs-client.cpp:25
static const char _type[]
Definition: hs-client.cpp:21
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.cpp:180
#define HMI_ERROR(prefix, args,...)
Definition: hmi-debug.h:38
static const char _replyto[]
Definition: hs-client.cpp:26
const char _application_id[]
Definition: homescreen.cpp:28
#define AFB_EVENT_BAD_REQUEST
Definition: hs-helper.h:23
int HS_Client::subscribe ( afb_req_t  request,
const char *  event 
)

subscribe event

Parameters

  • event: homescreen event, tap_shortcut etc.

Return

result

Definition at line 139 of file hs-client.cpp.

140 {
141  int ret = 0;
142  auto ip = event_list.find(std::string(event));
143  if(ip == event_list.end()) {
144  event_list[std::string(event)] = 0;
145  }
146  if(!subscription) {
147  ret = afb_req_subscribe(request, my_event);
148  if(ret == 0) {
149  subscription = true;
150  }
151  }
152  return ret;
153 }
int HS_Client::tap_shortcut ( const char *  appid)

push tap_shortcut event

Parameters

  • appid: app's id.

Return

result

Definition at line 70 of file hs-client.cpp.

71 {
72  if(!checkEvent(__FUNCTION__))
73  return 0;
74 
75  HMI_NOTICE("homescreen-service","%s application_id = %s.", __FUNCTION__, appid);
76  struct json_object* push_obj = json_object_new_object();
78  _type, __FUNCTION__);
79  afb_event_push(my_event, push_obj);
80  return 0;
81 }
#define HMI_NOTICE(prefix, args,...)
Definition: hmi-debug.h:40
static const char _type[]
Definition: hs-client.cpp:21
void hs_add_object_to_json_object_str(struct json_object *j_obj, int count,...)
Definition: hs-helper.cpp:180
const char _application_id[]
Definition: homescreen.cpp:28
int HS_Client::unsubscribe ( afb_req_t  request,
const char *  event 
)

unsubscribe event

Parameters

  • event: homescreen event, tap_shortcut etc.

Return

result

Definition at line 165 of file hs-client.cpp.

166 {
167  int ret = 0;
168  event_list.erase(std::string(event));
169  if(event_list.empty()) {
170  ret = afb_req_unsubscribe(request, my_event);
171  }
172  return ret;
173 }

The documentation for this class was generated from the following files: