rdbd.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2018, Real-Thread Information Technology Ltd
  3. * All rights reserved
  4. *
  5. * This software is dual-licensed: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation. For the terms of this
  8. * license, see <http://www.gnu.org/licenses/>.
  9. *
  10. * You are free to use this software under the terms of the GNU General
  11. * Public License, but WITHOUT ANY WARRANTY; without even the implied
  12. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * Alternatively, you can license this software under a commercial
  16. * license, please send mail to business@rt-thread.com for contact.
  17. *
  18. * Change Logs:
  19. * Date Author Notes
  20. * 2018-09-25 ZYH the first version
  21. */
  22. #ifndef __RDBD_H__
  23. #define __RDBD_H__
  24. #include <rtthread.h>
  25. #include <rtdevice.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #define RDBD_STATUS_CONNECTED (1)
  30. #define RDBD_STATUS_DISCONNECTED (0)
  31. typedef struct rdbd_msg * rdbd_msg_t;
  32. typedef struct rdbd * rdbd_t;
  33. struct rdbd_header
  34. {
  35. rt_uint8_t source;
  36. rt_uint32_t msg_len : 24;
  37. };
  38. struct rdbd_msg
  39. {
  40. struct rdbd_header header;
  41. rt_uint8_t msg[RT_UINT16_MAX];
  42. };
  43. struct rdbd_transfer_ops
  44. {
  45. int (* read)(void * buffer, size_t size, void (* callback)(void * context, int size), void * context);
  46. int (* write)(const void * buffer, size_t size,void (* callback)(void * context, int size), void * context);
  47. };
  48. struct rdbd
  49. {
  50. rt_list_t list;
  51. int status;
  52. char * name;
  53. struct rdbd_transfer_ops * private_transfer_ops;
  54. rt_list_t service_list;
  55. };
  56. extern rdbd_t rdbd_find(const char * rdbd_name);
  57. extern int rdbd_register_transfer_ops(rdbd_t rdbd, struct rdbd_transfer_ops * ops);
  58. extern rdbd_t rdbd_create(const char * rdbd_name);
  59. extern int rdbd_delete(rdbd_t rdbd);
  60. extern int rdbd_get_status(rdbd_t rdbd);
  61. #define RDBD_MSG(x) ((rdbd_msg_t)x)
  62. #define RDBD_RAW_MSG(x) ((char *)x)
  63. #define RDBD_MSG_LEN(x) (RDBD_MSG(x)->header.msg_len + sizeof(struct rdbd_header))
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif