Kii Thing SDK Embedded
 All Classes Files Functions Variables Typedefs
kii.h
Go to the documentation of this file.
1 
5 #ifndef KII_H
6 #define KII_H
7 
8 #include "kii_core.h"
9 #include "kii_task_callback.h"
10 
11 #include <kii_json.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #define KII_OBJECTID_SIZE 36
18 
19 #define KII_UPLOADID_SIZE 64
20 
21 #ifdef DEBUG
22 #ifndef __FILE__
23 #define __FILE__ ("__FILE__ macro is not available")
24 #endif
25 
26 #ifndef __LINE__
27 #define __LINE__ (-1)
28 #endif
29 
30 #define M_KII_LOG(x) \
31  if (kii->kii_core.logger_cb != NULL) {\
32  kii->kii_core.logger_cb("file:%s, line:%d ", __FILE__, __LINE__); \
33  (x); \
34  }
35 #else
36 #define M_KII_LOG(x)
37 #endif
38 
39 #define KII_TASK_NAME_RECV_MSG "recv_msg_task"
40 #ifdef KII_PUSH_KEEP_ALIVE_INTERVAL_SECONDS
41 #define KII_TASK_NAME_PING_REQ "ping_req_task"
42 #endif
43 
44 struct kii_t;
45 
46 typedef void (*KII_PUSH_RECEIVED_CB)(
47  struct kii_t* kii,
48  char* message,
49  size_t message_length);
50 
51 typedef struct kii_t {
52  kii_core_t kii_core;
53 
65  kii_socket_context_t mqtt_socket_context;
66  KII_SOCKET_CONNECT_CB mqtt_socket_connect_cb;
67  KII_SOCKET_SEND_CB mqtt_socket_send_cb;
68  KII_SOCKET_RECV_CB mqtt_socket_recv_cb;
69  KII_SOCKET_CLOSE_CB mqtt_socket_close_cb;
70 
71  KII_TASK_CREATE task_create_cb;
72 
73  KII_DELAY_MS delay_ms_cb;
74 
75  KII_PUSH_RECEIVED_CB push_received_cb;
76 
77  int _mqtt_connected;
78 
79  char* mqtt_buffer;
80  size_t mqtt_buffer_size;
81 
82  void* app_context;
83 
102  kii_json_resource_t kii_json_resource;
103 
110  KII_JSON_RESOURCE_CB kii_json_resource_cb;
111 
112 } kii_t;
113 
122 int kii_init(
123  kii_t* kii,
124  const char* site,
125  const char* app_id,
126  const char* app_key);
127 
137  kii_t* kii,
138  const char* vendor_thing_id,
139  const char* password);
140 
151  kii_t* kii,
152  const char* vendor_thing_id,
153  const char* thing_type,
154  const char* password);
155 
169  kii_t* kii,
170  const char* thing_id,
171  const char* thing_state,
172  const size_t content_length,
173  const char* content_type,
174  const char* content_encoding,
175  const char* normalizer_host);
176 
190  kii_t* kii,
191  const char* thing_id,
192  const char* thing_state,
193  const size_t content_length,
194  const char* content_type,
195  const char* content_encoding,
196  const char* normalizer_host);
197 
211  kii_t* kii,
212  const kii_bucket_t* bucket,
213  const char* object_data,
214  const char* object_content_type,
215  char* out_object_id);
216 
227  kii_t* kii,
228  const kii_bucket_t* bucket,
229  const char* object_id,
230  const char* object_data,
231  const char* object_content_type);
232 
244 int kii_object_patch(
245  kii_t* kii,
246  const kii_bucket_t* bucket,
247  const char* object_id,
248  const char* patch_data,
249  const char* opt_etag);
250 
264  kii_t* kii,
265  const kii_bucket_t* bucket,
266  const char* object_id,
267  const char* replacement_data,
268  const char* opt_etag);
269 
277  kii_t* kii,
278  const kii_bucket_t* bucket,
279  const char* object_id);
280 
288 int kii_object_get(
289  kii_t* kii,
290  const kii_bucket_t* bucket,
291  const char* object_id);
292 
306  kii_t* kii,
307  const kii_bucket_t* bucket,
308  const char* object_id,
309  const char* body_content_type,
310  const void* data,
311  size_t data_length);
312 
323  kii_t* kii,
324  const kii_bucket_t* bucket,
325  const char* object_id,
326  char* out_upload_id);
327 
329 typedef struct kii_chunk_data_t {
333  size_t position;
335  size_t length;
337  size_t total_length;
339  void* chunk;
341 
353  kii_t* kii,
354  const kii_bucket_t* bucket,
355  const char* object_id,
356  const char* upload_id,
357  const kii_chunk_data_t* chunk);
358 
373  kii_t* kii,
374  const kii_bucket_t* bucket,
375  const char* object_id,
376  const char* upload_id,
377  unsigned int commit);
378 
390  kii_t* kii,
391  const kii_bucket_t* bucket,
392  const char* object_id,
393  unsigned int* out_data_length);
394 
413  kii_t* kii,
414  const kii_bucket_t* bucket,
415  const char* object_id,
416  unsigned int position,
417  unsigned int length,
418  unsigned int* out_actual_length,
419  unsigned int* out_total_length);
420 
429  kii_t* kii,
430  const kii_bucket_t* bucket);
431 
438  kii_t* kii,
439  const kii_bucket_t* bucket);
440 
449  kii_t* kii,
450  const kii_topic_t* topic);
451 
458  kii_t* kii,
459  const kii_topic_t* topic);
460 
467  kii_t* kii,
468  const kii_topic_t* topic);
469 
476  kii_t* kii,
477  const kii_topic_t* topic);
478 
487  kii_t* kii,
488  KII_PUSH_RECEIVED_CB callback);
489 
497  kii_t* kii,
498  const char* endpoint_name,
499  const char* params);
500 
518  kii_t* kii,
519  const char* http_method,
520  const char* resource_path,
521  const char* content_type,
522  kii_bool_t set_authentication_header);
523 
537  kii_t* kii,
538  const void* body_data,
539  size_t body_size);
540 
553 int
555  kii_t* kii,
556  const char* key,
557  const char* value);
558 
576 int kii_api_call_run(kii_t* kii);
577 
578 #ifdef __cplusplus
579 }
580 #endif
581 
582 #endif
583 /* vim:set ts=4 sts=4 sw=4 et fenc=UTF-8 ff=unix: */
584 
int kii_api_call_run(kii_t *kii)
Definition: kii_call.c:31
int kii_thing_authenticate(kii_t *kii, const char *vendor_thing_id, const char *password)
Definition: kii_thing.c:34
int kii_push_start_routine(kii_t *kii, KII_PUSH_RECEIVED_CB callback)
Definition: kii_push.c:541
int kii_object_replace(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, const char *replacement_data, const char *opt_etag)
Definition: kii_object.c:143
int kii_push_subscribe_bucket(kii_t *kii, const kii_bucket_t *bucket)
Definition: kii_push.c:167
int kii_thing_upload_state(kii_t *kii, const char *thing_id, const char *thing_state, const size_t content_length, const char *content_type, const char *content_encoding, const char *normalizer_host)
Definition: kii_thing.c:155
int kii_object_get(kii_t *kii, const kii_bucket_t *bucket, const char *object_id)
Definition: kii_object.c:212
size_t total_length
Definition: kii.h:337
kii_socket_context_t mqtt_socket_context
Definition: kii.h:65
Definition: kii.h:51
size_t position
Definition: kii.h:333
int kii_api_call_append_body(kii_t *kii, const void *body_data, size_t body_size)
Definition: kii_call.c:16
int kii_object_upload_body(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, const char *upload_id, const kii_chunk_data_t *chunk)
Definition: kii_object.c:366
int kii_object_create_with_id(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, const char *object_data, const char *object_content_type)
Definition: kii_object.c:68
int kii_api_call_append_header(kii_t *kii, const char *key, const char *value)
Definition: kii_call.c:25
int kii_object_create(kii_t *kii, const kii_bucket_t *bucket, const char *object_data, const char *object_content_type, char *out_object_id)
Definition: kii_object.c:10
int kii_object_upload_body_at_once(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, const char *body_content_type, const void *data, size_t data_length)
Definition: kii_object.c:243
int kii_api_call_start(kii_t *kii, const char *http_method, const char *resource_path, const char *content_type, kii_bool_t set_authentication_header)
Definition: kii_call.c:5
Definition: kii.h:329
struct kii_chunk_data_t kii_chunk_data_t
kii_json_resource_t kii_json_resource
Definition: kii.h:102
int kii_push_delete_topic(kii_t *kii, const kii_topic_t *topic)
Definition: kii_push.c:291
size_t length
Definition: kii.h:335
int kii_push_unsubscribe_bucket(kii_t *kii, const kii_bucket_t *bucket)
Definition: kii_push.c:192
int kii_object_delete(kii_t *kii, const kii_bucket_t *bucket, const char *object_id)
Definition: kii_object.c:180
int kii_push_unsubscribe_topic(kii_t *kii, const kii_topic_t *topic)
Definition: kii_push.c:242
int kii_push_create_topic(kii_t *kii, const kii_topic_t *topic)
Definition: kii_push.c:267
int kii_init(kii_t *kii, const char *site, const char *app_id, const char *app_key)
Definition: kii_thing.c:25
int kii_thing_register(kii_t *kii, const char *vendor_thing_id, const char *thing_type, const char *password)
Definition: kii_thing.c:94
int kii_object_download_body_at_once(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, unsigned int *out_data_length)
Definition: kii_object.c:492
int kii_object_patch(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, const char *patch_data, const char *opt_etag)
Definition: kii_object.c:106
void * chunk
Definition: kii.h:339
int kii_push_subscribe_topic(kii_t *kii, const kii_topic_t *topic)
Definition: kii_push.c:218
int kii_object_commit_upload(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, const char *upload_id, unsigned int commit)
Definition: kii_object.c:432
KII_JSON_RESOURCE_CB kii_json_resource_cb
Definition: kii.h:110
int kii_object_download_body(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, unsigned int position, unsigned int length, unsigned int *out_actual_length, unsigned int *out_total_length)
Definition: kii_object.c:545
int kii_thing_patch_state(kii_t *kii, const char *thing_id, const char *thing_state, const size_t content_length, const char *content_type, const char *content_encoding, const char *normalizer_host)
Definition: kii_thing.c:200
int kii_server_code_execute(kii_t *kii, const char *endpoint_name, const char *params)
Definition: kii_server_code.c:9
int kii_object_init_upload_body(kii_t *kii, const kii_bucket_t *bucket, const char *object_id, char *out_upload_id)
Definition: kii_object.c:294
char * body_content_type
Definition: kii.h:331