00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GZ_DIST_BASE_H__
00022 #define __GZ_DIST_BASE_H__
00023
00031
00032 #include "gzBaseLibrary.h"
00033
00034 #ifdef GZ_WIN32
00035 #include <assert.h>
00036 #endif
00037
00038
00039
00040
00041 #ifdef GZ_WIN32
00042 #ifndef GZ_DIST_STATIC
00043 #define GZ_DIST_DLL
00044 #endif
00045 #endif
00046
00047 #ifdef GZ_DIST_DLL
00048
00049 #ifdef GZ_DISTRIBUTION_EXPORTS
00050 #define GZ_DIST_EXPORT __declspec(dllexport)
00051 #else
00052 #define GZ_DIST_EXPORT __declspec(dllimport)
00053 #endif
00054
00055 #ifdef GZ_REMOTE_DISTRIBUTION_EXPORTS
00056 #define GZ_REMOTE_EXPORT __declspec(dllexport)
00057 #else
00058 #define GZ_REMOTE_EXPORT __declspec(dllimport)
00059 #endif
00060
00061 #else
00062
00063 #define GZ_DIST_EXPORT
00064 #define GZ_REMOTE_EXPORT
00065
00066 #endif
00067
00068
00069
00070
00072 const gzString GZ_DIST_IDENTIFIER = "GizmoDistribution";
00073
00074 #define GZ_DIST_ASSERT(expr) GZ_MODULE_ASSERT(GZ_DIST_IDENTIFIER, expr)
00075 #define GZ_DIST_ASSERT_TEXT(expr, text) GZ_MODULE_ASSERT_TEXT(GZ_DIST_IDENTIFIER, expr, text)
00076
00077 #define GZ_DIST_DEBUG GZ_DIST_IDENTIFIER, GZ_MESSAGE_DEBUG
00078 #define GZ_DIST_NOTICE GZ_DIST_IDENTIFIER, GZ_MESSAGE_NOTICE
00079 #define GZ_DIST_WARNING GZ_DIST_IDENTIFIER, GZ_MESSAGE_WARNING
00080 #define GZ_DIST_FATAL GZ_DIST_IDENTIFIER, GZ_MESSAGE_FATAL
00081
00082
00083 #ifdef GZ_DEBUG
00084 #define GZ_DIST_DEBUG_WARNING GZ_DIST_WARNING
00085 #else
00086 #define GZ_DIST_DEBUG_WARNING GZ_MESSAGE_DEBUG
00087 #endif
00088
00089 #define GZ_DIST_TRACE0(text) GZTRACES(GZ_DIST_IDENTIFIER, text)
00090 #define GZ_DIST_TRACE1(format, arg1) GZTRACES(GZ_DIST_IDENTIFIER, format, arg1)
00091 #define GZ_DIST_TRACE2(format, arg1, arg2) GZTRACES(GZ_DIST_IDENTIFIER, format, arg1, arg2)
00092 #define GZ_DIST_TRACE3(format, arg1, arg2, arg3) GZTRACES(GZ_DIST_IDENTIFIER, format, arg1, arg2, arg3)
00093
00094
00095
00096
00097
00098 #define GZ_DIST_OPTIMIZED_MEMORY
00099
00100 #ifdef GZ_DIST_OPTIMIZED_MEMORY
00101 #define GZ_DIST_DECLARE_MEMBASE(cls) GZ_DECLARE_MEMBASE(cls)
00102 #define GZ_DIST_DECLARE_MEMBASE_EXPORT(cls, exp) GZ_DECLARE_MEMBASE_EXPORT(cls, exp)
00103 #define GZ_DIST_MEMBASE(cls) , public GZ_MEMBASE(cls)
00104 #define GZ_DIST_MEMBASE_SINGLE(cls) : public GZ_MEMBASE(cls)
00105 #define GZ_DIST_MEMBASE_IMP(cls) GZ_MEMBASE_IMP(cls)
00106 #define GZ_DIST_DECLARE_MEMBASE_IMP(cls, size) GZ_DECLARE_MEMBASE_IMP(cls, size)
00107
00108 #define GZ_DIST_MEMBASE_CALL(className) \
00109 static gzVoid enableOptimizeMemory() { s_allocator_##className.enable(); } \
00110 static gzVoid disableOptimizeMemory(gzBool force = FALSE) { s_allocator_##className.disable(); } \
00111 static gzBool tryResizeOptimizeMemory(gzULong nbrOfslots) { return s_allocator_##className.tryResize(nbrOfslots); }
00112 #else
00113 #define GZ_DIST_DECLARE_MEMBASE(cls)
00114 #define GZ_DIST_DECLARE_MEMBASE_EXPORT(cls, exp)
00115 #define GZ_DIST_MEMBASE(cls)
00116 #define GZ_DIST_MEMBASE_SINGLE(cls)
00117 #define GZ_DIST_MEMBASE_IMP(cls)
00118 #define GZ_DIST_DECLARE_MEMBASE_IMP(cls, size)
00119
00120 #define GZ_DIST_MEMBASE_CALL(className)
00121 #endif
00122
00123
00124
00125
00126
00128 const gzString GZ_DIST_EVENT = gzUniqueString("gzDistEvent", 90);
00129
00131 const gzString GZ_DIST_OBJECT = gzUniqueString("gzDistObject", 91);
00132
00134 const gzString GZ_DIST_NO_NAME;
00135
00136
00137
00138
00140 const gzInt GZ_DIST_SYNCHRONOUS = -1;
00141
00143 const gzInt GZ_DIST_ASYNCHRONOUS = 0;
00144
00146 const gzULong GZ_DIST_IDLE_SLEEP_TIME = 10;
00147
00148
00149
00150
00152 const gzULong GZ_DIST_POOL_ID_DEFAULT = 0;
00153
00155 const gzULong GZ_DIST_POOL_ID_CUSTOM = 0xFFFFFFFF;
00156
00158 const gzULong GZ_DIST_POOL_ID_DEBUG = 0xDEBA6;
00159
00160
00161
00162
00164 const gzString GZ_DIST_DEFAULT_IP_ADDRESS = "234.5.6.7";
00165
00167 const gzUShort GZ_DIST_DEFAULT_SERVER_PORT = 1122;
00168
00170 const gzUShort GZ_DIST_DEFAULT_SESSION_PORT = 2211;
00171
00172
00173
00174
00176 #define GZ_DIST_PTR(x) class x; typedef gzRefPointer<x> x##Ptr
00177
00179 #define GZ_DIST_LIST(x) typedef gzRefList<x> x##List; \
00180 typedef gzListIterator<x> x##Iterator
00181
00182
00183
00184
00185
00186 GZ_DIST_PTR(gzDistThreadSafeReference);
00187 GZ_DIST_PTR(gzDistEvent);
00188 GZ_DIST_PTR(gzDistObject);
00189 GZ_DIST_PTR(gzDistTransaction);
00190 GZ_DIST_PTR(gzDistSession);
00191 GZ_DIST_PTR(gzDistManager);
00192 GZ_DIST_PTR(gzDistManagerMessage);
00193 GZ_DIST_PTR(gzDistClientMessage);
00194 GZ_DIST_PTR(gzDistNotification);
00195 GZ_DIST_PTR(gzDistNotificationData);
00196 GZ_DIST_PTR(gzDistEvaluatorInterface);
00197 GZ_DIST_PTR(gzDistRemoteMessage);
00198 GZ_DIST_PTR(gzDistRouterBuffer);
00199
00200
00201
00202
00203 GZ_DIST_LIST(gzDistClientMessage);
00204 GZ_DIST_LIST(gzDistManagerMessage);
00205 GZ_DIST_LIST(gzDistNotification);
00206
00207
00208
00209
00211 class gzDistThreadSafeReference : public gzReference
00212 {
00213 public:
00214
00216 GZ_DIST_EXPORT gzDistThreadSafeReference();
00217
00219 GZ_DIST_EXPORT virtual ~gzDistThreadSafeReference();
00220
00222 GZ_DIST_EXPORT gzVoid ref();
00223
00225 GZ_DIST_EXPORT gzVoid unref();
00226
00228 GZ_DIST_EXPORT gzUInt unrefNoDelete();
00229
00231 GZ_DIST_EXPORT virtual gzReference* clone() const;
00232
00234 GZ_DIST_EXPORT virtual gzBool useDeepCopy();
00235
00236
00237 private:
00238
00239 gzMutex m_referenceLocker;
00240 };
00241
00242
00243
00244 class gzDistTrigger
00245 {
00246 public:
00247 gzDistTrigger();
00248 ~gzDistTrigger();
00249
00250 gzBool isTrigged() const;
00251 gzVoid reset();
00252 gzVoid fire();
00253
00254
00255 gzBool wait(gzUInt timeOut);
00256
00257 private:
00258 gzEvent m_trigger;
00259 gzBool m_trigged;
00260 };
00261
00262
00263
00264
00265 class gzDistTransportInterface;
00266 class gzDistEncoderInterface;
00267
00268
00270 class gzDistRemoteChannelInterface
00271 {
00272 public:
00273
00275 GZ_DIST_EXPORT gzDistRemoteChannelInterface() { };
00276
00277
00278 GZ_DIST_EXPORT virtual ~gzDistRemoteChannelInterface() { };
00279
00281
00285 GZ_REMOTE_EXPORT virtual gzBool setTransport(gzDistTransportInterface* transport, gzDistEncoderInterface* encoder = NULL) = 0;
00286
00288 GZ_DIST_EXPORT virtual gzBool open() = 0;
00289
00291 GZ_DIST_EXPORT virtual gzVoid close() = 0;
00292
00294 GZ_DIST_EXPORT virtual gzBool isOpen() = 0;
00295
00297 GZ_DIST_EXPORT virtual gzBool send(gzDistRemoteMessage* message) = 0;
00298
00300 GZ_DIST_EXPORT virtual gzBool receive(gzDistRemoteMessagePtr& message) = 0;
00301
00303 GZ_DIST_EXPORT virtual gzUInt getProtocolHeaderSize() = 0;
00304
00305 GZ_DIST_EXPORT virtual gzVoid onTick(){}
00306
00307 GZ_DIST_EXPORT virtual gzBool hasPendingData(){return FALSE;}
00308 };
00309
00310
00311
00312
00314
00316 class GZ_DIST_EXPORT gzDistInstanceID
00317 {
00318 public:
00319
00321 gzDistInstanceID();
00322
00324 gzDistInstanceID(gzULong pid, gzULong mid);
00325
00327 gzDistInstanceID(gzULongLong id);
00328
00330 virtual ~gzDistInstanceID();
00331
00333 gzBool operator==(const gzDistInstanceID& id) const;
00334
00336 gzBool operator!=(const gzDistInstanceID& id) const;
00337
00339 gzBool operator<(const gzDistInstanceID& id) const;
00340
00342 gzBool operator>(const gzDistInstanceID& id) const;
00343
00345 gzBool isNull() const;
00346
00348 gzVoid setNull();
00349
00351 gzString asString() const;
00352
00354 gzULongLong asULongLong() const;
00355
00357 gzULong processID;
00358
00360 gzULong machineID;
00361
00362 };
00363
00364
00366 const gzDistInstanceID GZ_DIST_NULL_INSTANCE(0, 0);
00367
00368
00369
00370
00372
00375 class GZ_DIST_EXPORT gzDistClientID
00376 {
00377 public:
00378
00380 gzDistClientID();
00381
00383
00384 explicit gzDistClientID(const gzString& name);
00385
00387 gzDistClientID(const gzString& name, const gzDistInstanceID& instance);
00388
00390 gzDistClientID(const gzString& name, gzUInt pid, const gzULong mid);
00391
00393 ~gzDistClientID();
00394
00396 gzBool operator==(const gzDistClientID& id) const;
00397
00399 gzBool operator!=(const gzDistClientID& id) const;
00400
00402 gzBool isNull() const;
00403
00405 gzVoid setNull();
00406
00408 gzString asString() const;
00409
00411 gzULong hash() const;
00412
00413
00414
00416 gzString name;
00417
00419 gzDistInstanceID instanceID;
00420 };
00421
00422
00424 const gzDistClientID GZ_DIST_NULL_CLIENT(GZ_EMPTY_STRING, GZ_DIST_NULL_INSTANCE);
00425
00426
00427
00428
00429 class gzDistInternals
00430 {
00431 friend class gzDistRemoteChannel;
00432 friend class gzDistServerImpl;
00433 friend class gzDistManager;
00434
00435 private:
00436 GZ_DIST_EXPORT static gzVoid gzDistAddPendingInstance(const gzDistInstanceID& instanceId);
00437 GZ_DIST_EXPORT static gzBool gzDistProcessPendingInstance(const gzDistInstanceID& instanceId, gzVoid* channel);
00438 GZ_DIST_EXPORT static gzVoid gzDistClearPendingInstances();
00439 };
00440
00441
00442
00444
00446 GZ_DIST_EXPORT gzUInt gzDistGetCurrentProcessID();
00447
00448
00450
00452 GZ_DIST_EXPORT gzULong gzDistGetCurrentMachineID();
00453
00454
00456
00458 GZ_DIST_EXPORT const gzDistInstanceID& gzDistGetCurrentInstanceID();
00459
00460 #endif //__GZ_DIST_BASE_H__