IO.Profile.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #pragma once
  2. #include <list>
  3. #include <vector>
  4. #include <chrono>
  5. #include <optional>
  6. #include "String.DString.hpp"
  7. namespace ECOM::IO::Network
  8. {
  9. class Socket;
  10. }
  11. namespace ECOM::Utility::Extension
  12. {
  13. class BSTTreeEx;
  14. }
  15. #ifndef _IO_Profile_EXPORTS
  16. #define _IO_Profile_API _declspec(dllimport)
  17. #else
  18. #define _IO_Profile_API _declspec(dllexport)
  19. #endif
  20. #ifndef _IO_Profile_EXPORTS
  21. #ifdef _WIN64
  22. #ifdef _DEBUG
  23. #pragma comment (lib, "ECOM.IO.Profile64D.lib")
  24. #else
  25. #pragma comment (lib, "ECOM.IO.Profile64.lib")
  26. #endif
  27. #else // X86
  28. #ifdef _DEBUG
  29. #pragma comment (lib, "ECOM.IO.ProfileD.lib")
  30. #else
  31. #pragma comment (lib, "ECOM.IO.Profile.lib")
  32. #endif
  33. #endif
  34. #endif // _IO_Profile_EXPORTS
  35. namespace ECOM::IO::Profile
  36. {
  37. //-----------------------------------------------------------------------------
  38. // BaseProfile
  39. // 基本类
  40. //-----------------------------------------------------------------------------
  41. class _IO_Profile_API BaseProfile
  42. {
  43. public:
  44. BaseProfile (int codec, CV_String & strProfile);
  45. BaseProfile (const BaseProfile & from);
  46. BaseProfile (BaseProfile && from);
  47. virtual ~BaseProfile ();
  48. public:
  49. size_t GetHash () const;
  50. eSTR::DString ToString () const; // return m_strFormattedProfile
  51. eSTR::DString ToJSON () const; // return m_strFormattedJSON
  52. bool IsEnable () const { return m_bEnable; }
  53. protected:
  54. virtual void Parse () {}
  55. protected:
  56. static auto GetDecoder (int codec, const eSTR::DString & str) -> std::optional <ECOM::Utility::Extension::BSTTreeEx>;
  57. protected:
  58. bool m_bEnable = true;
  59. int m_Codec = 0;
  60. eSTR::DString m_strOrgProfile;
  61. eSTR::DString m_strFormattedProfile;
  62. eSTR::DString m_strFormattedJSON;
  63. size_t m_Hash = 0; // = m_strFormattedProfile.Hash ()
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Profile_IP
  67. //-----------------------------------------------------------------------------
  68. class _IO_Profile_API Profile_IP : public BaseProfile
  69. {
  70. using base = BaseProfile;
  71. public:
  72. Profile_IP (int codec, CV_String & strProfile);
  73. public:
  74. virtual ~Profile_IP ();
  75. Profile_IP (Profile_IP && from);
  76. Profile_IP (const Profile_IP & from);
  77. Profile_IP & operator = (Profile_IP && from);
  78. Profile_IP & operator = (const Profile_IP & from);
  79. public:
  80. auto NewSocket () const ->std::unique_ptr <ECOM::IO::Network::Socket>;
  81. protected:
  82. void Parse () override;
  83. private:
  84. void DoParse ();
  85. eSTR::DString Reformat ();
  86. eSTR::DString FormatToJson ();
  87. public:
  88. eSTR::DString GetIP () const { return m_IPAddress; }
  89. int GetPort () const { return m_Port; }
  90. bool IsTcpNoDelay () const { return m_bTcpNoDelay; }
  91. bool IsSSL () const { return m_bSSL; }
  92. bool IsIPv6 () const { return m_bIPv6; }
  93. void SetPort (int Port);
  94. void SetTcpNoDelay (bool bSet);
  95. std::chrono::seconds GetKeepAlive () const; // m_secKeepAlive
  96. protected:
  97. eSTR::DString m_IPAddress; /// 默认是连到本地
  98. int m_Port = 0;
  99. bool m_bSSL = false;
  100. bool m_bIPv6 = false;
  101. bool m_bUDP = false;
  102. bool m_bTcpNoDelay = false;
  103. int m_secKeepAlive; // 保活时间, 单位是秒. 初始值来自配置文件. Pool.Socket 中的保活函数最终引用的就是这个值.
  104. eSTR::DString m_Reserved;
  105. public:
  106. static Profile_IP From (int codec, const eSTR::DString Profile);
  107. };
  108. //-----------------------------------------------------------------------------
  109. // Profile_NamedPipe
  110. //-----------------------------------------------------------------------------
  111. class _IO_Profile_API Profile_NamedPipe : public BaseProfile
  112. {
  113. using base = BaseProfile;
  114. public:
  115. Profile_NamedPipe (int codec, CV_String & strProfile);
  116. public:
  117. virtual ~Profile_NamedPipe ();
  118. Profile_NamedPipe (Profile_NamedPipe && from);
  119. Profile_NamedPipe (const Profile_NamedPipe & from);
  120. Profile_NamedPipe & operator = (Profile_NamedPipe && from);
  121. Profile_NamedPipe & operator = (const Profile_NamedPipe & from);
  122. protected:
  123. void Parse () override;
  124. private:
  125. void DoParse ();
  126. eSTR::DString Reformat ();
  127. eSTR::DString FormatToJson ();
  128. public:
  129. eSTR::DString GetName () const;
  130. int GetPort () const;
  131. void SetPort (int Port);
  132. protected:
  133. eSTR::DString m_Name;
  134. int m_Port = 0; // 需考虑多个通道, 创建管道时, 真实的名字是 m_Name + m_Port
  135. eSTR::DString m_Reserved;
  136. public:
  137. static Profile_NamedPipe From (int codec, const eSTR::DString Profile);
  138. };
  139. }