1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #ifndef _DM_MANAGER_H_
6 #define _DM_MANAGER_H_
7 
8 #include "iotx_dm_internal.h"
9 
10 typedef struct {
11     int devid;
12     int dev_type;
13 #if defined(DEPRECATED_LINKKIT)
14     dm_shw_t *dev_shadow;
15     iotx_dm_tsl_source_t tsl_source;
16 #endif
17     char product_key[IOTX_PRODUCT_KEY_LEN + 1];
18     char product_secret[IOTX_PRODUCT_SECRET_LEN + 1];
19     char device_name[IOTX_DEVICE_NAME_LEN + 1];
20     char device_secret[IOTX_DEVICE_SECRET_LEN + 1];
21     iotx_dm_dev_avail_t status;
22     iotx_dm_dev_status_t dev_status;
23     struct list_head linked_list;
24 } dm_mgr_dev_node_t;
25 
26 typedef struct {
27     void *mutex;
28     int global_devid;
29     struct list_head dev_list;
30 } dm_mgr_ctx;
31 
32 int dm_mgr_init(void);
33 int dm_mgr_deinit(void);
34 int dm_mgr_device_query(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1],
35                         _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1],
36                         _OU_ int *devid);
37 int dm_mgr_device_create(_IN_ int dev_type,
38                          _IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1],
39                          _IN_ char product_secret[IOTX_PRODUCT_SECRET_LEN + 1],
40                          _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1],
41                          _IN_ char device_secret[IOTX_DEVICE_SECRET_LEN + 1],
42                          _OU_ int *devid);
43 int dm_mgr_device_destroy(_IN_ int devid);
44 int dm_mgr_device_number(void);
45 int dm_mgr_get_devid_by_index(_IN_ int index, _OU_ int *devid);
46 int dm_mgr_get_next_devid(_IN_ int devid, _OU_ int *devid_next);
47 int dm_mgr_search_device_by_devid(
48     _IN_ int devid, _OU_ char product_key[IOTX_PRODUCT_KEY_LEN + 1],
49     _OU_ char device_name[IOTX_DEVICE_NAME_LEN + 1],
50     _OU_ char device_secret[IOTX_DEVICE_SECRET_LEN + 1]);
51 int dm_mgr_search_device_by_pkdn(
52     _IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1],
53     _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1], _OU_ int *devid);
54 int dm_mgr_search_device_node_by_devid(_IN_ int devid, _OU_ void **node);
55 
56 int dm_mgr_get_dev_type(_IN_ int devid, _OU_ int *dev_type);
57 int dm_mgr_set_dev_enable(_IN_ int devid);
58 int dm_mgr_set_dev_disable(_IN_ int devid);
59 int dm_mgr_get_dev_avail(_IN_ char product_key[IOTX_PRODUCT_KEY_LEN + 1],
60                          _IN_ char device_name[IOTX_DEVICE_NAME_LEN + 1],
61                          _OU_ iotx_dm_dev_avail_t *status);
62 int dm_mgr_set_dev_status(_IN_ int devid, _IN_ iotx_dm_dev_status_t status);
63 int dm_mgr_get_dev_status(_IN_ int devid, _OU_ iotx_dm_dev_status_t *status);
64 int dm_mgr_set_device_secret(
65     _IN_ int devid, _IN_ char device_secret[IOTX_DEVICE_SECRET_LEN + 1]);
66 int dm_mgr_dev_initialized(int devid);
67 int dm_mgr_upstream_thing_property_desired_get(_IN_ int devid,
68                                                _IN_ char *payload,
69                                                _IN_ int payload_len);
70 int dm_mgr_upstream_thing_property_desired_delete(_IN_ int devid,
71                                                   _IN_ char *payload,
72                                                   _IN_ int payload_len);
73 
74 #ifdef DEVICE_MODEL_GATEWAY
75 int dm_mgr_upstream_thing_sub_register(_IN_ int devid);
76 int dm_mgr_upstream_thing_proxy_product_register(_IN_ int devid);
77 int dm_mgr_upstream_thing_sub_unregister(_IN_ int devid);
78 int dm_mgr_upstream_thing_topo_add(_IN_ int devid);
79 int dm_mgr_upstream_thing_topo_delete(_IN_ int devid);
80 int dm_mgr_upstream_thing_topo_get(void);
81 int dm_mgr_upstream_thing_list_found(_IN_ int devid);
82 int dm_mgr_upstream_combine_login(_IN_ int devid);
83 int dm_mgr_upstream_combine_logout(_IN_ int devid);
84 #endif
85 int dm_mgr_upstream_thing_model_up_raw(_IN_ int devid, _IN_ char *payload,
86                                        _IN_ int payload_len);
87 #if !defined(DEVICE_MODEL_RAWDATA_SOLO)
88 int dm_mgr_upstream_thing_property_post(_IN_ int devid, _IN_ char *payload,
89                                         _IN_ int payload_len);
90 #ifdef LOG_REPORT_TO_CLOUD
91 int dm_mgr_upstream_thing_log_post(_IN_ int devid, _IN_ char *payload,
92                                    _IN_ int payload_len, int force_update);
93 #endif
94 int dm_mgr_upstream_thing_event_post(_IN_ int devid, _IN_ char *identifier,
95                                      _IN_ int identifier_len, _IN_ char *method,
96                                      _IN_ char *payload, _IN_ int payload_len);
97 int dm_mgr_upstream_thing_deviceinfo_update(_IN_ int devid, _IN_ char *payload,
98                                             _IN_ int payload_len);
99 int dm_mgr_upstream_thing_deviceinfo_delete(_IN_ int devid, _IN_ char *payload,
100                                             _IN_ int payload_len);
101 int dm_mgr_upstream_thing_dsltemplate_get(_IN_ int devid);
102 int dm_mgr_upstream_thing_dynamictsl_get(_IN_ int devid);
103 int dm_mgr_upstream_ntp_request(void);
104 int dm_mgr_upstream_thing_service_response(_IN_ int devid, _IN_ char *msgid,
105                                            _IN_ int msgid_len,
106                                            _IN_ iotx_dm_error_code_t code,
107                                            _IN_ char *identifier,
108                                            _IN_ int identifier_len,
109                                            _IN_ char *payload,
110                                            _IN_ int payload_len, void *ctx);
111 int dm_mgr_upstream_thing_property_get_response(
112     _IN_ int devid, _IN_ char *msgid, _IN_ int msgid_len,
113     _IN_ iotx_dm_error_code_t code, _IN_ char *payload, _IN_ int payload_len,
114     _IN_ void *ctx);
115 int dm_mgr_upstream_rrpc_response(_IN_ int devid, _IN_ char *msgid,
116                                   _IN_ int msgid_len,
117                                   _IN_ iotx_dm_error_code_t code,
118                                   _IN_ char *rrpcid, _IN_ int rrpcid_len,
119                                   _IN_ char *payload, _IN_ int payload_len);
120 #ifdef DEVICE_MODEL_SUBDEV_OTA
121 int dm_mgr_upstream_thing_firmware_version_update(_IN_ int devid,
122                                                   _IN_ char *payload,
123                                                   _IN_ int payload_len);
124 #endif
125 #endif
126 #ifdef DEPRECATED_LINKKIT
127 int dm_mgr_deprecated_set_tsl_source(_IN_ int devid,
128                                      _IN_ iotx_dm_tsl_source_t tsl_source);
129 int dm_mgr_deprecated_get_tsl_source(_IN_ int devid,
130                                      _IN_ iotx_dm_tsl_source_t *tsl_source);
131 int dm_mgr_deprecated_search_devid_by_device_node(_IN_ void *node,
132                                                   _OU_ int *devid);
133 int dm_mgr_deprecated_set_tsl(int devid, iotx_dm_tsl_type_t tsl_type,
134                               const char *tsl, int tsl_len);
135 int dm_mgr_deprecated_get_property_data(_IN_ int devid, _IN_ char *key,
136                                         _IN_ int key_len, _OU_ void **data);
137 int dm_mgr_deprecated_get_service_input_data(_IN_ int devid, _IN_ char *key,
138                                              _IN_ int key_len,
139                                              _OU_ void **data);
140 int dm_mgr_deprecated_get_service_output_data(_IN_ int devid, _IN_ char *key,
141                                               _IN_ int key_len,
142                                               _OU_ void **data);
143 int dm_mgr_deprecated_get_event_output_data(_IN_ int devid, _IN_ char *key,
144                                             _IN_ int key_len, _OU_ void **data);
145 int dm_mgr_deprecated_get_data_type(_IN_ void *property,
146                                     _OU_ dm_shw_data_type_e *type);
147 int dm_mgr_deprecated_get_property_number(_IN_ int devid, _OU_ int *number);
148 int dm_mgr_deprecated_get_service_number(_IN_ int devid, _OU_ int *number);
149 int dm_mgr_deprecated_get_event_number(_IN_ int devid, _OU_ int *number);
150 int dm_mgr_deprecated_get_property_by_index(_IN_ int devid, _IN_ int index,
151                                             _OU_ void **property);
152 int dm_mgr_deprecated_get_service_by_index(_IN_ int devid, _IN_ int index,
153                                            _OU_ void **service);
154 int dm_mgr_deprecated_get_event_by_index(_IN_ int devid, _IN_ int index,
155                                          _OU_ void **event);
156 int dm_mgr_deprecated_get_service_by_identifier(_IN_ int devid,
157                                                 _IN_ char *identifier,
158                                                 _OU_ void **service);
159 int dm_mgr_deprecated_get_event_by_identifier(_IN_ int devid,
160                                               _IN_ char *identifier,
161                                               _OU_ void **event);
162 int dm_mgr_deprecated_get_property_identifier(_IN_ void *property,
163                                               _OU_ char **identifier);
164 int dm_mgr_deprecated_get_service_method(_IN_ void *service,
165                                          _OU_ char **method);
166 int dm_mgr_deprecated_get_event_method(_IN_ void *event, _OU_ char **method);
167 int dm_mgr_deprecated_set_property_value(_IN_ int devid, _IN_ char *key,
168                                          _IN_ int key_len, _IN_ void *value,
169                                          _IN_ int value_len);
170 int dm_mgr_deprecated_get_property_value(_IN_ int devid, _IN_ char *key,
171                                          _IN_ int key_len, _IN_ void *value);
172 int dm_mgr_deprecated_set_event_output_value(_IN_ int devid, _IN_ char *key,
173                                              _IN_ int key_len, _IN_ void *value,
174                                              _IN_ int value_len);
175 int dm_mgr_deprecated_get_event_output_value(_IN_ int devid, _IN_ char *key,
176                                              _IN_ int key_len,
177                                              _IN_ void *value);
178 int dm_mgr_deprecated_set_service_input_value(_IN_ int devid, _IN_ char *key,
179                                               _IN_ int key_len,
180                                               _IN_ void *value,
181                                               _IN_ int value_len);
182 int dm_mgr_deprecated_get_service_input_value(_IN_ int devid, _IN_ char *key,
183                                               _IN_ int key_len,
184                                               _IN_ void *value);
185 int dm_mgr_deprecated_set_service_output_value(_IN_ int devid, _IN_ char *key,
186                                                _IN_ int key_len,
187                                                _IN_ void *value,
188                                                _IN_ int value_len);
189 int dm_mgr_deprecated_get_service_output_value(_IN_ int devid, _IN_ char *key,
190                                                _IN_ int key_len,
191                                                _IN_ void *value);
192 int dm_mgr_deprecated_assemble_property(_IN_ int devid, _IN_ char *identifier,
193                                         _IN_ int identifier_len,
194                                         _IN_ lite_cjson_item_t *lite);
195 int dm_mgr_deprecated_assemble_event_output(_IN_ int devid,
196                                             _IN_ char *identifier,
197                                             _IN_ int identifier_len,
198                                             _IN_ lite_cjson_item_t *lite);
199 int dm_mgr_deprecated_assemble_service_output(_IN_ int devid,
200                                               _IN_ char *identifier,
201                                               _IN_ int identifier_len,
202                                               _IN_ lite_cjson_item_t *lite);
203 int dm_mgr_deprecated_upstream_thing_service_response(
204     _IN_ int devid, _IN_ int msgid, _IN_ iotx_dm_error_code_t code,
205     _IN_ char *identifier, _IN_ int identifier_len, _IN_ char *payload,
206     _IN_ int payload_len);
207 #endif
208 #endif
209