X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLAObjectClass.hxx;h=d80e4f8d5988d9527e39dde7be1f85471f2bbd7b;hb=1f585d67199896749f5f532657d17afe586f6615;hp=b0db5ad1f9b40b776040ac16e899f28d5ff1a68d;hpb=44ff23b227dcc1f3efbd10a4df4d8b723165c11c;p=simgear.git diff --git a/simgear/hla/HLAObjectClass.hxx b/simgear/hla/HLAObjectClass.hxx index b0db5ad1..d80e4f8d 100644 --- a/simgear/hla/HLAObjectClass.hxx +++ b/simgear/hla/HLAObjectClass.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de +// Copyright (C) 2009 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -18,12 +18,12 @@ #ifndef HLAObjectClass_hxx #define HLAObjectClass_hxx -#include #include #include #include "HLADataType.hxx" #include "HLAObjectInstance.hxx" +#include "HLATypes.hxx" namespace simgear { @@ -32,30 +32,56 @@ class HLAFederate; class HLAObjectClass : public SGWeakReferenced { public: - HLAObjectClass(const std::string& name, HLAFederate& federate); + HLAObjectClass(const std::string& name, HLAFederate* federate); virtual ~HLAObjectClass(); - const std::string& getName() const - { return _name; } + /// Return the name of this object class + const std::string& getName() const; + /// return the federate this class belongs to + const SGWeakPtr& getFederate() const; + + /// Return the number of attributes in this object class unsigned getNumAttributes() const; + + /// Adds a new attribute to this object class, return the index + unsigned addAttribute(const std::string& name); + + /// Return the attribute index for the attribute with the given name unsigned getAttributeIndex(const std::string& name) const; + /// Return the attribute name for the attribute with the given index std::string getAttributeName(unsigned index) const; + /// Return the data type of the attribute with the given index const HLADataType* getAttributeDataType(unsigned index) const; - void setAttributeDataType(unsigned index, const HLADataType*); + /// Sets the data type of the attribute with the given index to dataType + void setAttributeDataType(unsigned index, const HLADataType* dataType); + /// Return the update type of the attribute with the given index HLAUpdateType getAttributeUpdateType(unsigned index) const; + /// Sets the update type of the attribute with the given index to updateType void setAttributeUpdateType(unsigned index, HLAUpdateType updateType); - HLADataElement::IndexPathPair getIndexPathPair(const HLADataElement::AttributePathPair&) const; + /// Return the subscription type of the attribute with the given index + HLASubscriptionType getAttributeSubscriptionType(unsigned index) const; + /// Sets the subscription type of the attribute with the given index to subscriptionType + void setAttributeSubscriptionType(unsigned index, HLASubscriptionType subscriptionType); + + /// Return the publication type of the attribute with the given index + HLAPublicationType getAttributePublicationType(unsigned index) const; + /// Sets the publication type of the attribute with the given index to publicationType + void setAttributePublicationType(unsigned index, HLAPublicationType publicationType); + + /// Return the index, path pair for the given string path pair + HLADataElement::IndexPathPair getIndexPathPair(const HLADataElement::StringPathPair&) const; + /// Return the index, path pair for the given string path HLADataElement::IndexPathPair getIndexPathPair(const std::string& path) const; - bool subscribe(const std::set& indexSet, bool active); - bool unsubscribe(); + virtual bool subscribe(); + virtual bool unsubscribe(); - bool publish(const std::set& indexSet); - bool unpublish(); + virtual bool publish(); + virtual bool unpublish(); // Object instance creation and destruction class InstanceCallback : public SGReferenced { @@ -74,6 +100,16 @@ public: const SGSharedPtr& getInstanceCallback() const { return _instanceCallback; } + virtual void discoverInstance(HLAObjectInstance& objectInstance, const RTIData& tag); + virtual void removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag); + virtual void registerInstance(HLAObjectInstance& objectInstance); + virtual void deleteInstance(HLAObjectInstance& objectInstance); + + // Is called by the default registration callback if installed + // Should register the already known object instances of this class. + virtual void startRegistration() const; + virtual void stopRegistration() const; + // Handles startRegistrationForObjectClass and stopRegistrationForObjectClass events class RegistrationCallback : public SGReferenced { public: @@ -87,43 +123,63 @@ public: const SGSharedPtr& getRegistrationCallback() const { return _registrationCallback; } - // Is called by the default registration callback if installed - void startRegistration() const; - void stopRegistration() const; + /// Create a new instance of this class. + virtual HLAObjectInstance* createObjectInstance(const std::string& name); -protected: - virtual HLAObjectInstance* createObjectInstance(RTIObjectInstance* rtiObjectInstance); + virtual void createAttributeDataElements(HLAObjectInstance& objectInstance); + virtual HLADataElement* createAttributeDataElement(HLAObjectInstance& objectInstance, unsigned index); private: + HLAObjectClass(const HLAObjectClass&); + HLAObjectClass& operator=(const HLAObjectClass&); + + void _setRTIObjectClass(RTIObjectClass* objectClass); + void _resolveAttributeIndex(const std::string& name, unsigned index); + void _clearRTIObjectClass(); + // The internal entry points from the RTILObjectClass callback functions - void discoverInstance(RTIObjectInstance* objectInstance, const RTIData& tag); - void removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag); - void registerInstance(HLAObjectInstance& objectInstance); - void deleteInstance(HLAObjectInstance& objectInstance); - - void discoverInstanceCallback(HLAObjectInstance& objectInstance, const RTIData& tag) const; - void removeInstanceCallback(HLAObjectInstance& objectInstance, const RTIData& tag) const; - void registerInstanceCallback(HLAObjectInstance& objectInstance) const; - void deleteInstanceCallback(HLAObjectInstance& objectInstance) const; - - void startRegistrationCallback(); - void stopRegistrationCallback(); + void _discoverInstance(RTIObjectInstance* objectInstance, const RTIData& tag); + void _removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag); + void _registerInstance(HLAObjectInstance* objectInstance); + void _deleteInstance(HLAObjectInstance& objectInstance); + + void _startRegistration(); + void _stopRegistration(); + friend class HLAObjectInstance; friend class RTIObjectClass; - // The object class name + struct Attribute { + Attribute() : _subscriptionType(HLAUnsubscribed), _publicationType(HLAUnpublished), _updateType(HLAUndefinedUpdate) {} + Attribute(const std::string& name) : _name(name), _subscriptionType(HLAUnsubscribed), _publicationType(HLAUnpublished), _updateType(HLAUndefinedUpdate) {} + std::string _name; + SGSharedPtr _dataType; + HLASubscriptionType _subscriptionType; + HLAPublicationType _publicationType; + HLAUpdateType _updateType; + }; + typedef std::vector AttributeVector; + typedef std::map NameIndexMap; + + /// The parent federate. + SGWeakPtr _federate; + + /// The object class name std::string _name; - // The underlying rti dispatcher class + /// The underlying rti dispatcher class SGSharedPtr _rtiObjectClass; + /// The attribute data + AttributeVector _attributeVector; + /// The mapping from attribute names to attribute indices + NameIndexMap _nameIndexMap; + // Callback classes SGSharedPtr _instanceCallback; SGSharedPtr _registrationCallback; - // The set of active objects - typedef std::set > ObjectInstanceSet; - ObjectInstanceSet _objectInstanceSet; + friend class HLAFederate; }; } // namespace simgear