123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #pragma once
- #include <list>
- #include <vector>
- #include <chrono>
- #include <optional>
- #include "String.DString.hpp"
- namespace ECOM::IO::Network
- {
- class Socket;
- }
- namespace ECOM::Utility::Extension
- {
- class BSTTreeEx;
- }
- #ifndef _IO_Profile_EXPORTS
- #define _IO_Profile_API _declspec(dllimport)
- #else
- #define _IO_Profile_API _declspec(dllexport)
- #endif
- #ifndef _IO_Profile_EXPORTS
- #ifdef _WIN64
- #ifdef _DEBUG
- #pragma comment (lib, "ECOM.IO.Profile64D.lib")
- #else
- #pragma comment (lib, "ECOM.IO.Profile64.lib")
- #endif
- #else // X86
- #ifdef _DEBUG
- #pragma comment (lib, "ECOM.IO.ProfileD.lib")
- #else
- #pragma comment (lib, "ECOM.IO.Profile.lib")
- #endif
- #endif
- #endif // _IO_Profile_EXPORTS
- namespace ECOM::IO::Profile
- {
- //-----------------------------------------------------------------------------
- // BaseProfile
- // 基本类
- //-----------------------------------------------------------------------------
- class _IO_Profile_API BaseProfile
- {
- public:
- BaseProfile (int codec, CV_String & strProfile);
- BaseProfile (const BaseProfile & from);
- BaseProfile (BaseProfile && from);
- virtual ~BaseProfile ();
- public:
- size_t GetHash () const;
- eSTR::DString ToString () const; // return m_strFormattedProfile
- eSTR::DString ToJSON () const; // return m_strFormattedJSON
- bool IsEnable () const { return m_bEnable; }
- protected:
- virtual void Parse () {}
- protected:
- static auto GetDecoder (int codec, const eSTR::DString & str) -> std::optional <ECOM::Utility::Extension::BSTTreeEx>;
- protected:
- bool m_bEnable = true;
- int m_Codec = 0;
- eSTR::DString m_strOrgProfile;
- eSTR::DString m_strFormattedProfile;
- eSTR::DString m_strFormattedJSON;
- size_t m_Hash = 0; // = m_strFormattedProfile.Hash ()
- };
- //-----------------------------------------------------------------------------
- // Profile_IP
- //-----------------------------------------------------------------------------
- class _IO_Profile_API Profile_IP : public BaseProfile
- {
- using base = BaseProfile;
- public:
- Profile_IP (int codec, CV_String & strProfile);
- public:
- virtual ~Profile_IP ();
- Profile_IP (Profile_IP && from);
- Profile_IP (const Profile_IP & from);
- Profile_IP & operator = (Profile_IP && from);
- Profile_IP & operator = (const Profile_IP & from);
- public:
- auto NewSocket () const ->std::unique_ptr <ECOM::IO::Network::Socket>;
- protected:
- void Parse () override;
- private:
- void DoParse ();
- eSTR::DString Reformat ();
- eSTR::DString FormatToJson ();
- public:
- eSTR::DString GetIP () const { return m_IPAddress; }
- int GetPort () const { return m_Port; }
- bool IsTcpNoDelay () const { return m_bTcpNoDelay; }
- bool IsSSL () const { return m_bSSL; }
- bool IsIPv6 () const { return m_bIPv6; }
- void SetPort (int Port);
- void SetTcpNoDelay (bool bSet);
- std::chrono::seconds GetKeepAlive () const; // m_secKeepAlive
- protected:
- eSTR::DString m_IPAddress; /// 默认是连到本地
- int m_Port = 0;
- bool m_bSSL = false;
- bool m_bIPv6 = false;
- bool m_bUDP = false;
- bool m_bTcpNoDelay = false;
- int m_secKeepAlive; // 保活时间, 单位是秒. 初始值来自配置文件. Pool.Socket 中的保活函数最终引用的就是这个值.
- eSTR::DString m_Reserved;
- public:
- static Profile_IP From (int codec, const eSTR::DString Profile);
- };
- //-----------------------------------------------------------------------------
- // Profile_NamedPipe
- //-----------------------------------------------------------------------------
- class _IO_Profile_API Profile_NamedPipe : public BaseProfile
- {
- using base = BaseProfile;
- public:
- Profile_NamedPipe (int codec, CV_String & strProfile);
- public:
- virtual ~Profile_NamedPipe ();
- Profile_NamedPipe (Profile_NamedPipe && from);
- Profile_NamedPipe (const Profile_NamedPipe & from);
- Profile_NamedPipe & operator = (Profile_NamedPipe && from);
- Profile_NamedPipe & operator = (const Profile_NamedPipe & from);
- protected:
- void Parse () override;
- private:
- void DoParse ();
- eSTR::DString Reformat ();
- eSTR::DString FormatToJson ();
- public:
- eSTR::DString GetName () const;
- int GetPort () const;
- void SetPort (int Port);
- protected:
- eSTR::DString m_Name;
- int m_Port = 0; // 需考虑多个通道, 创建管道时, 真实的名字是 m_Name + m_Port
- eSTR::DString m_Reserved;
- public:
- static Profile_NamedPipe From (int codec, const eSTR::DString Profile);
- };
- }
|