1 /* 2 * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 */ 4 5 #ifndef LINKKIT_EXPORT_H 6 #define LINKKIT_EXPORT_H 7 8 #ifdef __cplusplus 9 extern "C" { 10 #endif /* __cplusplus */ 11 12 #include <stdint.h> 13 14 typedef void (*handle_post_cb_fp_t)(const void *thing_id, int respons_id, 15 int code, const char *response_message, 16 void *ctx); 17 typedef void (*handle_subdev_cb_fp_t)(const void *thing_id, int code, 18 const char *response_message, int success, 19 void *ctx); 20 21 typedef struct _linkkit_ops { 22 #ifdef LOCAL_CONN_ENABLE 23 int (*on_connect)( 24 void *ctx, 25 int cloud); /* true: cloud connection; false: local connection */ 26 int (*on_disconnect)( 27 void *ctx, 28 int cloud); /* true: cloud connection; false: local connection */ 29 #else 30 int (*on_connect)( 31 void *ctx); /* true: cloud connection; false: local connection */ 32 int (*on_disconnect)( 33 void *ctx); /* true: cloud connection; false: local connection */ 34 #endif 35 int (*raw_data_arrived)(const void *thing_id, const void *data, int len, 36 void *ctx); 37 int (*thing_create)(const void *thing_id, void *ctx); 38 int (*thing_enable)(const void *thing_id, void *ctx); 39 int (*thing_disable)(const void *thing_id, void *ctx); 40 int (*thing_call_service)(const void *thing_id, const char *service, 41 int request_id, void *ctx); 42 int (*thing_prop_changed)(const void *thing_id, const char *property, 43 void *ctx); 44 int (*linkit_data_arrived)(const void *thing_id, const void *data, int len, 45 void *ctx); 46 } linkkit_ops_t; 47 48 typedef enum _linkkit_loglevel { 49 linkkit_loglevel_emerg = 0, 50 linkkit_loglevel_crit, 51 linkkit_loglevel_error, 52 linkkit_loglevel_warning, 53 linkkit_loglevel_info, 54 linkkit_loglevel_debug, 55 } linkkit_loglevel_t; 56 57 /* domain type */ 58 /* please sync with dm_cloud_domain_type_t */ 59 typedef enum { 60 /* shanghai */ 61 linkkit_cloud_domain_shanghai, 62 /* singapore */ 63 linkkit_cloud_domain_singapore, 64 /* japan */ 65 linkkit_cloud_domain_japan, 66 /* america */ 67 linkkit_cloud_domain_america, 68 /* germany */ 69 linkkit_cloud_domain_germany, 70 71 linkkit_cloud_domain_max, 72 } linkkit_cloud_domain_type_t; 73 74 /* device info related operation */ 75 typedef enum { 76 linkkit_extended_info_operate_update, 77 linkkit_extended_info_operate_delete, 78 79 linkkit_deviceinfo_operate_max, 80 } linkkit_extended_info_operate_t; 81 82 /** 83 * @brief dispatch message of queue for further process. 84 * 85 * @return void* 86 */ 87 void *linkkit_dispatch(void); 88 89 typedef enum { 90 linkkit_opt_property_post_reply, /* data type: int */ 91 linkkit_opt_event_post_reply, /* data type: int */ 92 linkkit_opt_property_set_reply /* data type: int */ 93 } linkkit_opt_t; 94 95 /** 96 * @brief get leave signal. 97 * 98 * 99 * @return int,0 no leave signal, 1 get a leave signal 100 */ 101 int being_deprecated linkkit_is_try_leave(); 102 103 /** 104 * @brief start linkkit routines, and install callback funstions(async type for 105 * cloud connecting). 106 * 107 * @param opt, specify the option need to be set. 108 * @param data, specify the option value. 109 * 110 * @return int, 0 when success, -1 when fail. 111 */ 112 int being_deprecated linkkit_set_opt(linkkit_opt_t opt, void *data); 113 114 /** 115 * @brief start linkkit routines, and install callback funstions(async type for 116 * cloud connecting). 117 * 118 * @param max_buffered_msg, specify max buffered message size. 119 * @param ops, callback function struct to be installed. 120 * @param get_tsl_from_cloud, config if device need to get tsl from cloud(!0) or 121 * local(0), if local selected, must invoke linkkit_set_tsl to tell tsl to dm 122 * after start complete. 123 * @param log_level, config log level. 124 * @param user_context, user context pointer. 125 * @param domain_type, specify the could server domain. 126 * 127 * @return int, 0 when success, -1 when fail. 128 */ 129 int being_deprecated linkkit_start(int max_buffered_msg, int get_tsl_from_cloud, 130 linkkit_loglevel_t log_level, 131 linkkit_ops_t *ops, 132 linkkit_cloud_domain_type_t domain_type, 133 void *user_context); 134 135 /** 136 * @brief stop linkkit routines. 137 * 138 * 139 * @return 0 when success, -1 when fail. 140 */ 141 int being_deprecated linkkit_end(void); 142 143 /** 144 * @brief install user tsl. 145 * 146 * @param tsl, tsl string that contains json description for thing object. 147 * @param tsl_len, tsl string length. 148 * 149 * @return pointer to thing object, NULL when fails. 150 */ 151 void *linkkit_set_tsl(const char *tsl, int tsl_len); 152 153 /* patterns: */ 154 /* method: 155 * set_property_/event_output_/service_output_value: 156 * method_set, thing_id, identifier, value */ 157 158 typedef enum { 159 linkkit_method_set_property_value = 0, 160 linkkit_method_set_event_output_value, 161 linkkit_method_set_service_output_value, 162 163 linkkit_method_set_number, 164 } linkkit_method_set_t; 165 166 /** 167 * @brief set value to property, event output, service output items. 168 * if identifier is struct type or service output type or event output 169 * type, use '.' as delimeter like "identifier1.ientifier2" to point to specific 170 * item. value and value_str could not be NULL at the same time; if value and 171 * value_str both as not NULL, value shall be used and value_str will be 172 * ignored. if value is NULL, value_str not NULL, value_str will be used. in 173 * brief, value will be used if not NULL, value_str will be used only if value 174 * is NULL. 175 * 176 * @param method_set, specify set value type. 177 * @param thing_id, pointer to thing object, specify which thing to set. 178 * @param identifier, property, event output, service output identifier. 179 * @param value. The value to be set, data type decided by data type of property 180 * as follows: int: int*, float: float*, double: double*, text: char*, enum: 181 * int*, date: char*, bool: int* 182 * 183 * @param value_str, value to set in string format if value is null. 184 * 185 * @return 0 when success, -1 when fail. 186 */ 187 int being_deprecated linkkit_set_value(linkkit_method_set_t method_set, 188 const void *thing_id, 189 const char *identifier, 190 const void *value, 191 const char *value_str); 192 193 typedef enum { 194 linkkit_method_get_property_value = 0, 195 linkkit_method_get_event_output_value, 196 linkkit_method_get_service_input_value, 197 linkkit_method_get_service_output_value, 198 199 linkkit_method_get_number, 200 } linkkit_method_get_t; 201 202 /** 203 * @brief get value from property, event output, service input/output items. 204 * if identifier is struct type or service input/output type or event 205 * output type, use '.' as delimeter like "identifier1.ientifier2" to point to 206 * specific item. value and value_str could not be NULL at the same time; if 207 * value and value_str both as not NULL, value shall be used and value_str will 208 * be ignored. if value is NULL, value_str not NULL, value_str will be used. in 209 * brief, value will be used if not NULL, value_str will be used only if value 210 * is NULL. 211 * @param method_get, specify get value type. 212 * @param thing_id, pointer to thing object, specify which thing to get. 213 * @param identifier, property, event output, service input/output identifier. 214 * @param value. The variable to store value, data type decided by data type of 215 * property as follows: int: int*, float: float*, double: double*, text: char**, 216 * enum: int*, date: char**, bool: int* 217 * 218 * @param value_str, value to get in string format. If success, memory of 219 * *value_str will be allocated, user should free the memory. 220 * 221 * @warning if data type is text or date, *value well be end with '\0'. 222 * the memory allocated to *value must be free by user. 223 * 224 * @return 0 when success, -1 when fail. 225 */ 226 int being_deprecated linkkit_get_value(linkkit_method_get_t method_get, 227 const void *thing_id, 228 const char *identifier, void *value, 229 char **value_str); 230 231 /** 232 * @brief answer to a service when a service requested by cloud. 233 * 234 * @param thing_id, pointer to thing object. 235 * @param service_identifier, service identifier to answer, user should get this 236 * identifier from handle_dm_callback_fp_t type callback report that 237 * "dm_callback_type_service_requested" happened, use this function to generate 238 * response to the service sender. 239 * @param response_id, id value in response payload. its value is from 240 * "dm_callback_type_service_requested" type callback function. use the same id 241 * as the request to send response as the same communication session. 242 * @param code, code value in response payload. for example, 200 when service 243 * successfully executed, 400 when not successfully executed. 244 * 245 * @return 0 when success, -1 when fail. 246 */ 247 int being_deprecated linkkit_answer_service(const void *thing_id, 248 const char *service_identifier, 249 int response_id, int code); 250 251 /** 252 * @brief answer a down raw service when a raw service requested by cloud, or 253 * invoke a up raw service to cloud. 254 * 255 * @param thing_id, pointer to thing object. 256 * @param is_up_raw, specify up raw(not 0) or down raw reply(0). 257 * @param raw_data, raw data that sent to cloud. 258 * @param raw_data_length, raw data length that sent to cloud. 259 * 260 * @return 0 when success, -1 when fail. 261 */ 262 int being_deprecated linkkit_invoke_raw_service(const void *thing_id, 263 int is_up_raw, void *raw_data, 264 int raw_data_length); 265 266 /** 267 * @brief trigger extended info update procedure. 268 * 269 * @param thing_id, pointer to thing object. 270 * @param params, json type string that user to send to cloud. 271 * @param linkkit_extended_info_operation, specify update type or delete type. 272 * 273 * @return 0 when success, -1 when fail. 274 */ 275 276 int being_deprecated linkkit_trigger_extended_info_operate( 277 const void *thing_id, const char *params, 278 linkkit_extended_info_operate_t linkkit_extended_info_operation); 279 280 /** 281 * @brief trigger a event to post to cloud. 282 * 283 * @param thing_id, pointer to thing object. 284 * @param event_identifier, event identifier to trigger. 285 * @param cb, callback function of event post. 286 * 287 * @return >=0 when success, -1 when fail. 288 */ 289 int being_deprecated linkkit_trigger_event(const void *thing_id, 290 const char *event_identifier, 291 handle_post_cb_fp_t cb); 292 293 /** 294 * @brief post property to cloud. 295 * 296 * @param thing_id, pointer to thing object. 297 * @param property_identifier, used when trigger event with method 298 * "event.property.post", if set, post specified property, if NULL, post all. 299 * @param cb, callback function of property post. 300 * 301 * @return >=0 when success, -1 when fail. 302 */ 303 int being_deprecated linkkit_post_property(const void *thing_id, 304 const char *property_identifier, 305 handle_post_cb_fp_t cb); 306 307 /** 308 * @brief this function used to yield when want to receive or send data. 309 * if multi-thread enabled, user should NOT call this function. 310 * 311 * @param timeout_ms, timeout value in ms. 312 * 313 * @return 0 when success, -1 when fail. 314 */ 315 int being_deprecated linkkit_yield(int timeout_ms); 316 317 typedef enum { 318 service_cota_callback_type_new_version_detected = 10, 319 320 service_cota_callback_type_number, 321 } service_cota_callback_type_t; 322 323 typedef void (*handle_service_cota_callback_fp_t)( 324 service_cota_callback_type_t callback_type, const char *configid, 325 uint32_t configsize, const char *gettype, const char *sign, 326 const char *signmethod, const char *cota_url); 327 328 /** 329 * @brief this function used to register callback for config ota. 330 * 331 * @param callback_fp, user callback which register to cota. 332 * 333 * @return 0 when success, -1 when fail. 334 */ 335 int being_deprecated 336 linkkit_cota_init(handle_service_cota_callback_fp_t callback_fp); 337 338 /** 339 * @brief this function used to execute cota process. 340 * 341 * @param data_buf, data buf that used to do ota. ota service will use this 342 * buffer to download bin. 343 * @param data_buf_length, data buf length that used to do ota. 344 * 345 * @return 0 when success, -1 when fail. 346 */ 347 int being_deprecated linkkit_invoke_cota_service(void *data_buf, 348 int data_buf_length); 349 350 /** 351 * @brief this function used to trigger cota process. 352 * 353 * @param config_scope, remote config scope, should be "product". 354 * @param get_type, remote config file type, should be "file". 355 * @param attribute_Keys, reserved. 356 * @param option, reserved. 357 * @return 0 when success, -1 when fail. 358 */ 359 int being_deprecated linkkit_invoke_cota_get_config(const char *config_scope, 360 const char *get_type, 361 const char *attribute_Keys, 362 void *option); 363 364 typedef enum { 365 service_fota_callback_type_new_version_detected = 10, 366 367 service_fota_callback_type_number, 368 } service_fota_callback_type_t; 369 370 typedef void (*handle_service_fota_callback_fp_t)( 371 service_fota_callback_type_t callback_type, const char *version); 372 373 /** 374 * @brief this function used to register callback for firmware ota. 375 * 376 * @param callback_fp, user callback which register to fota. 377 * 378 * @return 0 when success, -1 when fail. 379 */ 380 int being_deprecated 381 linkkit_fota_init(handle_service_fota_callback_fp_t callback_fp); 382 383 /** 384 * @brief this function used to execute fota process. 385 * 386 * @param data_buf, data buf that used to do ota. ota service will use this 387 * buffer to download bin. 388 * @param data_buf_length, data buf length that used to do ota. 389 * 390 * @return 0 when success, -1 when fail. 391 */ 392 int being_deprecated linkkit_invoke_fota_service(void *data_buf, 393 int data_buf_length); 394 395 /** 396 * @brief this function used to get NTP time from cloud. 397 * 398 * @param ntp_reply_cb, user callback which register to ntp request. 399 * when cloud returns ntp reply, sdk would trigger the 400 * callback function 401 * 402 * @return 0 when success, -1 when fail. 403 */ 404 int being_deprecated 405 linkkit_ntp_time_request(void (*ntp_reply_cb)(const char *ntp_offset_time_ms)); 406 407 #ifdef __cplusplus 408 } 409 #endif /* __cplusplus */ 410 411 #endif /* LINKKIT_EXPORT_H */ 412