rdbd_service.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_SERVICE_H__
  23. #define __RDBD_SERVICE_H__
  24. #include <rtthread.h>
  25. #include <rdbd.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. ///<summer>
  30. ///default Service id for rdbd service, you can used service id 20-255
  31. ///</summer>
  32. #define RDBD_SERVICE_ID_CONTROL (0U)
  33. #define RDBD_SERVICE_ID_FILE (1U)
  34. #define RDBD_SERVICE_ID_SHELL (2U)
  35. #define RDBD_SERVICE_ID_RTI (3U)
  36. #define RDBD_SERVICE_ID_TCP_DUMP (4U)
  37. #define RDBD_SERVICE_ID_OTA (5U)
  38. #define RDBD_SERVICE_FLAG_NONE 0
  39. #define RDBD_SERVICE_FLAG_RD 1
  40. #define RDBD_SERVICE_FLAG_WR 2
  41. enum rdbd_service_status
  42. {
  43. RDBD_SERVICE_STATUS_RUNNING = 1,
  44. RDBD_SERVICE_STATUS_STOP = 2,
  45. RDBD_SERVICE_STATUS_SUSPENDED = 3
  46. };
  47. struct rdbd_service_control_ops
  48. {
  49. int (*start)(void * args);
  50. int (*stop)(void * args);
  51. int (* resume)(void * args);
  52. int (* suspend)(void * args);
  53. };
  54. struct rdbd_request_write
  55. {
  56. rt_list_t list;
  57. struct rdbd_msg * msg;
  58. int msg_pos;
  59. };
  60. struct rdbd_service
  61. {
  62. rt_list_t list;
  63. char * name;
  64. rdbd_t rdbd;
  65. int status;
  66. char * in_pipe_path;
  67. char * out_pipe_path;
  68. int in_pipe_read_fd;
  69. int in_pipe_write_fd;
  70. int out_pipe_read_fd;
  71. int out_pipe_write_fd;
  72. rt_thread_t service_thread;
  73. struct rdbd_service_control_ops * control_ops;
  74. void * user_data;
  75. struct rdbd_msg * msg;
  76. int msg_pos;
  77. rt_list_t request_write_list;
  78. rt_uint8_t service_id;
  79. rt_uint8_t flag;
  80. };
  81. extern struct rdbd_service * rdbd_create_service(rt_uint8_t service_id,
  82. const char * name,
  83. struct rdbd_service_control_ops * control_ops,
  84. void * user_data,
  85. const char * in_pipe_name,
  86. rt_uint32_t in_buf_size,
  87. const char * out_pipe_name,
  88. rt_uint32_t out_buf_size,
  89. rt_uint8_t flag);
  90. extern int rdbd_service_request_write(struct rdbd_service * service, struct rdbd_msg * msg);
  91. extern int rdbd_service_request_delete(struct rdbd_request_write * request);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif