00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GZ_DIST_CLIENT_H__
00022 #define __GZ_DIST_CLIENT_H__
00023
00028
00029 #include "gzDistBase.h"
00030 #include "gzDistNotification.h"
00031 #include "gzDistServer.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00050
00074 class gzDistClientInterface
00075 {
00076 friend class gzDistSession;
00077 friend class gzDistManager;
00078 friend class gzDistClientThread;
00079 friend class gzDistClientThreadPool;
00080
00081 public:
00082
00084
00087 GZ_DIST_EXPORT gzDistClientInterface(const gzString& clientName);
00088
00090
00091 GZ_DIST_EXPORT gzDistClientInterface(const gzDistClientInterface& original);
00092
00094
00096 GZ_DIST_EXPORT virtual ~gzDistClientInterface();
00097
00099
00111 GZ_DIST_EXPORT gzBool initialize(const gzDouble& tickInterval = 0, gzULong poolId = GZ_DIST_POOL_ID_DEFAULT, gzBool responseBoost = FALSE);
00112
00114
00119 GZ_DIST_EXPORT gzBool uninitialize(gzBool wait = FALSE);
00120
00122
00125 GZ_DIST_EXPORT gzBool isInitialized();
00126
00128
00132 GZ_DIST_EXPORT const gzDistClientID& getID();
00133
00135
00149 GZ_DIST_EXPORT gzDistSessionPtr getSession(const gzString& sessionName, gzBool create = FALSE, gzBool global = FALSE, gzDistServerPriority prio = GZ_DIST_SERVER_PRIO_NORMAL);
00150
00152
00159 GZ_DIST_EXPORT gzBool joinSession(const gzDistSessionPtr& session, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00160
00162
00168 GZ_DIST_EXPORT gzBool resignSession(const gzDistSessionPtr& session, gzInt timeOut = GZ_DIST_SYNCHRONOUS);
00169
00171
00177 GZ_DIST_EXPORT gzBool subscribeSessions(gzBool notifyExisting = FALSE, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00178
00180
00183 GZ_DIST_EXPORT gzBool unsubscribeSessions(gzInt timeOut = GZ_DIST_SYNCHRONOUS);
00184
00186
00194 GZ_DIST_EXPORT gzBool subscribeEvents(gzType* classType, const gzDistSessionPtr& session, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00195
00197
00203 GZ_DIST_EXPORT gzBool unsubscribeEvents(gzType* classType, const gzDistSessionPtr& session, gzInt timeOut = GZ_DIST_SYNCHRONOUS);
00204
00206
00210 GZ_DIST_EXPORT gzBool sendEvent(gzDistEvent* event, const gzDistSessionPtr& session);
00211
00213
00221 GZ_DIST_EXPORT gzBool subscribeObjects(gzType* classType, const gzDistSessionPtr& session, gzBool notifyExisting = FALSE, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00222
00224
00230 GZ_DIST_EXPORT gzBool unsubscribeObjects(gzType* classType, const gzDistSessionPtr& session, gzInt timeOut = GZ_DIST_SYNCHRONOUS);
00231
00233
00240 GZ_DIST_EXPORT gzBool subscribeAttributes(const gzDistObjectPtr& object, gzBool notifyExisting = FALSE, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00241
00243
00248 GZ_DIST_EXPORT gzBool unsubscribeAttributes(const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_SYNCHRONOUS);
00249
00251
00259 GZ_DIST_EXPORT gzBool subscribeAttributeValue(const gzString& attributeName, const gzDistObjectPtr& object, gzBool notifyExisting = FALSE, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00260
00262
00267 GZ_DIST_EXPORT gzBool subscribeAttributeValue(const gzDistObjectPtr& object, gzBool notifyExisting = FALSE, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00268
00270
00274 GZ_DIST_EXPORT gzBool unsubscribeAttributeValue(const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00275
00277
00290 GZ_DIST_EXPORT gzBool subscribeAttributeValue(const gzDistTransactionPtr& transaction, const gzDistObjectPtr& object, gzBool notifyExisting = FALSE, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00291
00293
00307 GZ_DIST_EXPORT gzBool subscribeAttributeValue(const gzDistNotificationSet& attributes, const gzDistObjectPtr& object, gzBool notifyExisting = FALSE, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00308
00310
00317 GZ_DIST_EXPORT gzBool unsubscribeAttributeValue(const gzString& attributeName, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_SYNCHRONOUS);
00318
00320
00328 GZ_DIST_EXPORT gzBool unsubscribeAttributeValue(const gzDistTransactionPtr& transaction, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00329
00331
00341 GZ_DIST_EXPORT gzBool updateObject(const gzDistTransactionPtr& transaction, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00342
00344
00352 GZ_DIST_EXPORT gzBool updateObject(const gzString& attributeName, const gzDynamicType& value, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00353
00355
00363 GZ_DIST_EXPORT gzBool removeAttributes(const gzDistTransactionPtr& transaction, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00364
00366
00372 GZ_DIST_EXPORT gzBool removeAttribute(const gzString& attributeName, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00373
00375
00386 GZ_DIST_EXPORT gzBool addObject(const gzDistObjectPtr& object, const gzDistSessionPtr& session, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00387
00389
00396 GZ_DIST_EXPORT gzDistObjectPtr findObject(const gzString& objectName, const gzDistSessionPtr& session);
00397
00399
00410 GZ_DIST_EXPORT gzDistObjectPtr waitForObject(const gzString& objectName, const gzDistSessionPtr& session, gzInt timeOut = 10);
00411
00413
00419 GZ_DIST_EXPORT gzBool removeObject(const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00420
00422
00435 GZ_DIST_EXPORT gzBool requestOwnership(const gzString& attributeName, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00436
00438
00447 GZ_DIST_EXPORT gzBool dropOwnership(const gzString& attributeName, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00448
00450
00459 GZ_DIST_EXPORT gzBool pullOwnership(const gzString& attributeName, const gzDistObjectPtr& object, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00460
00462
00465 GZ_DIST_EXPORT gzVoid setAccumulateTick(gzBool accumulate);
00466
00468
00469
00470
00471
00472 GZ_DIST_EXPORT gzBool hasPendingData(gzBool outQueue = TRUE);
00473
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 GZ_DIST_EXPORT gzDynamicType invoke(const class gzDistInvokeMessage& message, gzBool synchronous = FALSE);
00485
00486 protected:
00487
00489
00493 virtual gzVoid onClientTick() {}
00494
00496
00498 virtual gzBool canProcessClientMessages() {return TRUE;}
00499
00500
00501
00503
00508 virtual gzVoid onEvent(gzDistEvent* event) {}
00509
00511
00517 virtual gzVoid onNewObject(gzDistObject* object, gzDistSession* session) {}
00518
00520
00525 virtual gzVoid onRemoveObject(gzDistObject* object, gzDistSession* session) {}
00526
00528
00535 virtual gzVoid onUpdateAttributes(const gzDistNotificationSet& attributes, gzDistObject* object, gzDistSession* session) {}
00536
00538
00544 virtual gzVoid onNewAttributes(const gzDistNotificationSet& attributes, gzDistObject* object, gzDistSession* session) {}
00545
00547
00553 virtual gzVoid onRemoveAttributes(const gzDistNotificationSet& attributes, gzDistObject* object, gzDistSession* session) {}
00554
00556
00561 virtual gzVoid onNewSession(gzDistSession* session) {}
00562
00564
00568 virtual gzVoid onRemoveSession(gzDistSession* session) {}
00569
00571
00578 virtual gzVoid onGrantOwnership(const gzString& attributeName, gzDistObject* object, gzDistSession* session) {}
00579
00581
00588 virtual gzVoid onDropOwnership(const gzString& attributeName, gzDistObject* object, gzDistSession* session) {}
00589
00591
00600 virtual gzVoid onRequestOwnership(const gzString& attributeName, gzDistObject* object, const gzDistClientID& requester, gzDistSession* session) {}
00601
00603
00609 virtual gzVoid onSystemShutdown() {}
00610
00612
00613 virtual gzVoid onDebugMessage(class gzDistDebugNotification* notification) {}
00614
00616
00617
00618 virtual gzDynamicType onInvoke(const gzDistInvokeMessage& message) { GZ_DIST_ASSERT(FALSE); return 0.0; }
00619
00620 private:
00621 gzVoid create();
00622
00623
00624 gzVoid addClientMessage(gzDistNotification* notification);
00625
00626
00627 gzBool processClientMessages();
00628
00629
00630 gzVoid addOutMessage(gzDistClientMessage* message, gzBool prio = FALSE);
00631
00632
00633
00634 gzBool waitAck(gzDistClientMessage* message, gzInt timeOut);
00635
00636
00637 gzVoid switchList(gzDistClientMessageList** list);
00638
00639
00640
00641 gzUInt switchNotificationList();
00642
00643 gzVoid onNotification(gzDistNotification* notification);
00644
00645 gzVoid addToTransaction(gzDistNotificationData* data);
00646
00647
00648 gzVoid setTransaction(gzDistNotificationSet* data);
00649
00650 gzVoid endTransaction(const gzDistNotificationType type, gzDistObject* object);
00651
00652
00653 gzDistClientMessageList* getManagerDataList();
00654
00655
00656 gzVoid dropManagerDataList();
00657
00658 gzBool isBoosted();
00659
00660 gzULong getThreadPoolId();
00661
00662
00663
00664
00665 const gzDistClientID m_identification;
00666
00667
00668
00669 gzDistNotificationList* m_clientNotificationList;
00670
00671
00672 gzDistNotificationList* m_managerNotificationList;
00673
00674
00675 gzMutex m_clientNotificationListMutex;
00676
00677
00678 gzMutex m_managerNotificationListMutex;
00679
00680
00681
00682 gzDistClientMessageList* m_managerProcessList;
00683
00684
00685 gzDistClientMessageList* m_clientSendList;
00686
00687
00688 gzMutex m_managerProcessListMutex;
00689
00690
00691 gzMutex m_clientSendListMutex;
00692
00693
00694
00695 gzDouble m_clientTickInterval;
00696
00697
00698 gzDouble m_nextTickTime;
00699
00700
00701 gzDouble m_lastTickTime;
00702
00703
00704 gzULong m_threadPoolId;
00705
00706
00707 class gzDistThreadInterface* m_thread;
00708
00709
00710
00711 gzDistNotificationSet* m_transactionData;
00712
00713
00714 gzBool m_skipTick;
00715
00716
00717 gzBool m_initialized;
00718
00719 gzBool m_responseBoost;
00720
00721
00722 gzBool m_processing;
00723 };
00724
00725
00726
00727 enum gzDistClientMessageType
00728 {
00729 GZ_CLIENT_MESSAGE_TYPE_JOIN_SESSION = 1,
00730 GZ_CLIENT_MESSAGE_TYPE_RESIGN_SESSION,
00731 GZ_CLIENT_MESSAGE_TYPE_SEND_EVENT,
00732 GZ_CLIENT_MESSAGE_TYPE_ADD_OBJECT,
00733 GZ_CLIENT_MESSAGE_TYPE_REMOVE_OBJECT,
00734 GZ_CLIENT_MESSAGE_TYPE_SUBSCRIBE_OBJECT,
00735 GZ_CLIENT_MESSAGE_TYPE_UNSUBSCRIBE_OBJECT,
00736 GZ_CLIENT_MESSAGE_TYPE_SUBSCRIBE_EVENT,
00737 GZ_CLIENT_MESSAGE_TYPE_UNSUBSCRIBE_EVENT,
00738 GZ_CLIENT_MESSAGE_TYPE_SUBSCRIBE_NEW_ATTRIBUTES,
00739 GZ_CLIENT_MESSAGE_TYPE_UNSUBSCRIBE_NEW_ATTRIBUTES,
00740 GZ_CLIENT_MESSAGE_TYPE_SUBSCRIBE_ATTRIBUTE,
00741 GZ_CLIENT_MESSAGE_TYPE_UNSUBSCRIBE_ATTRIBUTE,
00742 GZ_CLIENT_MESSAGE_TYPE_SUBSCRIBE_SESSIONS,
00743 GZ_CLIENT_MESSAGE_TYPE_UNSUBSCRIBE_SESSIONS,
00744 GZ_CLIENT_MESSAGE_TYPE_GET_SESSION,
00745 GZ_CLIENT_MESSAGE_TYPE_GET_ADD_SESSION,
00746 GZ_CLIENT_MESSAGE_TYPE_REMOVE_SESSION,
00747 GZ_CLIENT_MESSAGE_TYPE_UPDATE_OBJECT,
00748 GZ_CLIENT_MESSAGE_TYPE_REMOVE_ATTRIBUTES,
00749 GZ_CLIENT_MESSAGE_TYPE_REQUEST_OWNERSHIP,
00750 GZ_CLIENT_MESSAGE_TYPE_DROP_OWNERSHIP,
00751 GZ_CLIENT_MESSAGE_TYPE_PULL_OWNERSHIP
00752 };
00753
00754 GZ_DIST_DECLARE_MEMBASE(gzDistClientMessage);
00755
00756
00757 class gzDistClientMessage : public gzDistThreadSafeReference GZ_DIST_MEMBASE(gzDistClientMessage)
00758 {
00759 public:
00760 GZ_DIST_MEMBASE_IMP(gzDistClientMessage);
00761
00762 GZ_DIST_MEMBASE_CALL(gzDistClientMessage);
00763
00764
00765 gzDistClientMessage(const gzDistClientMessageType type, const gzDistSessionPtr& reference, gzBool ack);
00766
00767
00768 gzDistClientMessage(const gzDistClientMessageType type, const gzDistSessionPtr& session, gzType* classType, gzBool ack, gzBool notifyExisting = FALSE);
00769
00770
00771 gzDistClientMessage(const gzDistClientMessageType type, const gzDistObjectPtr& object, const gzString& attributeName, gzBool ack, gzBool notifyExisting = FALSE);
00772
00773
00774 gzDistClientMessage(const gzDistClientMessageType type, const gzDistThreadSafeReferencePtr& ref, const gzDistThreadSafeReferencePtr& addRef, gzBool ack, gzBool notifyExisting = FALSE);
00775
00776
00777 virtual ~gzDistClientMessage();
00778
00779
00780 gzDistSession* getSession();
00781
00782
00783 gzDistObject* getObject();
00784
00785
00786 gzDistEvent* getEvent();
00787
00788
00789 gzDistTransaction* getTransaction();
00790
00791
00792 gzVoid getTransaction(gzDistTransaction* transaction);
00793
00794
00795 gzString* m_attributeName;
00796
00797
00798 gzType* m_classType;
00799
00800
00801 gzDistClientMessageType m_messageType;
00802
00803
00804 gzBool m_notifyExisting;
00805
00806
00807 gzBool m_acknowledge;
00808
00809
00810 gzBool m_result;
00811
00812 private:
00813
00814
00815 gzDistThreadSafeReferencePtr m_reference;
00816
00817
00818 gzDistThreadSafeReferencePtr m_additional_ref;
00819
00820 };
00821
00823
00824 class gzDistInvokeMessage
00825 {
00826 public:
00827 GZ_DIST_EXPORT gzDistInvokeMessage(){}
00828 GZ_DIST_EXPORT gzDistInvokeMessage(gzULong type, const gzDynamicType& data) : messageType(type), messageData(data) {}
00829 GZ_DIST_EXPORT gzDistInvokeMessage(gzULong type) : messageType(type) {}
00830 GZ_DIST_EXPORT ~gzDistInvokeMessage(){}
00831
00832 gzULong messageType;
00833 gzDynamicType messageData;
00834 };
00835
00836 #endif
00837