dm_internal.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C) 2012-2019 UCloud. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #ifndef C_SDK_DM_INTERNAL_H_
  16. #define C_SDK_DM_INTERNAL_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include "uiot_export_dm.h"
  21. typedef struct {
  22. void *ch_signal;
  23. } DM_Struct_t;
  24. typedef struct {
  25. int dm_type;
  26. char *upstream_topic_template;
  27. char *downstream_topic_template;
  28. OnMessageHandler callback;
  29. } DM_MQTT_CB_t;
  30. typedef struct {
  31. void *mqtt;
  32. const char *product_sn;
  33. const char *device_sn;
  34. void *callbacks[DM_TYPE_MAX];
  35. char *upstream_topic_templates[DM_TYPE_MAX];
  36. char *downstream_topic_templates[DM_TYPE_MAX];
  37. void *context;
  38. } DM_MQTT_Struct_t;
  39. #define DEFINE_DM_CALLBACK(type, cb_type) int uiot_register_for_##type(void *handle, cb_type cb) { \
  40. if (type < 0 || type >= sizeof(g_dm_mqtt_cb)/sizeof(DM_MQTT_CB_t)) {return -1;} \
  41. _dsc_mqtt_register_callback((DM_MQTT_Struct_t *)(((DM_Struct_t *)handle)->ch_signal), type, (void *)cb);return 0;}
  42. void dm_mqtt_property_restore_cb(void *pClient, MQTTMessage *message, void *pContext);
  43. void dm_mqtt_property_post_cb(void *pClient, MQTTMessage *message, void *pContext);
  44. void dm_mqtt_property_set_cb(void *pClient, MQTTMessage *message, void *pContext);
  45. void dm_mqtt_property_desired_get_cb(void *pClient, MQTTMessage *message, void *pContext);
  46. void dm_mqtt_property_desired_delete_cb(void *pClient, MQTTMessage *message, void *pContext);
  47. void dm_mqtt_event_post_cb(void *pClient, MQTTMessage *message, void *pContext);
  48. void dm_mqtt_command_cb(void *pClient, MQTTMessage *message, void *pContext);
  49. void *dsc_init(const char *product_sn, const char *device_sn, void *channel, void *context);
  50. int dsc_deinit(void *handle);
  51. int dm_gen_properties_payload(DM_Property_t *property, int property_num, DM_Type type, bool value_key, char *properties_payload);
  52. int dm_mqtt_property_report_publish(DM_MQTT_Struct_t *handle, DM_Type type, int request_id, const char *payload);
  53. int dm_mqtt_property_report_publish_Ex(DM_MQTT_Struct_t *handle, DM_Type type, int request_id, DM_Property_t *property, int property_num);
  54. int dm_mqtt_event_publish(DM_MQTT_Struct_t *handle, int request_id, const char *identifier, const char *payload);
  55. int dm_mqtt_event_publish_Ex(DM_MQTT_Struct_t *handle, int request_id, DM_Event_t *event);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif //C_SDK_DM_INTERNAL_H_