HomeScreenBinding
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
LibHomeScreen Class Reference

#include <libhomescreen.hpp>

Public Types

enum  EventType {
  Event_ShowWindow = 1, Event_TapShortcut = 1, Event_OnScreenMessage, Event_OnScreenReply,
  Event_HideWindow, Event_ReplyShowWindow, Event_ShowNotification, Event_ShowInformation
}
 
using handler_func = std::function< void(json_object *)>
 

Public Member Functions

 LibHomeScreen ()
 
 ~LibHomeScreen ()
 
 LibHomeScreen (const LibHomeScreen &)=delete
 
LibHomeScreenoperator= (const LibHomeScreen &)=delete
 
int init (const int port, const std::string &token)
 
int tapShortcut (const char *application_id)
 
int onScreenMessage (const char *display_message)
 
int onScreenReply (const char *reply_message)
 
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)
 
int call (const std::string &verb, struct json_object *arg)
 
int call (const char *verb, struct json_object *arg)
 
int subscribe (const std::string &event_name)
 
int unsubscribe (const std::string &event_name)
 
int showWindow (const char *application_id, json_object *json)
 
int hideWindow (const char *application_id)
 
int replyShowWindow (const char *application_id, json_object *json)
 
int showNotification (json_object *json)
 
int showInformation (json_object *json)
 
void on_hangup (void *closure, struct afb_wsj1 *wsj)
 
void on_call (void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
 
void on_event (void *closure, const char *event, struct afb_wsj1_msg *msg)
 
void on_reply (void *closure, struct afb_wsj1_msg *msg)
 

Public Attributes

const char * _keyParameter = "parameter"
 
const char * _keyArea = "area"
 
const char * _areaNormal = "normal"
 
const char * _areaFullScreen = "fullscreen"
 
const char * _areaSplitMain = "split.main"
 
const char * _areaSplitSub = "split.sub"
 

Static Public Attributes

static const std::vector< std::string > api_list
 
static const std::vector< std::string > event_list
 

Detailed Description

Definition at line 31 of file libhomescreen.hpp.

Member Typedef Documentation

using LibHomeScreen::handler_func = std::function<void(json_object*)>

Definition at line 40 of file libhomescreen.hpp.

Member Enumeration Documentation

Constructor & Destructor Documentation

LibHomeScreen::LibHomeScreen ( )

constructor

Definition at line 93 of file libhomescreen.cpp.

94 {
95 }
LibHomeScreen::~LibHomeScreen ( )

destructor

Definition at line 100 of file libhomescreen.cpp.

101 {
102  if(mploop)
103  {
104  sd_event_unref(mploop);
105  }
106  if(sp_websock != NULL)
107  {
108  afb_wsj1_unref(sp_websock);
109  }
110 }
LibHomeScreen::LibHomeScreen ( const LibHomeScreen )
delete

Member Function Documentation

int LibHomeScreen::call ( const std::string &  verb,
struct json_object *  arg 
)
int LibHomeScreen::call ( const char *  verb,
struct json_object *  arg 
)

This function calls the API of HomeScreen via WebSocket This function is overload function of "call"

Parameters

  • verb [in] : This argument should be specified to the API name (e.g. "tap_shortcut")
  • arg [in] : This argument should be specified to the argument of API. And this argument expects JSON object

Return

  • Returns 0 on success or -1 in case of error.

Note

To call HomeScreen's APIs, the application should set its function name, arguments to JSON format.

Definition at line 377 of file libhomescreen.cpp.

378 {
379  int ret;
380  if(!sp_websock)
381  {
382  return -1;
383  }
384  if (!has_verb(string(verb)))
385  {
386  HMI_ERROR("libhomescreen","verb doesn't exit");
387  return -1;
388  }
389  ret = afb_wsj1_call_j(sp_websock, API, verb, arg, _on_reply_static, this);
390  if (ret < 0) {
391  HMI_ERROR("libhomescreen","Failed to call verb:%s",verb);
392  }
393  return ret;
394 }
static const char API[]
static bool has_verb(const string &verb)
#define HMI_ERROR(prefix, args,...)
Definition: hmi-debug.h:38
static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
int LibHomeScreen::hideWindow ( const char *  application_id)

Sending hide window event

Call HomeScreen Service's hideWindow verb to release id's screen.

Parameters

  • application_id [in] : This argument should be specified to the application's id.

Return

  • Returns 0 on success or -1 in case of error.

Definition at line 503 of file libhomescreen.cpp.

504 {
505  if(!sp_websock)
506  {
507  return -1;
508  }
509 
510  struct json_object* j_obj = json_object_new_object();
511  struct json_object* val = json_object_new_string(application_id);
512  json_object_object_add(j_obj, ApplicationId, val);
513 
514  return this->call("hideWindow", j_obj);
515 }
static const char ApplicationId[]
int call(const std::string &verb, struct json_object *arg)
int LibHomeScreen::init ( const int  port,
const std::string &  token 
)

This function is initializer

Parameters

  • port [in] : This argument should be specified to the port number to be used for websocket
  • token [in] : This argument should be specified to the token to be used for websocket

Return

Nothing

Note

Use this constructor

Definition at line 126 of file libhomescreen.cpp.

127 {
128  int ret = 0;
129  if(port > 0 && token.size() > 0)
130  {
131  mport = port;
132  mtoken = token;
133  }
134  else
135  {
136  HMI_ERROR("libhomescreen","port and token should be > 0, Initial port and token uses.");
137  }
138 
139  ret = initialize_websocket();
140  if(ret != 0 )
141  {
142  HMI_ERROR("libhomescreen","Failed to initialize websocket");
143  }
144  else{
145  HMI_DEBUG("libhomescreen","Initialized");
146  }
147 
148  return ret;
149 }
string token
Definition: simple-egl.cpp:61
long port
Definition: simple-egl.cpp:60
#define HMI_ERROR(prefix, args,...)
Definition: hmi-debug.h:38
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:42
void LibHomeScreen::on_call ( void *  closure,
const char *  api,
const char *  verb,
struct afb_wsj1_msg *  msg 
)

Definition at line 606 of file libhomescreen.cpp.

607 {
608 }
void LibHomeScreen::on_event ( void *  closure,
const char *  event,
struct afb_wsj1_msg *  msg 
)

Definition at line 616 of file libhomescreen.cpp.

617 {
618  HMI_DEBUG("libhomescreen","event: (%s) msg: (%s).", event, afb_wsj1_msg_object_s(msg));
619 
620  if (strstr(event, API) == NULL) {
621  return;
622  }
623 
624  struct json_object* ev_contents = afb_wsj1_msg_object_j(msg);
625  struct json_object *json_data;
626  if(!json_object_object_get_ex(ev_contents, "data", &json_data)) {
627  HMI_ERROR("libhomescreen", "got ev_contents error.");
628  return;
629  }
630 
631  if(onEvent != nullptr)
632  {
633  const string ev(event);
634  onEvent(ev, ev_contents);
635  }
636 
637  const char* event_type = nullptr;
638  struct json_object *json_event_type;
639  if(json_object_object_get_ex(json_data, "type", &json_event_type)) {
640  event_type = json_object_get_string(json_event_type);
641  }
642  else {
643  HMI_WARNING("libhomescreen","event_type is null.");
644  return;
645  }
646 
647  if (strcasecmp(event_type, LibHomeScreen::event_list[0].c_str()) == 0) {
648  auto i = this->handlers.find(Event_ShowWindow);
649  if ( i != this->handlers.end() ) {
650  i->second(json_data);
651  }
652  }
653  else if (strcasecmp(event_type, LibHomeScreen::event_list[1].c_str()) == 0) {
654  auto i = this->handlers.find(Event_OnScreenMessage);
655  if ( i != this->handlers.end() ) {
656  i->second(json_data);
657  }
658  }
659  else if (strcasecmp(event_type, LibHomeScreen::event_list[2].c_str()) == 0) {
660  auto i = this->handlers.find(Event_OnScreenReply);
661  if ( i != this->handlers.end() ) {
662  i->second(json_data);
663  }
664  }
665  else if (strcasecmp(event_type, LibHomeScreen::event_list[3].c_str()) == 0) {
666  auto i = this->handlers.find(Event_HideWindow);
667  if ( i != this->handlers.end() ) {
668  i->second(json_data);
669  }
670  }
671  else if (strcasecmp(event_type, LibHomeScreen::event_list[4].c_str()) == 0) {
672  auto i = this->handlers.find(Event_ReplyShowWindow);
673  if ( i != this->handlers.end() ) {
674  i->second(json_data);
675  }
676  }
677  else if (strcasecmp(event_type, LibHomeScreen::event_list[5].c_str()) == 0) {
678  auto i = this->handlers.find(Event_ShowNotification);
679  if ( i != this->handlers.end() ) {
680  i->second(json_data);
681  }
682  }
683  else if (strcasecmp(event_type, LibHomeScreen::event_list[6].c_str()) == 0) {
684  auto i = this->handlers.find(Event_ShowInformation);
685  if ( i != this->handlers.end() ) {
686  i->second(json_data);
687  }
688  }
689 }
static const char API[]
#define HMI_WARNING(prefix, args,...)
Definition: hmi-debug.h:39
static const std::vector< std::string > event_list
#define HMI_ERROR(prefix, args,...)
Definition: hmi-debug.h:38
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:42
void LibHomeScreen::on_hangup ( void *  closure,
struct afb_wsj1 *  wsj 
)

Definition at line 597 of file libhomescreen.cpp.

598 {
599  HMI_DEBUG("libhomescreen","called");
600  if(onHangup != nullptr)
601  {
602  onHangup();
603  }
604 }
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:42
void LibHomeScreen::on_reply ( void *  closure,
struct afb_wsj1_msg *  msg 
)

msg is like ({"response":{"verb":"subscribe","error":0},"jtype":"afb-reply","request":{"status":"success","info":"homescreen binder subscribe event name [on_screen_message]"}}) msg is like ({"response":{"verb":"tap_shortcut","error":0},"jtype":"afb-reply","request":{"status":"success","info":"afb_event_push event [tap_shortcut]"}})

Definition at line 695 of file libhomescreen.cpp.

696 {
697  HMI_DEBUG("libhomescreen","msg: (%s)", afb_wsj1_msg_object_s(msg));
698  if(onReply != nullptr)
699  {
700  struct json_object* reply = afb_wsj1_msg_object_j(msg);
701  onReply(reply);
702  }
703 }
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:42
int LibHomeScreen::onScreenMessage ( const char *  display_message)

Sending onScreen message event

Sending OnScreen message event to HomeScreen from applications

Parameters

  • display_message [in] : message for display

Return

  • Returns 0 on success or -1 in case of error.

Definition at line 242 of file libhomescreen.cpp.

243 {
244  if(!sp_websock)
245  {
246  return -1;
247  }
248 
249  struct json_object* j_obj = json_object_new_object();
250  struct json_object* val = json_object_new_string(display_message);
251  json_object_object_add(j_obj, "display_message", val);
252  return this->call("on_screen_message", j_obj);
253 }
int call(const std::string &verb, struct json_object *arg)
int LibHomeScreen::onScreenReply ( const char *  reply_message)

Sending onScreen reply event

Sending OnScreen reply event to applications from HomeScreen

Parameters

  • reply_message [in] : message for reply

Return

  • Returns 0 on success or -1 in case of error.

Definition at line 266 of file libhomescreen.cpp.

267 {
268  if(!sp_websock)
269  {
270  return -1;
271  }
272 
273  struct json_object* j_obj = json_object_new_object();
274  struct json_object* val = json_object_new_string(reply_message);
275  json_object_object_add(j_obj, "reply_message", val);
276  return this->call("on_screen_reply", j_obj);
277 }
int call(const std::string &verb, struct json_object *arg)
LibHomeScreen& LibHomeScreen::operator= ( const LibHomeScreen )
delete
void LibHomeScreen::registerCallback ( void(*)(const std::string &event, struct json_object *event_contents)  event_cb,
void(*)(struct json_object *reply_contents)  reply_cb,
void(*)(void)  hangup_cb = nullptr 
)

This function register callback function for reply/event message from home screen

Parameters

  • event_cb [in] : This argument should be specified to the callback for subscribed event
  • reply_cb [in] : This argument should be specified to the reply callback for call function

Return

Nothing

Note

Event callback is invoked by home screen for event you subscribed. If you would like to get event, please call subscribe function before/after this function

Definition at line 165 of file libhomescreen.cpp.

169 {
170  onEvent = event_cb;
171  onReply = reply_cb;
172  onHangup = hangup_cb;
173 }
int LibHomeScreen::replyShowWindow ( const char *  application_id,
json_object *  json 
)

Sending reply onscreen message event

Call HomeScreen Service's replyShowWindow verb to reply onscreen message.

Parameters

  • application_id [in] : This argument should be specified to the onscreen reply to applilcation id.
  • json [in] : This argument should be specified to the json parameters.

Return

  • Returns 0 on success or -1 in case of error.

Definition at line 530 of file libhomescreen.cpp.

531 {
532  if(!sp_websock)
533  {
534  return -1;
535  }
536 
537  if (json == nullptr) {
538  HMI_WARNING("libhomescreen", "replyShowWindow`s parameter is null");
539  return -1;
540  }
541 
542  struct json_object* j_obj = json_object_new_object();
543  struct json_object* val = json_object_new_string(application_id);
544  json_object_object_add(j_obj, ApplicationId, val);
545  json_object_object_add(j_obj, "parameter", json);
546 
547  return this->call("replyShowWindow", j_obj);
548 }
static const char ApplicationId[]
int call(const std::string &verb, struct json_object *arg)
#define HMI_WARNING(prefix, args,...)
Definition: hmi-debug.h:39
void LibHomeScreen::set_event_handler ( enum EventType  et,
handler_func  f 
)

Setting Event Handler

Setting event handler for Homescreen

Parameters

  • et [in] : event name
  • f [in] : event handler

Return

Nothing

Note

Don't release json_object by json_object_put in handler_func. The resource is released by libafbwsc library.

Definition at line 295 of file libhomescreen.cpp.

296 {
297  if (et >= 1 && et <= 7) {
298  switch (et) {
299 /* case Event_TapShortcut:
300  this->subscribe(LibHomeScreen::event_list[0]);
301  break;*/
302  case Event_ShowWindow:
304  break;
307  break;
308  case Event_OnScreenReply:
310  break;
311  case Event_HideWindow:
313  break;
316  break;
319  break;
322  break;
323  }
324 
325  this->handlers[et] = std::move(f);
326  }
327 }
int subscribe(const std::string &event_name)
static const std::vector< std::string > event_list
int LibHomeScreen::showInformation ( json_object *  json)

Sending show information event

Call HomeScreen Service's information verb to show notification on Information Bar.

Parameters

  • json [in] : This argument should be specified to the json parameters.

Return

  • Returns 0 on success or -1 in case of error.

Definition at line 584 of file libhomescreen.cpp.

585 {
586  if(!sp_websock)
587  {
588  return -1;
589  }
590 
591  return this->call("showInformation", json);
592 }
int call(const std::string &verb, struct json_object *arg)
int LibHomeScreen::showNotification ( json_object *  json)

Sending show notification event

Call HomeScreen Service's notification verb to show notification on Status Bar.

Parameters

  • json [in] : This argument should be specified to the json parameters.

Return

  • Returns 0 on success or -1 in case of error.

Definition at line 562 of file libhomescreen.cpp.

563 {
564  if(!sp_websock)
565  {
566  return -1;
567  }
568 
569  return this->call("showNotification", json);
570 }
int call(const std::string &verb, struct json_object *arg)
int LibHomeScreen::showWindow ( const char *  application_id,
json_object *  json 
)

Sending show window event

Call HomeScreen Service's showWindow verb to request display id's screen.

Parameters

  • application_id [in] : This argument should be specified to the application's id.
  • json [in] : This argument should be specified to the json parameters.

Return

  • Returns 0 on success or -1 in case of error.

Definition at line 467 of file libhomescreen.cpp.

468 {
469  if(!sp_websock)
470  {
471  return -1;
472  }
473 
474  struct json_object* j_obj = json_object_new_object();
475  struct json_object* val = json_object_new_string(application_id);
476  json_object_object_add(j_obj, ApplicationId, val);
477 
478  if (json == nullptr) {
479  struct json_object* j_json = json_object_new_object();
480  struct json_object* value = json_object_new_string("normal");
481  json_object_object_add(j_json, "area", value);
482  json_object_object_add(j_obj, "parameter", j_json);
483  }
484  else {
485  json_object_object_add(j_obj, "parameter", json);
486  }
487 
488  return this->call("showWindow", j_obj);
489 }
static const char ApplicationId[]
int call(const std::string &verb, struct json_object *arg)
int LibHomeScreen::subscribe ( const std::string &  event_name)

Register callback function for each event

Parameters

  • event_name [in] : This argument should be specified to the event name

Return

  • Returns 0 on success or -1 in case of error.

Note

This function enables to get an event to your callback function.

Definition at line 409 of file libhomescreen.cpp.

410 {
411  if(!sp_websock)
412  {
413  return -1;
414  }
415  struct json_object* j_obj = json_object_new_object();
416  json_object_object_add(j_obj, "event", json_object_new_string(event_name.c_str()));
417 
418  int ret = afb_wsj1_call_j(sp_websock, API, "subscribe", j_obj, _on_reply_static, this);
419  if (ret < 0) {
420  HMI_ERROR("libhomescreen","Failed to call verb");
421  }
422  return ret;
423 }
static const char API[]
#define HMI_ERROR(prefix, args,...)
Definition: hmi-debug.h:38
static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
int LibHomeScreen::tapShortcut ( const char *  application_id)

Sending ShortCut Icon tapped event

When HomeScreen shortcut area is tapped, sending a event

Parameters

  • application_id [in] : Tapped application id (label)

Return

  • Returns 0 on success or -1 in case of error.

Definition at line 222 of file libhomescreen.cpp.

223 {
224  struct json_object* obj = json_object_new_object();
225  struct json_object* val = json_object_new_string("normal");
226  json_object_object_add(obj, "area", val);
227 
228  return showWindow(application_id, obj);
229 }
int showWindow(const char *application_id, json_object *json)
int LibHomeScreen::unsubscribe ( const std::string &  event_name)

Unregister callback function for each event

Parameters

  • event_name [in] : This argument should be specified to the event name

Return

  • Returns 0 on success or -1 in case of error.

Note

This function disables to get an event to your callback function.

Definition at line 438 of file libhomescreen.cpp.

439 {
440  if(!sp_websock)
441  {
442  return -1;
443  }
444  struct json_object* j_obj = json_object_new_object();
445  json_object_object_add(j_obj, "event", json_object_new_string(event_name.c_str()));
446 
447  int ret = afb_wsj1_call_j(sp_websock, API, "unsubscribe", j_obj, _on_reply_static, this);
448  if (ret < 0) {
449  HMI_ERROR("libhomescreen","Failed to call verb");
450  }
451  return ret;
452 }
static const char API[]
#define HMI_ERROR(prefix, args,...)
Definition: hmi-debug.h:38
static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)

Member Data Documentation

const char* LibHomeScreen::_areaFullScreen = "fullscreen"

Definition at line 59 of file libhomescreen.hpp.

const char* LibHomeScreen::_areaNormal = "normal"

Definition at line 58 of file libhomescreen.hpp.

const char* LibHomeScreen::_areaSplitMain = "split.main"

Definition at line 60 of file libhomescreen.hpp.

const char* LibHomeScreen::_areaSplitSub = "split.sub"

Definition at line 61 of file libhomescreen.hpp.

const char* LibHomeScreen::_keyArea = "area"

Definition at line 55 of file libhomescreen.hpp.

const char* LibHomeScreen::_keyParameter = "parameter"

Definition at line 54 of file libhomescreen.hpp.

const std::vector< std::string > LibHomeScreen::api_list
static
Initial value:
{
std::string("ping"),
std::string("tap_shortcut"),
std::string("on_screen_message"),
std::string("on_screen_reply"),
std::string("subscribe"),
std::string("unsubscribe"),
std::string("showWindow"),
std::string("hideWindow"),
std::string("replyShowWindow"),
std::string("showNotification"),
std::string("showInformation")
}

Definition at line 63 of file libhomescreen.hpp.

const std::vector< std::string > LibHomeScreen::event_list
static
Initial value:
{
std::string("showWindow"),
std::string("on_screen_message"),
std::string("on_screen_reply"),
std::string("hideWindow"),
std::string("replyShowWindow"),
std::string("showNotification"),
std::string("showInformation"),
std::string("none")
}

Definition at line 64 of file libhomescreen.hpp.


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