DataBlock_Function.h

00001 /* START_LICENSE_HEADER
00002 
00003 Copyright (C) 2000 Martin Piper, original design and program code
00004 Copyright (C) 2001 Replica Software
00005 
00006 This program file is copyright (C) Replica Software and can only be used under license.
00007 For more information visit: http://www.replicanet.com/
00008 Or email: info@replicanet.com
00009 
00010 END_LICENSE_HEADER */
00011 #ifndef __DATABLOCK_FUNCTION_H__
00012 #define __DATABLOCK_FUNCTION_H__
00013 #include "RNPlatform/Inc/DLLExportAPI.h"
00014 
00015 #include "RNReplicaNet/Inc/DataBlock.h"
00016 #include "RNPlatform/Inc/MessageHelper.h"
00017 #include "RNPlatform/Inc/RegistryManagerMap.h"
00018 #include <list>
00019 
00020 namespace RNReplicaNet
00021 {
00022 
00023 struct CombinedDataPacket;
00024 struct SessionBlock_Function;
00025 
00052 class REPLICANETDLL_API DataBlock_Function : public DataBlock
00053 {
00054 public:
00055     typedef void (tDataBlock_Function_funcp)(void *classp,void *data);
00056 
00060     DataBlock_Function();
00061 
00065     virtual ~DataBlock_Function();
00066 
00067     virtual void Poll(DataBlockReason *reason);
00068 
00069     virtual void ParseMessage(MessageHelper *message);
00070 
00077     static DataBlock_Function *Register(void *classp,tDataBlock_Function_funcp *funcp);
00078 
00084     void RegisterInClassPointer(void *classp,tDataBlock_Function_funcp *funcp)
00085     {
00086         mClassp = classp;
00087         mData = funcp;
00088     }
00089 
00096     static void SetSessionIDFilter(const int numSessionIDs = 0,const int *sessionIDs = 0);
00097 
00098     void AddFunctionStateChange(void *data,int len,const char *debug = 0);
00099 
00100     bool IsAttached(void *data);
00101 
00102 protected:  // User defined DataBlocks have access to these variables.
00103     void *mClassp;
00104     tDataBlock_Function_funcp *mData;
00105 
00106     RegistryManagerMap<int,SessionBlock_Function> mPerSessionFunction;
00107 
00108     std::list<CombinedDataPacket *> mFunctionStateChanges;
00109 
00110     static int mConfiguredNumSessions;
00111     static int *mConfiguredSessionIDs;
00112 };
00113 
00114 } // namespace RNReplicaNet
00115 
00116 
00117 /* _RO_DO_REGISTERBLOCK_FUNCTION_VAR macro starts here */
00118 #define _RO_DO_REGISTERBLOCK_FUNCTION_VAR(x)    \
00119     {\
00120         RNReplicaNet::DataBlock_Function *datablock = 0;    \
00121         datablock = RNReplicaNet::DataBlock_Function::Register((void *)this,&x);    \
00122         mDataBlockFunction_##x = datablock; \
00123         _RO_DO_SETDATABLOCKVARIABLENAME(x);
00124 /* _RO_DO_REGISTERBLOCK_FUNCTION_VAR macro ends here */
00125 
00126 // For member function wrapping. A lot of macro work
00127 /* _RO_MAKE_MEMBERFUNC macro starts here */
00128 #define _RO_MAKE_MEMBERFUNC(x)  Call_##x
00129 /* _RO_MAKE_MEMBERFUNC macro ends here */
00130 
00131 /* _RO_DO_MEMBERFUNC_PRESTAGE_DEF macro starts here */
00132 #define _RO_DO_MEMBERFUNC_PRESTAGE_DEF(x,y) \
00133 void _MAKE_RO(x)::_RO_MAKE_MEMBERFUNC(y)(
00134 /* _RO_DO_MEMBERFUNC_PRESTAGE_DEF macro ends here */
00135 
00136 
00137 /* _RO_DO_MEMBERFUNC_PRESTAGE macro starts here */
00138 #ifdef REPLICANET_VISUALDEBUGGER
00139 #define _RO_DO_MEMBERFUNC_PRESTAGE(x)   \
00140 )   \
00141 {   \
00142     if (!mDataBlocksRegistered) \
00143     {   \
00144         return; \
00145     }   \
00146     RNReplicaNet::DynamicMessageHelper message; \
00147     message.SetBufferSize(256); \
00148     std::string debug;
00149 #else //ifdef REPLICANET_VISUALDEBUGGER
00150 #define _RO_DO_MEMBERFUNC_PRESTAGE(x)   \
00151 )   \
00152 {   \
00153     if (!mDataBlocksRegistered) \
00154     {   \
00155         return; \
00156     }   \
00157     RNReplicaNet::DynamicMessageHelper message; \
00158     message.SetBufferSize(256);
00159 #endif //ifdef REPLICANET_VISUALDEBUGGER
00160 /* _RO_DO_MEMBERFUNC_PRESTAGE macro ends here */
00161 
00162 /* _RO_DO_MEMBERFUNC_ADDVAR macro starts here */
00163 #define _RO_DO_MEMBERFUNC_ADDVAR(x) \
00164     message.AddVariable(&x,sizeof(x));
00165 // Updated version of this macro, does the same as _RO_DO_MEMBERFUNC_ADDVAR but also includes the string variable type for extra debug info.
00166 #ifdef REPLICANET_VISUALDEBUGGER
00167 #define _RO_DO_MEMBERFUNC_ADDVAR2(x,y)  \
00168     message.AddVariable(&x,sizeof(x));  \
00169     if (RNReplicaNet::XPURL::GetDebugHandler()) \
00170     {   \
00171         debug += #y;    \
00172         debug += "\n";  \
00173         debug += RNReplicaNet::MessageHelper::DumpAsHex(&x,sizeof(x));  \
00174         debug += "\n";  \
00175     }
00176 #else // ifdef REPLICANET_VISUALDEBUGGER
00177 #define _RO_DO_MEMBERFUNC_ADDVAR2(x,y)  \
00178     message.AddVariable(&x,sizeof(x));
00179 #endif // ifdef REPLICANET_VISUALDEBUGGER
00180 /* _RO_DO_MEMBERFUNC_ADDVAR macro ends here */
00181 
00182 /* _RO_DO_MEMBERFUNC_POSTSTAGE macro starts here */
00183 #ifdef REPLICANET_VISUALDEBUGGER
00184 #define _RO_DO_MEMBERFUNC_POSTSTAGE(x)  \
00185     RNReplicaNet::DataBlock_Function *datablock = (RNReplicaNet::DataBlock_Function *) mDataBlockFunction_##x;  \
00186     datablock->AddFunctionStateChange(message.GetBuffer(),message.GetSize(),debug.c_str()); \
00187 }
00188 #else //ifdef REPLICANET_VISUALDEBUGGER
00189 #define _RO_DO_MEMBERFUNC_POSTSTAGE(x)  \
00190     RNReplicaNet::DataBlock_Function *datablock = (RNReplicaNet::DataBlock_Function *) mDataBlockFunction_##x;  \
00191     datablock->AddFunctionStateChange(message.GetBuffer(),message.GetSize());   \
00192 }
00193 #endif //ifdef REPLICANET_VISUALDEBUGGER
00194 /* _RO_DO_MEMBERFUNC_POSTSTAGE macro ends here */
00195 
00196 
00197 /* _RO_DO_MEMBERFUNC_CRACK_START macro starts here */
00198 #define _RO_DO_MEMBERFUNC_CRACK_START(x,y)  \
00199 void _MAKE_RO(x)::y(void *classp,void *opaque_message)  \
00200 {   \
00201     _MAKE_RO(x) *thisclass = (_MAKE_RO(x) *) classp;    \
00202     RNReplicaNet::MessageHelper *message = (RNReplicaNet::MessageHelper *) opaque_message;  \
00203     message = message;
00204 /* _RO_DO_MEMBERFUNC_CRACK_START macro ends here */
00205 
00206 /* _RO_DO_MEMBERFUNC_MESSAGE_CRACK macro starts here */
00207 #define _RO_DO_MEMBERFUNC_MESSAGE_CRACK(x)  \
00208 MESSAGEHELPER_GETVARIABLEp((*message),x);
00209 /* _RO_DO_MEMBERFUNC_MESSAGE_CRACK macro ends here */
00210 
00211 
00212 /* _RO_DO_MEMBERFUNC_CRACK_END macro starts here */
00213 #define _RO_DO_MEMBERFUNC_CRACK_END(x,y)    \
00214     ((x*)thisclass)->y(
00215 /* _RO_DO_MEMBERFUNC_CRACK_END macro ends here */
00216 
00217 /* _RO_DO_MEMBERFUNC_CRACK_END2 macro starts here */
00218 #define _RO_DO_MEMBERFUNC_CRACK_END2()  \
00219 );  \
00220 }
00221 /* _RO_DO_MEMBERFUNC_CRACK_END2 macro ends here */
00222 
00223 #endif

Generated on Sat Jun 28 22:02:16 2008 for ReplicaNet and RNLobby by  doxygen 1.5.3