123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #pragma once
- #include "DelegateArg.hpp"
- #include "WString.hpp"
- #ifndef _DELEGATEARG_DLL
- #define DELEGATEARG_API _declspec(dllimport)
- #else
- #define DELEGATEARG_API _declspec(dllexport)
- #endif
- #pragma warning (disable : 4275)
- //-----------------------------------------------------------------------------
- // A general DelegateArg of BUSMessage
- //-----------------------------------------------------------------------------
- class DELEGATEARG_API EventArgs_BUSMessage : public DelegateArgs
- {
- typedef DelegateArgs inherited;
- DECLARE_RTTI (EventArgs_BUSMessage)
- public:
- inline EventArgs_BUSMessage (DWORD Command, DString SourceID, DString TargetID, DString Message, WString WMessage, DWORD MsgID)
- {
- m_SourceID = SourceID;
- m_TargetID = TargetID;
- m_Message = Message;
- m_WMessage = WMessage;
- m_Command = Command;
- m_ErrorCode = 0; // 0 -- 没有错误
- m_MessageID = MsgID;
- }
- inline EventArgs_BUSMessage (const EventArgs_BUSMessage & From)
- {
- m_SourceID = From.m_SourceID;
- m_TargetID = From.m_TargetID;
- m_Message = From.m_Message;
- m_WMessage = From.m_WMessage;
- m_Command = From.m_Command;
- m_ErrorCode = 0; // 0 -- 没有错误
- m_MessageID = From.m_MessageID;
- }
- public:
- template <typename T> T MsgAs () const { }
- template <> DString MsgAs () const { if (m_Message.GetLength () > 0) return m_Message; return m_WMessage.ToDString (); }
- template <> WString MsgAs () const { if (m_WMessage.GetLength () > 0) return m_WMessage; return WString (m_Message); }
- template <typename T> T AckAs () const { }
- template <> DString AckAs () const { if (m_AckMessage.GetLength () > 0) return m_AckMessage; return m_WAckMessage.ToDString (); }
- template <> WString AckAs () const { if (m_WAckMessage.GetLength () > 0) return m_WAckMessage; return WString (m_AckMessage); }
- template <typename T> T & GetAck () { }
- template <> DString & GetAck () { return m_AckMessage; }
- template <> WString & GetAck () { return m_WAckMessage; }
- void SetAck (DString & ACK) { m_AckMessage = ACK; }
- void SetAck (WString & ACK) { m_WAckMessage = ACK; }
- // 强制修改 Message
- // 目前在 CSBUSClient 中使用
- void ForceSetMessage (DString & Msg)
- {
- if (m_Message.GetLength () > 0)
- m_Message = Msg;
- else
- m_WMessage = Msg;
- }
- void ForceSetMessage (WString & Msg)
- {
- if (m_WMessage.GetLength () > 0)
- m_WMessage = Msg;
- else
- m_Message = Msg.ToDString ();
- }
- public:
- DString m_SourceID;
- DString m_TargetID;
- DWORD m_Command;
- DWORD m_ErrorCode; // 由被调用者赋值, 表示错误代号
- DWORD m_MessageID; // 来自总线内部的 MessageID, 用于跟踪
- protected:
- DString m_Message;
- DString m_AckMessage;
- WString m_WMessage;
- WString m_WAckMessage;
- };
- //-----------------------------------------------------------------------------
- // A general DelegateArg of BUSBLOB
- //-----------------------------------------------------------------------------
- #include "TmplBlockBuffer.tlh"
- #include "TmplBlockBuffer.tli"
- class DELEGATEARG_API EventArgs_BUSBLOB : public EventArgs_BUSMessage
- {
- typedef EventArgs_BUSMessage inherited;
- DECLARE_RTTI (EventArgs_BUSBLOB)
- public:
- inline EventArgs_BUSBLOB (DWORD Command, DString SourceID, DString TargetID, DString Message, WString WMessage, DWORD MsgID, BlockBuffer BLOB)
- : EventArgs_BUSMessage (Command, SourceID, TargetID, Message, WMessage, MsgID)
- {
- m_BLOB = BLOB;
- }
- public:
- BlockBuffer m_BLOB;
- BlockBuffer m_AckBLOB;
- };
|