HomeScreenBinding
Macros | Typedefs | Enumerations | Functions | Variables
hs-helper.h File Reference
#include <afb/afb-binding.h>
#include <json-c/json.h>

Go to the source code of this file.

Macros

#define AFB_BINDING_VERSION   3
 
#define AFB_EVENT_BAD_REQUEST   100
 
#define AFB_REQ_SUBSCRIBE_ERROR   101
 
#define AFB_REQ_UNSUBSCRIBE_ERROR   102
 
#define AFB_REQ_SHOWNOTIFICATION_ERROR   103
 
#define AFB_REQ_SHOWINFORMATION_ERROR   104
 

Typedefs

typedef enum REQ_ERROR REQ_ERROR
 

Enumerations

enum  REQ_ERROR { REQ_FAIL = -1, REQ_OK =0, NOT_NUMBER, OUT_RANGE }
 

Functions

REQ_ERROR get_value_uint16 (const afb_req_t request, const char *source, uint16_t *out_id)
 
REQ_ERROR get_value_int16 (const afb_req_t request, const char *source, int16_t *out_id)
 
REQ_ERROR get_value_int32 (const afb_req_t request, const char *source, int32_t *out_id)
 
void hs_add_object_to_json_object (struct json_object *j_obj, int count,...)
 
void hs_add_object_to_json_object_str (struct json_object *j_obj, int count,...)
 
void hs_add_object_to_json_object_func (struct json_object *j_obj, const char *verb_name, int count,...)
 
int hs_search_event_name_index (const char *value)
 

Variables

const char * evlist []
 
const char _error []
 
const char _application_id []
 
const char _display_message []
 
const char _reply_message []
 

Macro Definition Documentation

#define AFB_BINDING_VERSION   3

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

#define AFB_EVENT_BAD_REQUEST   100

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

#define AFB_REQ_SHOWINFORMATION_ERROR   104

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

#define AFB_REQ_SHOWNOTIFICATION_ERROR   103

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

#define AFB_REQ_SUBSCRIBE_ERROR   101

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

#define AFB_REQ_UNSUBSCRIBE_ERROR   102

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

Typedef Documentation

typedef enum REQ_ERROR REQ_ERROR

Enumeration Type Documentation

enum REQ_ERROR
Enumerator
REQ_FAIL 
REQ_OK 
NOT_NUMBER 
OUT_RANGE 

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

30 {
31  REQ_FAIL = -1,
32  REQ_OK=0,
33  NOT_NUMBER,
34  OUT_RANGE
35 }REQ_ERROR;
REQ_ERROR
Definition: hs-helper.h:29

Function Documentation

REQ_ERROR get_value_int16 ( const afb_req_t  request,
const char *  source,
int16_t *  out_id 
)

get int16 value from source

Parameters

  • request : Describes the request by bindings from afb-daemon
  • source : input source
  • out_id : output int16 value

Return

error code

Definition at line 82 of file hs-helper.cpp.

83 {
84  char* endptr;
85  const char* tmp = afb_req_value (request, source);
86  if(!tmp)
87  {
88  return REQ_FAIL;
89  }
90  long tmp_id = strtol(tmp,&endptr,10);
91 
92  /* error check of range */
93  if( (tmp_id > INT16_MAX) || (tmp_id < INT16_MIN) )
94  {
95  return OUT_RANGE;
96  }
97  if(*endptr != '\0')
98  {
99  return NOT_NUMBER;
100  }
101 
102  *out_id = (int16_t)tmp_id;
103  return REQ_OK;
104 }
REQ_ERROR get_value_int32 ( const afb_req_t  request,
const char *  source,
int32_t *  out_id 
)

get int32 value from source

Parameters

  • request : Describes the request by bindings from afb-daemon
  • source : input source
  • out_id : output int32 value

Return

error code

Definition at line 118 of file hs-helper.cpp.

119 {
120  char* endptr;
121  const char* tmp = afb_req_value (request, source);
122  if(!tmp)
123  {
124  return REQ_FAIL;
125  }
126  long tmp_id = strtol(tmp,&endptr,10);
127 
128  /* error check of range */
129  if( (tmp_id > INT32_MAX) || (tmp_id < INT32_MIN) )
130  {
131  return OUT_RANGE;
132  }
133  if(*endptr != '\0')
134  {
135  return NOT_NUMBER;
136  }
137 
138  *out_id = (int32_t)tmp_id;
139  return REQ_OK;
140 }
REQ_ERROR get_value_uint16 ( const afb_req_t  request,
const char *  source,
uint16_t *  out_id 
)

get uint16 value from source

Parameters

  • request : Describes the request by bindings from afb-daemon
  • source : input source
  • out_id : output uint16 value

Return

error code

Definition at line 46 of file hs-helper.cpp.

47 {
48  char* endptr;
49  const char* tmp = afb_req_value (request, source);
50  if(!tmp)
51  {
52  return REQ_FAIL;
53  }
54  long tmp_id = strtol(tmp,&endptr,10);
55 
56  /* error check of range */
57  if( (tmp_id > UINT16_MAX) || (tmp_id < 0) )
58  {
59  return OUT_RANGE;
60  }
61  if(*endptr != '\0')
62  {
63  return NOT_NUMBER;
64  }
65 
66  *out_id = (uint16_t)tmp_id;
67  return REQ_OK;
68 }
void hs_add_object_to_json_object ( struct json_object *  j_obj,
int  count,
  ... 
)

add int object to json object

Parameters

  • j_obj : the json object will join in int json object
  • count : input parameter number
  • ... : parameter list

Return

None

Definition at line 154 of file hs-helper.cpp.

155 {
156  va_list args;
157  va_start(args, count);
158  for(int i = 0; i < count; ++i )
159  {
160  char *key = va_arg(args, char*);
161  int value = va_arg(args, int);
162  json_object_object_add(j_obj, key, json_object_new_int((int32_t)value));
163  ++i;
164  }
165  va_end(args);
166 }
void hs_add_object_to_json_object_func ( struct json_object *  j_obj,
const char *  verb_name,
int  count,
  ... 
)

add new json object to json object

Parameters

  • j_obj : the json object will join in new json object
  • verb_name : new json object's verb value
  • count : input parameter number
  • ... : parameter list

Return

None

Definition at line 207 of file hs-helper.cpp.

208 {
209  va_list args;
210  va_start(args, count);
211 
212  json_object_object_add(j_obj,"verb", json_object_new_string(verb_name));
213 
214  for(int i = 0; i < count; ++i )
215  {
216  char *key = va_arg(args, char*);
217  int value = va_arg(args, int);
218  json_object_object_add(j_obj, key, json_object_new_int((int32_t)value));
219  ++i;
220  }
221  va_end(args);
222 }
void hs_add_object_to_json_object_str ( struct json_object *  j_obj,
int  count,
  ... 
)

add string object to json object

Parameters

  • j_obj : the json object will join in string json object
  • count : input parameter number
  • ... : parameter list

Return

None

Definition at line 180 of file hs-helper.cpp.

181 {
182  va_list args;
183  va_start(args, count);
184  for(int i = 0; i < count; ++i )
185  {
186  char *key = va_arg(args, char*);
187  char *value = va_arg(args, char*);
188  json_object_object_add(j_obj, key, json_object_new_string(value));
189  ++i;
190  }
191  va_end(args);
192 }
int hs_search_event_name_index ( const char *  value)

search event position in event list

Parameters

  • value : searched event name

Return

event's index in event list

Definition at line 234 of file hs-helper.cpp.

235 {
236  size_t buf_size = 50;
237  size_t size = sizeof evlist / sizeof *evlist;
238  int ret = -1;
239  for(size_t i = 0 ; i < size ; ++i)
240  {
241  if(!strncmp(value, evlist[i], buf_size))
242  {
243  ret = i;
244  break;
245  }
246  }
247  return ret;
248 }
const char * evlist[]
Definition: hs-helper.cpp:22

Variable Documentation

const char _application_id[]

Definition at line 28 of file homescreen.cpp.

const char _display_message[]

Definition at line 29 of file homescreen.cpp.

const char _error[]

Definition at line 27 of file homescreen.cpp.

const char _reply_message[]

Definition at line 30 of file homescreen.cpp.

const char* evlist[]

Definition at line 22 of file hs-helper.cpp.