GizmoDistribution

gzDistAttribute.h

00001 //*****************************************************************************
00002 // File         : gzDistAttribute.h
00003 // Module       : gzDistribution
00004 // Description  : Declaration of attributes in gzDistEvent and gzDistObject
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  040113  Created file    
00019 //
00020 //*****************************************************************************
00021 #ifndef __GZ_DIST_ATTRIBUTE_H__
00022 #define __GZ_DIST_ATTRIBUTE_H__
00023 
00024 // Includes
00025 #include "gzDistBase.h"
00026 
00027 // Forward declarations.
00028 class gzDistClientInterface;
00029 
00030 //---------------------------- gzDistAttribute --------------------------------
00031 
00032 GZ_DIST_DECLARE_MEMBASE_EXPORT(gzDistAttribute, GZ_DIST_EXPORT);
00033 
00035 
00040 class gzDistAttribute GZ_DIST_MEMBASE_SINGLE(gzDistAttribute)
00041 {
00042     public:
00043 
00044         GZ_DIST_MEMBASE_IMP(gzDistAttribute);
00045 
00046         GZ_DIST_MEMBASE_CALL(gzDistAttribute);
00047 
00049         GZ_DIST_EXPORT gzDistAttribute(const gzString& name);
00050 
00052         GZ_DIST_EXPORT gzDistAttribute(const gzString& name, const gzDynamicType& value);
00053 
00055         GZ_DIST_EXPORT gzDistAttribute(const gzDistAttribute& attribute);
00056 
00058         GZ_DIST_EXPORT virtual ~gzDistAttribute();
00059 
00061         GZ_DIST_EXPORT const gzString& getName() const;
00062         
00064         GZ_DIST_EXPORT const gzDynamicType& getValue() const;
00065 
00067         GZ_DIST_EXPORT gzBool store(gzSerializeAdapter* adapter);
00068 
00070         GZ_DIST_EXPORT gzBool restore(gzSerializeAdapter* adapter);
00071     
00072 
00073 //  private:
00074 
00075         gzULong getDataSize() const;
00076 
00077         gzDistAttribute(){}
00078 
00079         // The attribute value
00080         gzDynamicType value;
00081 
00082         // The name of the attribute
00083         gzSerializeString name;
00084 };
00085 
00086 //-------------------------- gzDistObjectAttribute -----------------------------
00087 
00088 // Internal object attribute class
00089 class gzDistObjectAttribute : public gzDistThreadSafeReference
00090 {
00091     friend class gzDistObject;
00092     friend class gzDistSession;
00093 
00094     public:
00095 
00096         // Constructor
00097         GZ_DIST_EXPORT gzDistObjectAttribute(const gzString& name, gzDistObject* parent);
00098 
00099         // Constructor
00100         GZ_DIST_EXPORT gzDistObjectAttribute(const gzString& name, const gzDynamicType& value, gzDistObject* parent);
00101 
00102         // Copy constructor
00103         GZ_DIST_EXPORT gzDistObjectAttribute(const gzDistObjectAttribute& attribute);
00104 
00105         // Destructor
00106         GZ_DIST_EXPORT virtual ~gzDistObjectAttribute();
00107 
00108         // Clone the attribute
00109         GZ_DIST_EXPORT virtual gzReference* clone() const;
00110 
00111         // Get the name of the attribute
00112         const gzString& getName() const;
00113 
00114         // For internal use only
00115         const gzDistAttribute& attribute() const;
00116 
00117     private:
00118 
00119         // Get the attribute value
00120         gzDynamicType getValue() const;
00121 
00122         // Get the attribute value
00123         gzVoid getValue(gzDynamicType& value) const;
00124 
00125         // Get the type of the attribute value
00126         const gzString& getDynamicType() const;
00127 
00128         // Get the number in the attribute value
00129         gzDouble getNumber() const;
00130 
00131         // Get the value as GUID
00132         gzGUID getGuid() const;
00133 
00134         // Get the value as GUID
00135         gzVoid getGuid(gzGUID& guid) const;
00136 
00137         // Get the string in the attribute value
00138         gzVoid getString(gzString& string) const;
00139 
00140         // Get a ref pointer to the referenced object in attribute value
00141         gzVoid getReference(gzRefPointer<gzReference>& reference) const;
00142 
00143         // Get the pointer in attribute value
00144         gzVoid* getPointer() const;
00145 
00146         // Serialize attribute including owners to adapter.
00147         gzBool store(gzSerializeAdapter* adapter);
00148 
00149         // Serialize adapter data (including owners) to attribute.
00150         gzBool restore(gzSerializeAdapter* adapter);
00151 
00152         // Constructor used in serialisazion.
00153         gzDistObjectAttribute(gzDistObject* parent);
00154 
00155         // Get the object containing this attribute
00156         gzDistObject* getObject();
00157 
00158         // Check if the client is a subscriber of this attribute.
00159         gzBool isSubscriber(gzDistClientInterface* client) const;
00160 
00161         // Set the attribute value
00162         gzVoid setValue(const gzDynamicType& value);
00163 
00164         // Subscribe of instance of the attribute in the obejct
00165         gzBool subscribe(gzDistClientInterface* client);
00166 
00167         // Unsubscribe of instance of the attribute in the obejct
00168         gzBool unsubscribe(gzDistClientInterface* client);
00169 
00170         // Remove all attribute subscribers
00171         gzVoid removeSubscribers();
00172 
00173         // Remove all references to client.
00174         // Returns TRUE if client was owner of attribute.
00175         gzBool resign(gzDistClientInterface* client);
00176 
00177         // Set the owner off attribute independent of requests.
00178         // If the new owner exist in request queue it will be removed.
00179         gzVoid setOwner(const gzDistClientID& owner);
00180 
00181         // Get the owner of the attribute. If no owner, a null-instance will be returned.
00182         const gzDistClientID& getOwner();
00183 
00184         // Set next requesting owner.
00185         gzVoid setNextOwner();
00186 
00187         // Returns TRUE if client is owner.
00188         gzBool isOwner(const gzDistClientID& clientId) const;
00189 
00190         // Returns TRUE if client is requesting the ownership.
00191         gzBool isOwnershipRequester(const gzDistClientID& clientId) const;
00192 
00193         // Puts the client in request queue for ownership.
00194         // If no owner, client will be owner.
00195         // Returns owner after request.
00196         const gzDistClientID& requestOwnership(const gzDistClientID& clientId);
00197 
00198         // Returns first entry in gzDistOwnerData::m_ownerRequests if exist.
00199         gzDistClientID* getNextOwnerRequester();
00200 
00201         // Remove client from ownership request queue.
00202         gzBool removeOwnershipRequest(const gzDistClientID& clientId);
00203 
00204         // Checks if there is another owner than client.
00205         // The method returns TRUE if the attribute is "un-owned" or owned by the client, otherwise FALSE.
00206         gzBool isAllowedToUpdate(const gzDistClientID& clientId);
00207 
00208         // Release all references to object, clients etc.       
00209         gzVoid release();
00210 
00211         // Clear all ownership requests.
00212         // If 'destroy' is FALSE, the items will not be deleted, only removed.
00213         gzVoid clearOwnershipRequests(gzBool destroy = TRUE);
00214 
00215         // Clean up all ownership etc. referring to instance.
00216         gzVoid cleanUpInstance(const gzDistInstanceID& instance);
00217 
00218     // Members:
00219 
00220         // A list containing all subscribers of this attribute.
00221         gzList<gzDistClientInterface> m_subscribers;
00222 
00223         // The owner of the attribute
00224         struct gzDistOwnerData
00225         {
00226             gzDistClientID m_owner;
00227             gzList<gzDistClientID> m_ownerRequests;
00228 
00229         }* m_ownerData;
00230         
00231         // A pointer to the owner object.
00232         gzDistObject* m_parent;
00233 
00234         // The attribute
00235         gzDistAttribute m_attribute;
00236 };
00237 
00238 
00239 //-------------------------- gzDistEventAttribute ------------------------------
00240 
00241 GZ_DIST_DECLARE_MEMBASE_EXPORT(gzDistEventAttribute, GZ_DIST_EXPORT);
00242 
00243 // Internal event attribute class
00244 class gzDistEventAttribute GZ_DIST_MEMBASE_SINGLE(gzDistEventAttribute)
00245 {
00246     friend class gzDistEvent;
00247 
00248     public:
00249 
00250         GZ_DIST_MEMBASE_IMP(gzDistEventAttribute);
00251 
00252         GZ_DIST_MEMBASE_CALL(gzDistEventAttribute);
00253 
00254         // Constructor
00255         GZ_DIST_EXPORT gzDistEventAttribute(const gzString& name, const gzDynamicType& value);
00256 
00257         // Constructor
00258         GZ_DIST_EXPORT gzDistEventAttribute(const gzDistAttribute& data);
00259 
00260         // Constructor that takes name and value from the gzDistObjectAttribute
00261         GZ_DIST_EXPORT gzDistEventAttribute(gzDistObjectAttribute* objectAttribute);
00262 
00263         // Constructor that takes the value from the gzDistObjectAttribute
00264         GZ_DIST_EXPORT gzDistEventAttribute(const gzString& name, gzDistEventAttribute* objectAttribute);
00265 
00266         // Copy constructor
00267         GZ_DIST_EXPORT gzDistEventAttribute(const gzDistEventAttribute& attribute);
00268 
00269         // Destructor
00270         GZ_DIST_EXPORT virtual ~gzDistEventAttribute();
00271 
00272         // For internal use only
00273         const gzDistAttribute& attribute() const;
00274 
00275     private:
00276 
00277         gzDistEventAttribute();
00278 
00279         // Get the name of the attribute
00280         const gzString& getName() const;        
00281 
00282         // Get the value as number
00283         gzDouble getNumber() const;
00284 
00285         // Get the value as string
00286         gzVoid getString(gzString& string) const;
00287 
00288         // Get the value as GUID
00289         gzGUID getGuid() const;
00290 
00291         // Get the value as GUID
00292         gzVoid getGuid(gzGUID& guid) const;
00293 
00294         // Get the value as string
00295         gzString getString() const;
00296 
00297         // Get the type
00298         const gzString& getDynamicType() const;
00299 
00300         // Serialize attribute to adapter.
00301         gzBool store(gzSerializeAdapter* adapter);
00302 
00303         // Serialize adapter data to attribute.
00304         gzBool restore(gzSerializeAdapter* adapter);
00305 
00306         gzVoid setValue(const gzDynamicType& value);
00307 
00308     // Members:
00309 
00310         gzDistAttribute m_attribute;
00311 };
00312 
00313 
00314 #endif

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