123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- #pragma once
- #include <list>
- #include <vector>
- #include <functional>
- #include <chrono>
- #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 <bool (std::unique_ptr <IOLink> 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 <std::shared_ptr <Profile_IP>> m_arProfile_IP;
- std::vector <std::shared_ptr <Profile_NamedPipe>> m_arProfile_Pipe;
- private:
- auto GetNext_IP () const->std::shared_ptr <Profile_IP>;
- auto GetNext_Pipe () const->std::shared_ptr <Profile_NamedPipe>;
- public:
- bool IsTcpNoDelay () const;
- void SetTcpNoDelay (bool bSet);
- DWORD GetWireVersion () const;
- const Profile & SetWireVersion (DWORD version) const;
- public:
- auto GetProvider () const -> std::unique_ptr <ECOM::ServiceBus::Controller::Role::Sender>;
- 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 <Profile>;
- static auto FromIPv4 (CV_String IP, int Port = 0) -> std::unique_ptr <Profile>;
- static auto FromIPv6 (CV_String IP, int Port = 0) -> std::unique_ptr <Profile>;
- static auto FromPort (int Port) -> std::unique_ptr <Profile>;
- static auto Default () -> std::unique_ptr <Profile>;
- };
- }
- 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 <ECOM::ServiceBus::Controller::Role::Receiver> >;
- public:
- // 返回一个简单的 Link, 用于 SetUniqueSourceID 等功能. 一般是连接到第一个通道.
- auto EasyLink () -> std::unique_ptr <IOLink>;
- 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>; // 返回 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 <Profile>;
- static auto FromIPv4 (CV_String IP, int Port = 0) -> std::unique_ptr <Profile>;
- static auto FromIPv6 (CV_String IP, int Port = 0) -> std::unique_ptr <Profile>;
- static auto FromPort (int Port) -> std::unique_ptr <Profile>;
- static auto Default () -> std::unique_ptr <Profile>;
- };
- }
- }
- //-----------------------------------------------------------------------------
- // 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 <HASH64> m_Hash64;
- std::unique_ptr <SHA256> m_SHA256;
- std::unique_ptr <SHA512> 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 <Passport> m_Passport;
- public:
- // 返回值一定非空
- static auto From (int codec, CV_String strProfile) -> std::unique_ptr <Profile>;
- public:
- // 返回值一定非空
- static auto LoadFile (int codec, CV_String FileName, CV_String encKey) -> std::unique_ptr <Profile>;
- // 返回: 写入的字节数
- static int RenewACL (int codec, CV_String FileName, CV_String encKey);
- };
- }
- }
- //namespace IOPBUS = ECOM::IO::Profile::ServiceBus;
|