You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include <fstream>
  3. #include <functional>
  4. #include <iostream>
  5. #include <list>
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <sstream>
  10. #include <string>
  11. #include <vector>
  12. #include "xsync_errcode.hpp"
  13. #include "iflytop_xsync_protocol\iflytop_xsync_protocol.h"
  14. namespace xsync {
  15. using namespace std;
  16. class XsyncNetAdd {
  17. public:
  18. XsyncNetAdd(){};
  19. XsyncNetAdd(string ip, uint32_t port) : ip(ip), port(port) {}
  20. string ip;
  21. uint32_t port;
  22. };
  23. class I_XSUDP {
  24. public:
  25. typedef function<void(XsyncNetAdd& from, uint8_t* data, size_t length)> onMessage_t;
  26. public:
  27. /**
  28. * @brief UDP
  29. *
  30. * @param ip localip default 0
  31. * @param localport localport
  32. * @return int
  33. */
  34. virtual xs_error_code_t initialize(string ip, int localport) = 0;
  35. /**
  36. * @brief UDP消息
  37. *
  38. * @param to
  39. * @param data
  40. * @param length
  41. * @return int
  42. * >0 ,
  43. * <0
  44. */
  45. virtual xs_error_code_t sendto(const XsyncNetAdd& to, const char* data, int32_t length, int32_t* sendlength) = 0;
  46. /**
  47. * @brief UDP消息
  48. *
  49. * @param data
  50. * @param length
  51. * @param from
  52. * @return int
  53. * >0 ,
  54. * <0
  55. */
  56. virtual xs_error_code_t receive(char* data, int32_t& length, XsyncNetAdd& from, int overtimems) = 0;
  57. /**
  58. * @brief UDP消息
  59. *
  60. * @param onMessage
  61. * @return xs_error_code_t
  62. */
  63. virtual xs_error_code_t startReceive(onMessage_t onMessage) = 0;
  64. virtual xs_error_code_t stopReceive() = 0;
  65. virtual xs_error_code_t clearRxBuffer() = 0;
  66. virtual ~I_XSUDP() {}
  67. };
  68. class I_XSUDPFactory {
  69. public:
  70. virtual shared_ptr<I_XSUDP> createXSUDP() = 0;
  71. };
  72. } // namespace xsync