1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #ifndef _IOTX_CM_INTERNAL_H_
6 #define _IOTX_CM_INTERNAL_H_
7 
8 #include <string.h>
9 
10 #include "linkkit/infra/infra_config.h"
11 #include "linkkit/infra/infra_types.h"
12 #include "linkkit/infra/infra_defs.h"
13 #include "linkkit/infra/infra_list.h"
14 #include "linkkit/infra/infra_compat.h"
15 #include "linkkit/infra/infra_timer.h"
16 
17 #include "linkkit/wrappers/wrappers.h"
18 #include "linkkit/mqtt_api.h"
19 
20 #include "iotx_cm.h"
21 
22 #ifdef INFRA_MEM_STATS
23 #include "linkkit/infra/infra_mem_stats.h"
24 #define cm_malloc(size) LITE_malloc(size, MEM_MAGIC, "cm")
25 #define cm_free(ptr)    LITE_free(ptr)
26 #else
27 #define cm_malloc(size) HAL_Malloc(size)
28 #define cm_free(ptr)           \
29     {                          \
30         HAL_Free((void *)ptr); \
31         ptr = NULL;            \
32     }
33 #endif
34 
35 #ifdef INFRA_LOG
36 #include "linkkit/infra/infra_log.h"
37 #define cm_debug(...)   log_debug("CM", __VA_ARGS__)
38 #define cm_info(...)    log_info("CM", __VA_ARGS__)
39 #define cm_warning(...) log_warning("CM", __VA_ARGS__)
40 #define cm_err(...)     log_err("CM", __VA_ARGS__)
41 #else
42 #define cm_debug(...)            \
43     do {                         \
44         HAL_Printf(__VA_ARGS__); \
45         HAL_Printf("\r\n");      \
46     } while (0)
47 #define cm_info(...)             \
48     do {                         \
49         HAL_Printf(__VA_ARGS__); \
50         HAL_Printf("\r\n");      \
51     } while (0)
52 #define cm_warning(...)          \
53     do {                         \
54         HAL_Printf(__VA_ARGS__); \
55         HAL_Printf("\r\n");      \
56     } while (0)
57 #define cm_err(...)              \
58     do {                         \
59         HAL_Printf(__VA_ARGS__); \
60         HAL_Printf("\r\n");      \
61     } while (0)
62 #endif
63 
64 typedef int (*iotx_cm_connect_fp)(uint32_t timeout);
65 typedef int (*iotx_cm_yield_fp)(unsigned int timeout);
66 typedef int (*iotx_cm_sub_fp)(iotx_cm_ext_params_t *params, const char *topic,
67                               iotx_cm_data_handle_cb topic_handle_func,
68                               void *pcontext);
69 typedef int (*iotx_cm_unsub_fp)(const char *topic);
70 typedef int (*iotx_cm_pub_fp)(iotx_cm_ext_params_t *params, const char *topic,
71                               const char *payload, unsigned int payload_len);
72 typedef int (*iotx_cm_close_fp)();
73 
74 typedef struct iotx_connection_st {
75     int fd;
76     void *open_params;
77     void *context;
78     void *list_lock;
79     iotx_cm_protocol_types_t protocol_type;
80     iotx_cm_connect_fp connect_func;
81     iotx_cm_sub_fp sub_func;
82     iotx_cm_unsub_fp unsub_func;
83     iotx_cm_pub_fp pub_func;
84     iotx_cm_yield_fp yield_func;
85     iotx_cm_close_fp close_func;
86     iotx_cm_event_handle_cb event_handler;
87     void *cb_data;
88 
89 } iotx_cm_connection_t;
90 
91 #include "iotx_cm_mqtt.h"
92 
93 extern const char ERR_INVALID_PARAMS[];
94 #endif /* _LINKKIT_CM_H_ */
95