server.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * space_server 对外接口通用功能。
  3. *
  4. * © 2020 成都河狸智能科技有限责任公司。保留所有权利。
  5. *
  6. * 作者: zhq1229
  7. */
  8. #ifndef __SERVER_H__
  9. #define __SERVER_H__
  10. #include <space_lib/space_lib.h>
  11. namespace server {
  12. typedef void (*ReadCallback)(Json::Value &data, space::comm::CommMsg &msg);
  13. typedef void (*WritCallback)();
  14. enum CommType {
  15. COMM_NONE = 0,
  16. COMM_WEBSOCKET_SERVER,
  17. COMM_WEBSOCKET_CLIENT,
  18. COMM_TCP_SERVER,
  19. COMM_TCP_CLIENT,
  20. COMM_UDP,
  21. COMM_SERIAL,
  22. };
  23. enum WritType {
  24. WRIT_CALLBACK = 0,
  25. WRIT_JSON,
  26. };
  27. struct Comm {
  28. Comm() :
  29. type(COMM_NONE),
  30. ws_server(nullptr),
  31. ws_client(nullptr),
  32. tcp_server(nullptr),
  33. tcp_client(nullptr),
  34. udp(nullptr),
  35. serial(nullptr) { }
  36. CommType type;
  37. space::comm::WsServer *ws_server;
  38. space::comm::WsClient *ws_client;
  39. space::comm::TcpServer *tcp_server;
  40. space::comm::TcpClient *tcp_client;
  41. space::comm::Udp *udp;
  42. space::comm::Serial *serial;
  43. };
  44. struct Writ {
  45. Writ() :
  46. writ_callback(nullptr),
  47. data(Json::Value()),
  48. cycle(0),
  49. count(0),
  50. read_callback(nullptr),
  51. type(WRIT_CALLBACK) { }
  52. WritCallback writ_callback;
  53. Json::Value data;
  54. unsigned int cycle;
  55. int count;
  56. ReadCallback read_callback;
  57. WritType type;
  58. };
  59. int init(Json::Value &conf);
  60. int shutdown();
  61. } // namespace server
  62. #endif // __SERVER_H__