#pragma once #include #include #include #include #include "String.DString.hpp" #include "IO.Profile.hpp" #include "IO.Profile.BUS.Define.hpp" namespace ECOM::IO { class Link; } namespace ECOM::ServiceBus::Controller { namespace Role { class Sender; class Receiver; } } namespace ECOM::IO::Profile { namespace ServiceBus { DWORD constexpr WireVersion_510 = 0x0510; DWORD constexpr WireVersion_801 = 0x0801; } } namespace ECOM::IO::Profile::ServiceBus::Detail { using IOLink = ECOM::IO::Link; //----------------------------------------------------------------------------- // Manager //----------------------------------------------------------------------------- class _IO_Profile_BUS_API Manager { Manager () = delete; public: static void OpenLogger (); static void Prepare (); static void Quit (); public: using tfnCallback = std::function link)>; static void SetKeepWarm (tfnCallback fun); }; } //----------------------------------------------------------------------------- // Send::Profile 和 Receive::Profile 都无需继承自 Profile_IP // 因为 Create_Profile () 函数体中, 才创建 Profile_IP // //----------------------------------------------------------------------------- namespace ECOM::IO::Profile::ServiceBus::Detail { namespace Send { //----------------------------------------------------------------------------- // Send::Profile //----------------------------------------------------------------------------- class _IO_Profile_BUS_API Profile : public BaseProfile { using base = BaseProfile; protected: // 传入的 strProfile 中, 如果指定了端口号, 必须是 Sender 的端口号 (比如 6630) Profile (int codec, CV_String & strProfile); public: virtual ~Profile (); Profile (Profile && from) = delete; Profile (const Profile & from) = delete; Profile & operator = (Profile && from) = delete; Profile & operator = (const Profile & from) = delete; protected: void Parse () override; private: void DoParse (); void Create_Profile (); private: eSTR::DString m_IPAddress; eSTR::DString m_NamedPipe; // 命名管道的名字 int m_CommandPort = 0; int m_NbOfChannel = 4; int m_NbOfRetry = 4; mutable DWORD m_WireVersion = 0; bool m_bPool = true; bool m_bTcpNoDelay = false; using tTimeOut = std::chrono::milliseconds; tTimeOut m_TimeOut; std::vector > m_arProfile_IP; std::vector > m_arProfile_Pipe; private: auto GetNext_IP () const->std::shared_ptr ; auto GetNext_Pipe () const->std::shared_ptr ; public: bool IsTcpNoDelay () const; void SetTcpNoDelay (bool bSet); DWORD GetWireVersion () const; const Profile & SetWireVersion (DWORD version) const; public: auto GetProvider () const -> std::unique_ptr ; public: eSTR::DString GetIP () const; // 返回 IP 地址 eSTR::DString GetNamedPipe () const; // 返回命名管道名称 // 如果 strProfile 中未指定, 就返回 0. 注意单位 ! auto GetTimeOut () const->std::chrono::milliseconds; public: // 返回值一定非空 // 传入的 strProfile 中, 如果指定了端口号, 必须是 Sender 的端口号 (比如 6630) static auto From (int codec, CV_String strProfile) -> std::unique_ptr ; static auto FromIPv4 (CV_String IP, int Port = 0) -> std::unique_ptr ; static auto FromIPv6 (CV_String IP, int Port = 0) -> std::unique_ptr ; static auto FromPort (int Port) -> std::unique_ptr ; static auto Default () -> std::unique_ptr ; }; } namespace Receive { //----------------------------------------------------------------------------- // Receive::Profile //----------------------------------------------------------------------------- class _IO_Profile_BUS_API Profile : public BaseProfile { using base = BaseProfile; protected: // 传入的 strProfile 中, 如果指定了端口号, 必须是 Receiver 的端口号 (比如 6631) Profile (int codec, CV_String & strProfile); public: virtual ~Profile (); public: auto GetProvider () const -> std::list < std::unique_ptr >; public: // 返回一个简单的 Link, 用于 SetUniqueSourceID 等功能. 一般是连接到第一个通道. auto EasyLink () -> std::unique_ptr ; public: eSTR::DString GetIP () const; eSTR::DString GetNamedPipe () const; // 返回命名管道名称 // 如果 strProfile 中未指定, 就返回 0. 注意单位 ! auto GetHeartbeat () const -> std::chrono::milliseconds; public: auto ToProfileOfSend () const -> std::unique_ptr ; // 返回 Send::Profile protected: void Parse () override; private: void DoParse (); protected: eSTR::DString m_IPAddress; int m_NbOfChannel = 4; int m_StatusPort = 0; std::chrono::milliseconds m_Heartbeat; public: // 返回值一定非空 // 传入的 strProfile 中, 如果指定了端口号, 必须是 Receiver 的端口号 (比如 6631) static auto From (int codec, CV_String strProfile) -> std::unique_ptr ; static auto FromIPv4 (CV_String IP, int Port = 0) -> std::unique_ptr ; static auto FromIPv6 (CV_String IP, int Port = 0) -> std::unique_ptr ; static auto FromPort (int Port) -> std::unique_ptr ; static auto Default () -> std::unique_ptr ; }; } } //----------------------------------------------------------------------------- // AccessControl::Profile & AccessControl::AccessToken //----------------------------------------------------------------------------- namespace ECOM::IO::Profile::ServiceBus::Detail { namespace AccessControl { class _IO_Profile_BUS_API Passport { class Password { union HASH64 { static constexpr auto NbOf8 = 8; static constexpr auto NbOf32 = 2; static constexpr auto NbOf64 = 1; BYTE Hash8 [NbOf8]; // LOWLOW, LOW, HIGH, HIGHHIGH DWORD Hash32 [NbOf32]; // LOW, HIGH UINT64 Hash64; HASH64 (CV_String str); }; union SHA256 { static constexpr auto NbOf8 = 32; static constexpr auto NbOf32 = 8; static constexpr auto NbOf64 = 4; BYTE Hash8 [NbOf8]; DWORD Hash32 [NbOf32]; UINT64 Hash64 [NbOf64]; SHA256 (CV_String str); }; union SHA512 { static constexpr auto NbOf8 = 32 * 2; static constexpr auto NbOf32 = 8 * 2; static constexpr auto NbOf64 = 4 * 2; BYTE Hash8 [NbOf8]; DWORD Hash32 [NbOf32]; UINT64 Hash64 [NbOf64]; SHA512 (CV_String str); }; std::unique_ptr m_Hash64; std::unique_ptr m_SHA256; std::unique_ptr m_SHA512; public: const HASH64 * GetHash64 () const { return m_Hash64.get (); }; const SHA256 * GetSHA256 () const { return m_SHA256.get (); }; const SHA512 * GetSHA512 () const { return m_SHA512.get (); }; friend class Profile; }; // password private: eSTR::DString m_UserName; Password m_Password; friend class Profile; public: const eSTR::DString & GetUser () const { return m_UserName; } const Password & GetPassword () const { return m_Password; } }; //----------------------------------------------------------------------------- // AccessControl::Profile //----------------------------------------------------------------------------- class _IO_Profile_BUS_API Profile : public BaseProfile { using base = BaseProfile; protected: Profile (int codec, CV_String & strProfile); public: virtual ~Profile (); Profile (Profile && from) = delete; Profile (const Profile & from) = delete; Profile & operator = (Profile && from) = delete; Profile & operator = (const Profile & from) = delete; public: auto GetPassport () const { return m_Passport; } protected: void Parse () override; private: void DoParse (); private: std::shared_ptr m_Passport; public: // 返回值一定非空 static auto From (int codec, CV_String strProfile) -> std::unique_ptr ; public: // 返回值一定非空 static auto LoadFile (int codec, CV_String FileName, CV_String encKey) -> std::unique_ptr ; // 返回: 写入的字节数 static int RenewACL (int codec, CV_String FileName, CV_String encKey); }; } } //namespace IOPBUS = ECOM::IO::Profile::ServiceBus;