00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GZ_DIST_SESSION_H__
00022 #define __GZ_DIST_SESSION_H__
00023
00028
00029 #include "gzDistBase.h"
00030 #include "gzDistEvaluator.h"
00031 #include "gzDistNotification.h"
00032 #include "gzDistServer.h"
00033
00034
00035 class gzDistSessionServer;
00036 class gzDistSessionObjectIterator;
00037 class gzDistSessionMessage;
00038 class gzDistDebugClient;
00039 class gzDistObjectAttribute;
00040 class gzDistClientInterface;
00041
00043 enum gzDistEvaluatorPrio
00044 {
00045 GZ_DIST_EVALUATOR_PRIO_LOWEST = 1,
00046 GZ_DIST_EVALUATOR_PRIO_LOW = 3,
00047 GZ_DIST_EVALUATOR_PRIO_MEDIUM = 5,
00048 GZ_DIST_EVALUATOR_PRIO_HIGH = 7,
00049 GZ_DIST_EVALUATOR_PRIO_HIGHEST = 10
00050 };
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00069
00084 class gzDistSession : public gzDistThreadSafeReference
00085 {
00086 friend class gzDistManager;
00087 friend class gzDistSessionObjectIterator;
00088 friend class gzDistObject;
00089
00090 public:
00091
00093 GZ_DIST_EXPORT virtual ~gzDistSession();
00094
00096
00097 GZ_DIST_EXPORT const gzString& getName();
00098
00100
00103 GZ_DIST_EXPORT gzDistObjectPtr findObject(const gzString& name);
00104
00106
00111 GZ_DIST_EXPORT gzBool findObject(const gzString& name, gzDistObjectPtr& object);
00112
00114
00115 GZ_DIST_EXPORT gzBool isGlobal();
00116
00118
00122 GZ_DIST_EXPORT gzBool registerEvaluator(const gzDistEvaluatorInterfacePtr& evaluator, const gzDistEvaluatorPrio prio = GZ_DIST_EVALUATOR_PRIO_MEDIUM);
00123
00125
00128 GZ_DIST_EXPORT gzBool unregisterEvaluator(gzDistEvaluatorInterface* evaluator);
00129
00131
00132 GZ_DIST_EXPORT gzUInt getNumberOfObjects();
00133
00135
00144 GZ_DIST_EXPORT gzDistObjectPtr waitForObject(const gzString& objectName, gzInt timeOut = 10);
00145
00147
00154 GZ_DIST_EXPORT gzBool evaluate(gzDistObject* object, gzDistEvaluatorType type, gzDistTransaction* transaction = NULL);
00155
00157
00166 GZ_DIST_EXPORT gzDistObjectPtr getNextObject(gzDistObject* object, gzType* objectType);
00167
00168 private:
00169
00170
00171
00172 gzDistSession(gzDistManager* manager, const gzString& sessionName, gzBool global, gzDistServerPriority prio);
00173
00174
00175 gzBool subscribeEvents(gzDistClientInterface* client, gzType* eventType);
00176
00177
00178 gzBool subscribeObjects(gzDistClientInterface* client, gzType* objectType, const gzBool notifyExisting);
00179
00180
00181 gzBool unsubscribeEvents(gzDistClientInterface* client, const gzType* eventType);
00182
00183
00184 gzBool unsubscribeObjects(gzDistClientInterface* client, const gzType* objectType);
00185
00186
00187 gzBool subscribeAttributeValue(const gzString& attributeName, gzDistObject* object, gzDistClientInterface* client, const gzBool notifyExisting);
00188
00189
00190 gzBool subscribeAttributeValue(gzDistTransaction* transaction, gzDistObject* object, gzDistClientInterface* client, const gzBool notifyExisting);
00191
00192
00193 gzBool unsubscribeAttributeValue(const gzString& attributeName, gzDistObject* object, gzDistClientInterface* client);
00194
00195
00196 gzBool subscribeNewAttributes(gzDistObject* object, gzDistClientInterface* client, const gzBool notifyExisting);
00197
00198
00199 gzBool unsubscribeNewAttributes(gzDistObject* object, gzDistClientInterface* client);
00200
00201
00202 gzBool join(gzDistClientInterface* client);
00203
00204
00205 gzBool resign(gzDistClientInterface* client);
00206
00207
00208 gzBool process();
00209
00210
00211 gzBool processSessionServerMessage(gzDistSessionMessage* message);
00212
00213
00214 gzVoid shutDown();
00215
00216
00217 gzVoid removeLowerSubscriptions(gzDistClientInterface* client, gzType* type, gzDict<gzInstanceCompareInterface, gzList<gzDistClientInterface> >& subscribers);
00218
00219
00220 gzBool hasHigherSubscription(gzDistClientInterface* client, gzType* type, gzDict<gzInstanceCompareInterface, gzList<gzDistClientInterface> >& subscribers);
00221
00222
00223 gzVoid notifyExistingObjects(gzDistClientInterface* client, gzType* type);
00224
00225
00226 gzVoid sendEvent(gzDistEvent* event, const gzDistClientID& clientId);
00227
00228
00229 gzBool addObject(gzDistObject* object, const gzDistClientID& clientId);
00230
00231
00232 gzBool updateObject(gzDistObject* object, gzDistTransaction* transaction, const gzDistClientID& clientId);
00233
00234
00235 gzBool removeObject(gzDistObject* object, const gzDistClientID& clientId);
00236
00237
00238 gzBool removeAttributes(gzDistTransaction* transaction, gzDistObject* object, const gzDistClientID& clientId);
00239
00240
00241 gzVoid localSendEvent(gzDistEvent* event, const gzDistClientID& clientId);
00242
00243
00244 gzBool localAddObject(gzDistObject* object);
00245
00246
00247 gzBool localUpdateObject(gzDistObject* object, gzDistTransaction* transaction);
00248
00249
00250 gzBool localRemoveAttributes(gzDistTransaction* transaction, gzDistObject* object, const gzDistClientID& client);
00251
00252
00253 gzBool localRemoveObject(gzDistObject* object);
00254
00255
00256 gzBool localRequestOwnership(gzDistObjectAttribute* attribute, const gzDistClientID& clientId);
00257
00258
00259
00260 gzBool localDropOwnership(gzDistObjectAttribute* attribute, const gzDistClientID& clientId);
00261
00262
00263 gzVoid endTransaction(const gzDistNotificationType type, gzDistObject* object);
00264
00265
00266 gzVoid notifyGrantOwnership(gzDistObjectAttribute* attribute);
00267
00268
00269 gzVoid notifyDropOwnership(gzDistObjectAttribute* attribute, gzDistClientInterface* client);
00270
00271
00272 gzVoid notifyOwnersipRequests(gzDistObjectAttribute* attribute, gzDistClientInterface* client);
00273
00274
00275 gzDistClientInterface* getClient(const gzDistClientID& clientId);
00276
00277
00278 gzUInt joinedClients();
00279
00280
00281 gzBool isJoinedClient(const gzDistClientID& clientId);
00282
00283
00284 gzBool requestOwnership(const gzString& attributeName, gzDistObject* object, gzDistClientInterface* client);
00285
00286
00287 gzBool dropOwnership(const gzString& attributeName, gzDistObject* object, gzDistClientInterface* client);
00288
00289
00290 gzBool pullOwnership(const gzString& attributeName, gzDistObject* object, gzDistClientInterface* client);
00291
00292
00293 gzVoid synchronizeObject(gzDistObject* object);
00294
00295
00296 gzVoid synchronizeOwnership(gzDistObjectAttribute* existingAttribute, gzDistObjectAttribute* syncAttribute);
00297
00298
00299 gzBool localSetOwnership(gzDistObjectAttribute* attribute, const gzDistClientID& clientId);
00300
00301
00302 gzBool isValidInsertion(gzDistObject* object);
00303
00304
00305 gzBool isAllowedUpdate(gzDistTransaction* transaction, gzDistObject* object, const gzDistClientID& clientId);
00306
00307
00308 gzVoid cleanUpInstance(const gzDistInstanceID& instance);
00309
00310
00311 gzBool hasPendingData();
00312
00313
00314 gzVoid setDebugClient(gzDistDebugClient* debugClient);
00315
00316
00317 gzVoid debugAttributeSubscriptions(const gzString& attributeName, gzDistObject* object, gzDistClientInterface* subscriber, gzBool newClient);
00318
00319
00320 gzVoid debugAttributeSubscriptions(gzDistTransaction* transaction, gzDistObject* object, gzDistClientInterface* subscriber, gzBool newClient);
00321
00322
00323 gzVoid debugNewAttributesSubscriptions(gzDistObject* object, gzDistClientInterface* subscriber, gzBool newClient);
00324
00325 gzVoid debugOwnership(gzDistObjectAttribute* attribute);
00326
00327 gzVoid addLinkObject(gzDistObject* object);
00328
00329 gzVoid removeLinkObject(gzDistObject* object);
00330
00331 gzDistObject* firstObject();
00332
00333 gzBool isServer();
00334
00335
00336
00337
00338 const gzString m_name;
00339
00340 const gzDouble m_creationTime;
00341
00342
00343 gzDict<gzInstanceCompareInterface, gzList<gzDistClientInterface> > m_eventSubscribers;
00344
00345
00346 gzDict<gzInstanceCompareInterface, gzList<gzDistClientInterface> > m_objectSubscribers;
00347
00348
00349 gzDict<gzDistClientID, gzDistClientInterface> m_joinedClients;
00350
00351
00352 gzRefDict<gzString, gzDistObject> m_objects;
00353
00354
00355 gzMutex m_objectsLocker;
00356
00357
00358 gzDistManagerPtr m_manager;
00359
00360
00361 gzRefList<gzDistEvaluatorInterface> m_evaluators;
00362
00363
00364 gzMutex m_evaluatorLocker;
00365
00366
00367
00368 gzDistSessionServer* m_sessionServer;
00369
00370
00371 gzList<gzDistSessionMessage>* m_sessionServerMessages;
00372
00373
00374 gzDistDebugClient* m_debugClient;
00375
00376 gzDistObject* m_firstObject;
00377
00378 gzDistObject* m_lastObject;
00379 };
00380
00381
00382
00383
00385 class gzDistSessionObjectIterator
00386 {
00387 public:
00388
00390
00393 GZ_DIST_EXPORT gzDistSessionObjectIterator(const gzDistSessionPtr& session, gzType* objectType);
00394
00396
00398 GZ_DIST_EXPORT gzDistSessionObjectIterator(const gzDistSessionPtr& session);
00399
00401
00402 GZ_DIST_EXPORT ~gzDistSessionObjectIterator();
00403
00405
00407 GZ_DIST_EXPORT gzDistObject* operator()();
00408
00410 GZ_DIST_EXPORT gzDistObject* current();
00411
00413 GZ_DIST_EXPORT gzVoid reset();
00414
00416
00422 GZ_DIST_EXPORT gzVoid unLockSession();
00423
00424 private:
00425
00426 const gzDistSessionPtr m_session;
00427 gzDistObject* m_currentObject;
00428 gzType* m_objectType;
00429 gzBool m_lockedSession;
00430 };
00431
00432
00433
00435 class gzDistSessionIterator
00436 {
00437 public:
00438 GZ_DIST_EXPORT gzDistSessionIterator();
00439 GZ_DIST_EXPORT ~gzDistSessionIterator();
00440
00442
00444 GZ_DIST_EXPORT gzDistSession* operator()();
00445
00447 GZ_DIST_EXPORT gzDistSession* current();
00448
00450 GZ_DIST_EXPORT gzVoid reset();
00451
00452 private:
00453
00454 gzDistManagerPtr m_manager;
00455
00456 gzDictIterator<gzString, gzDistSession>* m_iterator;
00457 gzDictEntry<gzString, gzDistSession>* m_entry;
00458
00459 gzBool m_sessionsLocked;
00460 };
00461
00462 #endif //__GZ_DIST_SESSION_H__