ReplicaNet and RNLobby  1
DataBlock_Function.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef __DATABLOCK_FUNCTION_H__
13 #define __DATABLOCK_FUNCTION_H__
14 
15 #include "RNReplicaNet/Inc/DataBlock.h"
16 #include "RNPlatform/Inc/MessageHelper.h"
17 #include "RNPlatform/Inc/RegistryManagerMap.h"
18 #include <list>
19 
20 namespace RNReplicaNet
21 {
22 
23 struct CombinedDataPacket;
24 struct SessionBlock_Function;
25 
57 {
58 public:
59  RN_CLASS_MINIMAL_RTTI();
60  typedef void (tDataBlock_Function_funcp)(void *classp,void *data,void *thisDataBlock);
61 
66 
70  virtual ~DataBlock_Function();
71 
72  virtual void Poll(DataBlockReason *reason,const bool discardOlderIncluded = false,const unsigned int discardOrder = 0);
73 
74  virtual void ParseMessage(MessageHelper *message);
75 
82  static DataBlock_Function *Register(void *classp,tDataBlock_Function_funcp *funcp);
83 
89  void RegisterInClassPointer(void *classp,tDataBlock_Function_funcp *funcp)
90  {
91  mClassp = classp;
92  mData = funcp;
93  }
94 
101  static void SetSessionIDFilter(const int numSessionIDs = 0,const int *sessionIDs = 0);
102 
103  void AddFunctionStateChange(void *data,int len,const char *debug = 0);
104 
105  bool IsAttached(void *data);
106 
107  virtual void OwnerChanged(const int sessionID);
108 
109 protected: // User defined DataBlocks have access to these variables.
110  void FreeSessionBlocks(void);
111  void *mClassp;
112  tDataBlock_Function_funcp *mData;
113 
115 
116  std::list<CombinedDataPacket *> mFunctionStateChanges;
117 
118  static int mConfiguredNumSessions;
119  static int *mConfiguredSessionIDs;
120 };
121 
122 // Specialise this template to allow different variable types to be used with DataBlock_Function
123 template<typename T>
124 void FunctionAddVariable(DynamicMessageHelper &message, T &variable)
125 {
126  message.AddVariable(&variable,sizeof(variable));
127 }
128 
129 // Specialise this template to allow different variable types to be used with DataBlock_Function
130 template<typename T>
131 void FunctionGetVariable(MessageHelper &message, T &variable)
132 {
133  message.GetVariable(&variable,sizeof(variable));
134 }
135 
136 } // namespace RNReplicaNet
137 
138 
139 /* _RO_DO_REGISTERBLOCK_FUNCTION_VAR macro starts here */
140 #define _RO_DO_REGISTERBLOCK_FUNCTION_VAR(x) \
141  {\
142  RNReplicaNet::DataBlock_Function *datablock = 0; \
143  datablock = RNReplicaNet::DataBlock_Function::Register((void *)this,&x); \
144  mDataBlockFunction_##x = datablock; \
145  _RO_DO_SETDATABLOCKVARIABLENAME(x);
146 /* _RO_DO_REGISTERBLOCK_FUNCTION_VAR macro ends here */
147 
148 // For member function wrapping. A lot of macro work
149 /* _RO_MAKE_MEMBERFUNC macro starts here */
150 #define _RO_MAKE_MEMBERFUNC(x) Call_##x
151 /* _RO_MAKE_MEMBERFUNC macro ends here */
152 
153 /* _RO_DO_MEMBERFUNC_PRESTAGE_DEF macro starts here */
154 #define _RO_DO_MEMBERFUNC_PRESTAGE_DEF(x,y) \
155 void _MAKE_RO(x)::_RO_MAKE_MEMBERFUNC(y)(
156 /* _RO_DO_MEMBERFUNC_PRESTAGE_DEF macro ends here */
157 
158 
159 /* _RO_DO_MEMBERFUNC_PRESTAGE macro starts here */
160 #ifdef REPLICANET_VISUALDEBUGGER
161 #define _RO_DO_MEMBERFUNC_PRESTAGE(x) \
162 ) \
163 { \
164  if (!mDataBlocksRegistered) \
165  { \
166  return; \
167  } \
168  RNReplicaNet::DynamicMessageHelper message; \
169  message.SetBufferSize(256); \
170  std::string debug;
171 #else //ifdef REPLICANET_VISUALDEBUGGER
172 #define _RO_DO_MEMBERFUNC_PRESTAGE(x) \
173 ) \
174 { \
175  if (!mDataBlocksRegistered) \
176  { \
177  return; \
178  } \
179  RNReplicaNet::DynamicMessageHelper message; \
180  message.SetBufferSize(256);
181 #endif //ifdef REPLICANET_VISUALDEBUGGER
182 /* _RO_DO_MEMBERFUNC_PRESTAGE macro ends here */
183 
184 /* _RO_DO_MEMBERFUNC_ADDVAR macro starts here */
185 #define _RO_DO_MEMBERFUNC_ADDVAR(x) \
186  RNReplicaNet::FunctionAddVariable(message,x);
187 // Updated version of this macro, does the same as _RO_DO_MEMBERFUNC_ADDVAR but also includes the string variable type for extra debug info.
188 #ifdef REPLICANET_VISUALDEBUGGER
189 #define _RO_DO_MEMBERFUNC_ADDVAR2(x,y) \
190  RNReplicaNet::FunctionAddVariable(message,x); \
191  if (RNReplicaNet::XPURL::GetDebugHandler()) \
192  { \
193  debug += #y; \
194  debug += "\n"; \
195  debug += RNReplicaNet::MessageHelper::DumpAsHex(&x,sizeof(x)); \
196  debug += "\n"; \
197  }
198 #else // ifdef REPLICANET_VISUALDEBUGGER
199 #define _RO_DO_MEMBERFUNC_ADDVAR2(x,y) \
200  RNReplicaNet::FunctionAddVariable(message,x);
201 #endif // ifdef REPLICANET_VISUALDEBUGGER
202 /* _RO_DO_MEMBERFUNC_ADDVAR macro ends here */
203 
204 /* _RO_DO_MEMBERFUNC_POSTSTAGE macro starts here */
205 #ifdef REPLICANET_VISUALDEBUGGER
206 #define _RO_DO_MEMBERFUNC_POSTSTAGE(x) \
207  RNReplicaNet::DataBlock_Function *datablock = (RNReplicaNet::DataBlock_Function *) mDataBlockFunction_##x; \
208  datablock->AddFunctionStateChange(message.GetBuffer(),message.GetSize(),debug.c_str()); \
209 }
210 #else //ifdef REPLICANET_VISUALDEBUGGER
211 #define _RO_DO_MEMBERFUNC_POSTSTAGE(x) \
212  RNReplicaNet::DataBlock_Function *datablock = (RNReplicaNet::DataBlock_Function *) mDataBlockFunction_##x; \
213  datablock->AddFunctionStateChange(message.GetBuffer(),message.GetSize()); \
214 }
215 #endif //ifdef REPLICANET_VISUALDEBUGGER
216 /* _RO_DO_MEMBERFUNC_POSTSTAGE macro ends here */
217 
218 
219 /* _RO_DO_MEMBERFUNC_CRACK_START macro starts here */
220 #define _RO_DO_MEMBERFUNC_CRACK_START(x,y) \
221 void _MAKE_RO(x)::y(void *classp,void *opaque_message,void *thisDataBlock) \
222 { \
223  _MAKE_RO(x) *thisclass = (_MAKE_RO(x) *) classp; \
224  RNReplicaNet::MessageHelper *message = (RNReplicaNet::MessageHelper *) opaque_message; \
225  message = message;
226 /* _RO_DO_MEMBERFUNC_CRACK_START macro ends here */
227 
228 /* _RO_DO_MEMBERFUNC_MESSAGE_CRACK macro starts here */
229 #define _RO_DO_MEMBERFUNC_MESSAGE_CRACK(x) \
230  RNReplicaNet::FunctionGetVariable(*message,x);
231 /* _RO_DO_MEMBERFUNC_MESSAGE_CRACK macro ends here */
232 
233 
234 /* _RO_DO_MEMBERFUNC_CRACK_END macro starts here */
235 #define _RO_DO_MEMBERFUNC_CRACK_END(x,y) \
236  if (!((RNReplicaNet::DataBlock*)thisDataBlock)->GetDiscardThisUpdate()) \
237  { \
238  ((x*)thisclass)->y(
239 /* _RO_DO_MEMBERFUNC_CRACK_END macro ends here */
240 
241 /* _RO_DO_MEMBERFUNC_CRACK_END2 macro starts here */
242 #define _RO_DO_MEMBERFUNC_CRACK_END2() \
243  ); \
244  } \
245 }
246 /* _RO_DO_MEMBERFUNC_CRACK_END2 macro ends here */
247 
248 #endif
Definition: DataBlock.h:357
void RegisterInClassPointer(void *classp, tDataBlock_Function_funcp *funcp)
Definition: DataBlock_Function.h:89
Definition: DataBlock_Function.h:56
static DataBlock_Function * Register(void *classp, tDataBlock_Function_funcp *funcp)
virtual void ParseMessage(MessageHelper *message)
Definition: MessageHelper.h:35
virtual void OwnerChanged(const int sessionID)
virtual void Poll(DataBlockReason *reason, const bool discardOlderIncluded=false, const unsigned int discardOrder=0)
static void SetSessionIDFilter(const int numSessionIDs=0, const int *sessionIDs=0)
Definition: DataBlock.h:47