Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cXProtocol.h
Go to the documentation of this file.
1 //
5 //
6 #ifndef _INC_cXProtocol_H
7 #define _INC_cXProtocol_H 0x1E // This is the version stamp for the XProtocol
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../Proto/cPingClient.h"
13 #include "../Scriptable/IScriptableObj.h"
14 #include "../Scriptable/cScriptableInterface.h"
15 
16 #include "GrayCore/include/cAtom.h"
17 #include "GrayCore/include/cFile.h"
20 
21 #ifdef USE_DEBUG_LOG
22 #define USE_XPROTO_LOGFILE // log to a special file to keep messages isolated from the rest of the logging system
23 #endif
24 
25 namespace GrayLib
26 {
27 #ifdef USE_XPROTO_LOGFILE
28  class cLogAppendFile;
29  typedef cRefPtr<cLogAppendFile> cLogAppendFilePtr;
30 #endif
31 
32  class GRAYLIB_LINK cVariant;
35  class GRAYLIB_LINK cXObject;
36  typedef cRefPtr<cXObject> cXObjectPtr;
37 
39  {
44 
45 #define cXProtocolMsg(a,b,c) XPROTO_##a,
46 #include "cXProtocolMsg.tbl"
47 #undef cXProtocolMsg
48 
50 
51  XPROTO_MASK = 0x0F,
52  XPROTO_Request = 0x10,
53  XPROTO_LastUID = 0x20,
55  XPROTO_HashProp = 0x40,
56  };
57  typedef BYTE XPROTO_t;
58 
60  {
64 
65  public:
67 #ifdef USE_XPROTO_LOGFILE
68  cLogAppendFilePtr m_pLogFile;
69 #endif
70 
71  public:
73  virtual ~cXProtocolDataMgr();
74 
75 #ifdef USE_XPROTO_LOGFILE
76  void SetLogFile(const FILECHAR_t* pszFilePath);
77 #endif
78 
79  virtual cScriptableInterfaceDef* FindInterfaceDef(cXObject* pObj, SCRIPTINTERFACEID_t bInterfaceID);
80  virtual cXObjectPtr FindXObj(UID_t uid, SCRIPTINTERFACEID_t bInterfaceID = SCRIPTINTERFACEID_MAX, cScriptableInterfaceDef** ppInterfaceDef = nullptr);
81  };
82 
84  {
89 
90  public:
91  // General state info.
92  static const size_t k_Packet_Size_Max = cStream::k_FILE_BLOCK_SIZE + 16; // file blocks. Rx buffer must be at least this large.
96 
97  public:
98  cXProtocolBase(cXProtocolDataMgr* pProtocolDataMgr);
99  virtual ~cXProtocolBase();
100 
102  {
103  return this->m_pProtocolDataMgr;
104  }
105 
106  static cStringA GRAYCALL GetMsgName(XPROTO_t bMsg);
107 
108  virtual bool isClientSide() const = 0;
109  STDMETHOD_(cString, get_Name)() const = 0;
110  STDMETHOD_(PLEVEL_TYPE, get_PrivLevel)() const = 0;
111 
112 #ifdef USE_XPROTO_LOGFILE
113  cLogProcessor* get_LogFile() const; // Log internal stuff. Must watch out for feedback.
114 #endif
115 
116  };
117 
119  {
122 
123  friend class cXProtocolServerTx;
124 
125  protected:
132 
133  protected:
134  void InitTx();
135  HRESULT Send_MsgPropName(const ATOMCHAR_t* pszPropName);
136 
138  {
139  ASSERT(m_pStreamTx != nullptr);
140  return *m_pStreamTx;
141  }
142 
143  protected:
144  cXProtocolTx(cXProtocolBase& rBase, cStreamOutput* pStreamTx);
145  virtual ~cXProtocolTx();
146 
147  bool IsTxMsgBuilding() const
148  {
149  // I am building a message or failed to complete a message.
150  return m_bMsgBuilding != XPROTO_NULL;
151  }
152 
153  HRESULT Send_MsgHeader(XPROTO_t bMsg);
154  HRESULT Send_MsgHeaderUID(XPROTO_t bMsg, UID_t uid);
155  void Send_MsgEnd();
156 
157  HRESULT Send_Error(HRESULT hResRet, const cVariant& vVal);
158 
159  HRESULT Send_PropN(UID_t uid, const ATOMCHAR_t* pszPropName, const cVariant& vVal);
160  HRESULT Send_PropN(cXObject* pObj, const ATOMCHAR_t* pszPropName, const cVariant& vValRet);
161  HRESULT Send_PropN(cXObject* pObj, const cScriptableProp* pProp, const cVariant& vValRet);
162 
163  HRESULT Request_InvokeN(UID_t uid, const ATOMCHAR_t* pszPropName, const cVariant& vArgs);
164  HRESULT Request_InvokeN(UID_t uid, const ATOMCHAR_t* pszPropName);
165  HRESULT Request_InvokeN(cXObject* pObj, const ATOMCHAR_t* pszPropName, const cVariant& vArgs);
166  HRESULT Request_InvokeN(cXObject* pObj, const ATOMCHAR_t* pszPropName);
167  HRESULT Request_InvokeN(cXObject* pObj, const cScriptableMethod* pMethod, const cVariant& vArgs);
168 
169  HRESULT Send_FileChecked(const FILECHAR_t* pszSrcPath, const FILECHAR_t* pszDestName);
170  HRESULT Send_File(const FILECHAR_t* pszSrcPath, const FILECHAR_t* pszDestName, FILE_SIZE_t nOffsetStart, FILE_SIZE_t nSize);
171  HRESULT Send_FileNext();
172  };
173 
175  {
178 
179  protected:
184 
189 
190  protected:
191  cXProtocolRx(cXProtocolBase& rBase, cStreamInput* pStreamRx);
192  virtual ~cXProtocolRx();
193 
194  virtual HRESULT onX_Error(HRESULT hResRet, const cVariant& vVal) = 0;
195 
196  virtual HRESULT onXSet_Prop(cXObject* pObj, const cScriptableProp* pProp, const cVariant& vVal);
197  virtual HRESULT onXReq_Invoke(cXObject* pObj, const cScriptableMethod* pMethod, const cVariant& vArgs, OUT cVariant& vValRet);
198 
199  // For simple apps that don't truly enumerate the props and methods. just use the names.
200  virtual HRESULT onXSet_PropN(UID_t uidLastRx, const ATOMCHAR_t* pszPropName, ATOMCODE_t nPropName, const cVariant& vVal);
201  virtual HRESULT onXReq_InvokeN(UID_t uidLastRx, const ATOMCHAR_t* pszMethodName, ATOMCODE_t nMethodName, const cVariant& vArgs);
202 
203  virtual HRESULT onXSet_File(const FILECHAR_t* pszReqName, size_t dwTotalLen);
204 
205  void InitRx();
206  HRESULT ReadUID();
207 
208  HRESULT on_Error();
209  HRESULT onSet_PropN();
210  HRESULT onReq_InvokeN();
211  HRESULT onSet_File();
212  HRESULT onSet_FileNext();
213 
215  {
216  ASSERT(m_pStreamRx != nullptr);
217  return *m_pStreamRx;
218  }
220  virtual HRESULT ProcessStreamPacket();
221  };
222 
223 };
224 #endif // _INC_cXProtocol_H
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cScriptableInterface.h:300
Definition: cScriptableInterface.h:97
Definition: cVariant.h:26
Definition: cXObject.h:78
Definition: cXProtocol.h:84
cFile m_FileWork
The local file we are reading or writing for XPROTO_File.
Definition: cXProtocol.h:95
virtual bool isClientSide() const =0
cXProtocolDataMgr * get_DataMgr() const
Definition: cXProtocol.h:101
STDMETHOD_(cString, get_Name)() const =0
STDMETHOD_(PLEVEL_TYPE, get_PrivLevel)() const =0
cXProtocolDataMgr *const m_pProtocolDataMgr
Point back to the protocol singleton.
Definition: cXProtocol.h:93
bool m_bUseHashPropName
for stuff i send, should i hash the prop names ? XPROTO_HashProp
Definition: cXProtocol.h:94
Definition: cXProtocol.h:60
cStringF m_sFileRootDir
This is the virtual root for this server. XPROTO_File (as the other side is concerned,...
Definition: cXProtocol.h:66
Definition: cXProtocol.h:175
SCRIPTINTERFACEID_t m_bInterfaceIDUnk
An interface received that I don't understand (yet)! client only.
Definition: cXProtocol.h:183
XPROTO_t m_bMsgReadPrev
Last message i got and understood. for debug.
Definition: cXProtocol.h:186
XPROTO_t m_bMsgReading
We are in the process of reading/dispatching a message.
Definition: cXProtocol.h:185
cXProtocolBase & m_rBase
Input stream.
Definition: cXProtocol.h:181
UID_t m_uidLastRx
Last UID sent from client. ( be careful order of messages does not change!)
Definition: cXProtocol.h:188
int m_iMsgNumRx
Count the messages we received.
Definition: cXProtocol.h:187
virtual HRESULT onX_Error(HRESULT hResRet, const cVariant &vVal)=0
cStreamInput * m_pStreamRx
Where to RX from.
Definition: cXProtocol.h:182
virtual HRESULT ProcessStreamRxMsg()=0
cStreamInput & get_StreamRx()
Definition: cXProtocol.h:214
Definition: cXProtocolServer.h:19
Definition: cXProtocol.h:119
bool m_bFileSending
Must call Send_FileNext() until done.
Definition: cXProtocol.h:129
bool IsTxMsgBuilding() const
Definition: cXProtocol.h:147
UID_t m_uidLastTx
Last UID i sent. Periodically resend this just in case the other side gets out of sync ?
Definition: cXProtocol.h:131
int m_iMsgNumTx
Count the messages we transmit.
Definition: cXProtocol.h:130
cStreamOutput & get_StreamTx() const
Definition: cXProtocol.h:137
cXProtocolBase & m_rBase
My parent. dumb pointer.
Definition: cXProtocol.h:126
XPROTO_t m_bMsgBuilding
We are in the process of building a message. not called Send_MsgEnd() yet.
Definition: cXProtocol.h:128
cStreamOutput * m_pStreamTx
Where to TX to.
Definition: cXProtocol.h:127
Definition: cFile.h:137
Definition: cLogAppender.h:168
Definition: cRefPtr.h:225
static const size_t k_FILE_BLOCK_SIZE
default arbitrary transfer block size. more than this is NOT more efficient.
Definition: cStream.h:89
Definition: cStream.h:306
Definition: cStream.h:126
Definition: cMesh.h:22
BYTE XPROTO_t
XPROTO_TYPE_ + XPROTO_MASK bits.
Definition: cXProtocol.h:57
cRefPtr< cXObject > cXObjectPtr
Definition: cXObject.h:331
BYTE SCRIPTINTERFACEID_t
enumerate all the defined interface definitions.
Definition: cScriptableInterface.h:35
class __DECL_IMPORT cXObject
Definition: cXObject.h:33
PLEVEL_TYPE
Definition: PrivLevel.h:16
class __DECL_IMPORT cScriptTagDef
Definition: cXProtocol.h:34
cRefPtr< cLogAppendFile > cLogAppendFilePtr
Definition: cLogAppendFile.h:53
XPROTO_TYPE_
Definition: cXProtocol.h:39
@ XPROTO_NextChunk
Alternate name/usage for XPROTO_LastUID.
Definition: cXProtocol.h:54
@ XPROTO_Request
This is the request version of the message. (expect a response)
Definition: cXProtocol.h:52
@ XPROTO_QTY
Definition: cXProtocol.h:49
@ XPROTO_LastUID
Hint to Just use the last UID or this is the next chunk of a file.
Definition: cXProtocol.h:53
@ XPROTO_MASK
Mask XPROTO_QTY bits.
Definition: cXProtocol.h:51
@ XPROTO_HashProp
The prop name is a hash id number. variation of message.
Definition: cXProtocol.h:55
const SCRIPTINTERFACEID_t SCRIPTINTERFACEID_MAX
Definition: cScriptableInterface.h:36
class __DECL_IMPORT cVariant
Definition: cJSONWriter.h:19
class __DECL_IMPORT cScriptableInterfaceDynamic
Definition: cScriptableInterfaceDynamic.h:19
HASHCODE32_t UID_t
Sort of the same as a HASHCODE_t. not the same as UIDINDEX_t.
Definition: cUID.h:18
HASHCODE32_t ATOMCODE_t
Encode a atom as a 32 bit hashcode instead of using its name/pointer. StrT::GetHashCode32()
Definition: cAtom.h:18
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15
UINT64 FILE_SIZE_t
similar to STREAM_POS_t size_t
Definition: cFileStatus.h:31