GizmoDistribution

gzDistObject.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzDistObject.h
00003 // Module       : gzDistribution
00004 // Description  : Definition of a gzDistributionObject
00005 // Author       : Christian Andersson   
00006 // Product      : GizmoDistribution 2.1.1
00007 //      
00008 // Copyright © 2004 - Saab Training Systems AB, Sweden
00009 //          
00010 // NOTE:    GizmoDistribution is a toolkit used for implementing distributed 
00011 //          objects and events in C++
00012 //
00013 //
00014 // Revision History...
00015 //                                  
00016 // Who  Date    Description
00017 //                                  
00018 // CAN  031021  Created file
00019 //
00020 //*****************************************************************************
00021 #ifndef __GZ_DIST_OBJECT_H__
00022 #define __GZ_DIST_OBJECT_H__
00023 
00028 // Includes
00029 #include "gzDistBase.h"
00030 #include "gzDistAttribute.h"
00031 
00032 
00033 //----------------------------- gzDistObject ----------------------------------
00034 
00035 //*****************************************************************************
00036 // Class    : gzDistObject
00037 //                                  
00038 // Purpose  : The base def class of a distribution object
00039 //                                  
00040 // Notes    : - 
00041 //                                  
00042 // Revision History...                          
00043 //
00044 // Who  Date    Description                     
00045 //                                  
00046 // CAN  031021  Created 
00047 //                                  
00048 //*****************************************************************************
00050 
00073 class gzDistObject : public gzDistThreadSafeReference
00074 {
00075     friend class gzDistManager;
00076     friend class gzDistSession;
00077     friend class gzDistObjectAttribute;
00078     friend class gzDistObjectAttributeIterator;
00079     friend class gzDistSessionObjectIterator;
00080 
00081     public:
00082 
00083         GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_DIST_EXPORT);
00084 
00086 
00087         GZ_DIST_EXPORT explicit gzDistObject(const gzString& name);
00088 
00090         GZ_DIST_EXPORT gzDistObject(const gzDistObject& object);
00091 
00093         GZ_DIST_EXPORT virtual ~gzDistObject();
00094 
00096 
00098         GZ_DIST_EXPORT gzDouble getAttributeNumber(const gzString& attributeName) const;
00099 
00101 
00106         GZ_DIST_EXPORT gzBool getAttributeNumber(const gzString& attributeName, gzDouble& number) const;
00107 
00109 
00111         GZ_DIST_EXPORT gzString getAttributeString(const gzString& attributeName) const;
00112 
00114 
00119         GZ_DIST_EXPORT gzBool getAttributeString(const gzString& attributeName, gzString& string) const;
00120 
00122 
00125         GZ_DIST_EXPORT gzGUID getAttributeGuid(const gzString& attributeName) const;
00126 
00128 
00133         GZ_DIST_EXPORT gzBool getAttributeGuid(const gzString& attributeName, gzGUID& guid) const;
00134 
00136 
00141         GZ_DIST_EXPORT gzBool setAttributeValue(const gzString& attributeName, const gzDynamicType& value);
00142 
00144 
00146         GZ_DIST_EXPORT gzDynamicType getAttributeValue(const gzString& attributeName) const;
00147 
00149 
00152         GZ_DIST_EXPORT gzBool getAttributeValue(const gzString& attributeName, gzDynamicType& value) const;
00153 
00155 
00159         GZ_DIST_EXPORT gzBool hasAttribute(const gzString& attributeName) const;
00160 
00162 
00165         GZ_DIST_EXPORT gzDistSessionPtr getSession() const;
00166 
00168 
00171         GZ_DIST_EXPORT const gzString& getName() const;
00172 
00174 
00176         GZ_DIST_EXPORT virtual gzReference* clone() const;
00177 
00179 
00182         GZ_DIST_EXPORT gzBool store(gzSerializeAdapter* adapter) const;
00183 
00185 
00189         GZ_DIST_EXPORT gzBool restore(gzSerializeAdapter* adapter);
00190 
00192         GZ_DIST_EXPORT gzUInt getNumberOfAttributes() const;
00193 
00195 
00201         GZ_DIST_EXPORT gzBool isOwnerOf(const gzString& attributeName, const gzDistClientID& clientID) const;
00202 
00204 
00210         GZ_DIST_EXPORT gzDistClientID getOwnerOf(const gzString& attributeName) const;
00211 
00213 
00217         GZ_DIST_EXPORT gzBool setName(const gzString& objectName);
00218 
00220         /*  \return TRUE if the object belong to a session, otherwise FALSE.*/
00221         GZ_DIST_EXPORT gzBool inSession() const;
00222 
00224 
00225         GZ_DIST_EXPORT gzVoid clear();
00226     
00227     private:
00228 
00229         // Remove all subscriptions, ownership and ownersip requests.
00230         // Returns a pointer to a list of attribute that was owned by client. If there wasn't any, the return value is NULL.
00231         // Note: The list must be destroyed by the caller.
00232         gzList<gzDistObjectAttribute>* resign(gzDistClientInterface* client);
00233 
00234         // Subscribe on an attribute
00235         gzBool subscribeAttributeValue(const gzString& attributeName, gzDistClientInterface* client);
00236 
00237         // Unsubscribe on an attribute
00238         gzBool unsubscribeAttributeValue(const gzString& attributeName, gzDistClientInterface* client);
00239 
00240         // Subscribe on an attribute
00241         gzBool subscribeNewAttributes(gzDistClientInterface* client);
00242 
00243         // Unsubscribe on an attribute
00244         gzBool unsubscribeNewAttributes(gzDistClientInterface* client);
00245 
00246         // Removes all subscriptions by client.
00247         gzVoid removeSubscriptions(gzDistClientInterface* client);
00248 
00249         // Remove all subscriptions, and sets m_session to NULL.
00250         gzVoid release();
00251 
00252         // Set m_evaluateHash
00253         gzVoid setEvalHash(const gzUInt hash);
00254 
00255         // Get m_evaluateHash
00256         const gzUInt getEvalHash() const;
00257 
00258         // Returns a pointer to the attribute whith the given name.
00259         gzDistObjectAttribute* getAttribute(const gzString& attributeName);
00260 
00261         // Set curent session
00262         gzVoid setSession(gzDistSession* session);
00263 
00264         // Checks if there is another owner than client.
00265         // The method returns TRUE if the attribute is "un-owned" or owned by the client, otherwise FALSE.
00266         gzBool isAllowedToUpdate(const gzString& attributeName, const gzDistClientID& clientId);
00267 
00268         // Returns a list containing all attributes that client is owner of or is requesting ownership of.
00269         // Note: The list must be destroyed by the caller.
00270         gzList<gzDistObjectAttribute>* getOwnerAffectedAttributes(gzDistClientInterface* client);
00271 
00272         // Increase m_ownedAttributes by one.
00273         gzVoid increaseOwners();
00274 
00275         // Decrease m_ownedAttributes by one.
00276         gzVoid decreaseOwners();
00277 
00278         // Remove attributes from object.
00279         gzBool removeAttribute(const gzString& attributeName);
00280 
00281         // Add attributes to object.
00282         gzVoid addAttribute(gzDistObjectAttribute* attribute);
00283 
00284         // Lock the object and its attributes
00285         gzVoid lock() const;
00286 
00287         // Unlock the object and its attributes
00288         gzVoid unLock() const;
00289 
00290         gzVoid cleanUpInstance(const gzDistInstanceID& instance);
00291 
00292         // Internal "get session".
00293         gzDistSession* session() const;
00294 
00295         // Get next object in order.
00296         gzDistObject* getNext() const;
00297 
00298         // Get previous object in order.
00299         gzDistObject* getPrevious() const;
00300 
00301         // Set previous object in order.
00302         gzVoid setPrevious(gzDistObject* parent);
00303 
00304         // Set next object in order.
00305         gzVoid setNext(gzDistObject* next);
00306 
00307         // Remove the link order.
00308         gzVoid removeLink();
00309 
00310     // Members:
00311 
00312         // Dictionary containing all attributes.
00313         mutable gzRefDict<gzString, gzDistObjectAttribute> m_attributes;
00314 
00315         // This list contain clients that are interested in new/removed attributes.
00316         gzList<gzDistClientInterface> m_subscribers;
00317 
00318         // Mutex for m_attributes and m_session.
00319         mutable gzMutex m_locker;
00320 
00321         // The name of the object.
00322         gzString m_name;
00323 
00324         // The session the object is in.
00325         gzDistSession* m_session;
00326 
00327         // This member tells if the object has been accepted by a session's evaluator. If so, this value is not zero.
00328         // The value of this member will get the hash value from the name of the session it is evaluated by.
00329         // The value must match with the session to be accepted to the session.
00330         gzULong m_evaluateHash;
00331         
00332         // This member tells how many of the object's attributes that are owned by any client.
00333         // The purpose is to quickly se if any attributes are owned by any client.
00334         gzUInt m_ownedAttributes;
00335 
00336         // This makes it possible to have an order of all objects in a session.
00337         struct Link
00338         {
00339             gzDistObject* prev;
00340             gzDistObject* next;
00341         } m_link;
00342 };
00343 
00344 
00345 //-------------------------- gzDistObjectAttributeIterator --------------------
00346 
00347 //*****************************************************************************
00348 // Class    : gzDistObjectAttributeIterator
00349 //                                  
00350 // Purpose  : Iterator for object attributes
00351 //                                  
00352 // Notes    : - 
00353 //                                  
00354 // Revision History...                          
00355 //
00356 // Who  Date    Description                     
00357 //                                  
00358 // CAN  031021  Created 
00359 //                                  
00360 //*****************************************************************************
00362 class gzDistObjectAttributeIterator
00363 {
00364     public:
00366 
00368         GZ_DIST_EXPORT gzDistObjectAttributeIterator(const gzDistObjectPtr& object);
00369         
00371 
00372         GZ_DIST_EXPORT ~gzDistObjectAttributeIterator();
00373 
00375 
00377         GZ_DIST_EXPORT gzBool operator()();
00378 
00380         GZ_DIST_EXPORT const gzDistAttribute& current();
00381 
00383         GZ_DIST_EXPORT gzVoid reset();
00384 
00385     private:
00386 
00387         const gzDistObjectPtr m_object;
00388         gzDictIterator<gzString, gzDistObjectAttribute> m_iterator;
00389         gzDictEntry<gzString, gzDistObjectAttribute>* m_entry;
00390         
00391         // Tells if the iterator has locked the object.
00392         gzBool m_lockedObject;
00393 };
00394 
00395 
00396 //----------------------------- gzDistTransaction ------------------------------
00397 
00398 //*****************************************************************************
00399 // Class    : gzDistTransaction
00400 //                                  
00401 // Purpose  : Transaction class definition
00402 //                                  
00403 // Notes    : - 
00404 //                                  
00405 // Revision History...                          
00406 //
00407 // Who  Date    Description                     
00408 //                                  
00409 // CAN  031021  Created 
00410 //                                  
00411 //*****************************************************************************
00412 
00413 GZ_DIST_DECLARE_MEMBASE_EXPORT(gzDistTransaction, GZ_DIST_EXPORT);
00414 
00416 
00420 class gzDistTransaction : public gzDistThreadSafeReference GZ_DIST_MEMBASE(gzDistTransaction)
00421 {
00422     friend class gzDistSession;
00423     friend class gzDistTransactionIterator;
00424 
00425     public:
00426 
00427         GZ_DIST_MEMBASE_IMP(gzDistTransaction);
00428 
00429         GZ_DIST_MEMBASE_CALL(gzDistTransaction);
00430 
00432         GZ_DIST_EXPORT gzDistTransaction();
00433 
00435         GZ_DIST_EXPORT gzDistTransaction(const gzString& attributeName, const gzDynamicType& value = gzDynamicType());
00436 
00438         GZ_DIST_EXPORT gzDistTransaction(const gzDistTransaction& transaction);
00439     
00441         GZ_DIST_EXPORT virtual ~gzDistTransaction();
00442 
00444 
00446         GZ_DIST_EXPORT virtual gzReference* clone() const;
00447 
00449 
00452         GZ_DIST_EXPORT gzVoid setAttributeValue(const gzString& attributeName, const gzDynamicType& value);
00453 
00455 
00458         GZ_DIST_EXPORT gzVoid setAttributeName(const gzString& attributeName);
00459 
00461 
00463         GZ_DIST_EXPORT gzBool hasAttribute(const gzString& attributeName) const;
00464 
00466 
00469         GZ_DIST_EXPORT gzBool getAttributeValue(const gzString& attributeName, gzDynamicType& value) const;
00470 
00472 
00474         GZ_DIST_EXPORT const gzDynamicType& getAttributeValue(const gzString& attributeName) const;
00475 
00477 
00480         GZ_DIST_EXPORT gzBool getAttributeNumber(const gzString& attributeName, gzDouble& number) const;
00481 
00483 
00486         GZ_DIST_EXPORT gzBool getAttributeString(const gzString& attributeName, gzString& string) const;
00487 
00489 
00492         GZ_DIST_EXPORT gzBool getAttributeGuid(const gzString& attributeName, gzGUID& guid) const;
00493 
00495 
00497         GZ_DIST_EXPORT gzBool removeAttribute(const gzString& attributeName);
00498 
00500 
00503         GZ_DIST_EXPORT gzBool verifyAttribute(const gzString& attributeName, const gzDynamicType& value) const;
00504 
00506 
00509         GZ_DIST_EXPORT gzBool store(gzSerializeAdapter* adapter);
00510 
00512 
00515         GZ_DIST_EXPORT gzBool restore(gzSerializeAdapter* adapter);
00516 
00518 
00519         GZ_DIST_EXPORT gzUInt entries() const;
00520 
00522 
00527         GZ_DIST_EXPORT gzBool isEditable() const;
00528 
00529         // Internally used by the client interface.
00530         // After this is called, it's impossible to set more attribute values.
00531         gzVoid setSent();
00532 
00533     private:
00534 
00535         // Todo: change gzDistAttribute to a transaction specific class (to be "optimized").
00536         mutable gzDict<gzString, gzDistAttribute> m_transactionData;
00537     
00538         gzBool m_sent;
00539 };
00540 
00542 
00543 class gzDistTransactionIterator
00544 {
00545     public:
00547         GZ_DIST_EXPORT gzDistTransactionIterator(const gzDistTransactionPtr& transaction);
00548 
00550         GZ_DIST_EXPORT ~gzDistTransactionIterator();
00551 
00553 
00556         GZ_DIST_EXPORT gzBool operator()();
00557 
00559         GZ_DIST_EXPORT const gzDistAttribute& current() const;
00560 
00562         GZ_DIST_EXPORT gzVoid reset();
00563 
00564     private:
00565         
00566         gzDictIterator<gzString, gzDistAttribute> m_iterator;
00567         gzDictEntry<gzString, gzDistAttribute>* m_entry;
00568 };
00569 
00570 //  gzDistUnknownObjectType class.
00571 /*  This class is only for internal use.*/
00572 class gzDistUnknownObjectType : public gzDistObject
00573 {
00574     public:
00575         
00576         gzDistUnknownObjectType(const gzString& typeName, const gzString& objectName);
00577         virtual ~gzDistUnknownObjectType();
00578 
00579         // Overrides gzDistObject::getType() from gzTypeInterface in gzDistObject
00580         gzType* getType() const;
00581 
00582     private:
00583         const gzType m_type;
00584 };
00585 
00586 #endif

Documentation for GizmoDistribution generated at Wed Feb 20 11:59:21 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond