1 // Copyright (C) 2009 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #ifndef HLAInteractionClass_hxx
19 #define HLAInteractionClass_hxx
25 #include <simgear/structure/SGWeakReferenced.hxx>
27 #include "HLADataElement.hxx"
28 #include "HLADataType.hxx"
29 #include "HLATypes.hxx"
33 class RTIInteractionClass;
37 class HLAInteractionClass : public SGWeakReferenced {
39 HLAInteractionClass(const std::string& name, HLAFederate* federate);
40 virtual ~HLAInteractionClass();
42 const std::string& getName() const;
44 /// return the federate this interaction class belongs to
45 const SGWeakPtr<HLAFederate>& getFederate() const;
47 HLASubscriptionType getSubscriptionType() const;
48 void setSubscriptionType(HLASubscriptionType subscriptionType);
50 HLAPublicationType getPublicationType() const;
51 void setPublicationType(HLAPublicationType publicationType);
53 unsigned getNumParameters() const;
54 unsigned addParameter(const std::string& name);
56 unsigned getParameterIndex(const std::string& name) const;
57 std::string getParameterName(unsigned index) const;
59 const HLADataType* getParameterDataType(unsigned index) const;
60 void setParameterDataType(unsigned index, const SGSharedPtr<const HLADataType>& dataType);
62 HLADataElement::IndexPathPair getIndexPathPair(const HLADataElement::StringPathPair& stringPathPair) const;
63 HLADataElement::IndexPathPair getIndexPathPair(const std::string& path) const;
65 /// Get the attribute data element index for the given path, return true if successful
66 bool getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const;
67 HLADataElementIndex getDataElementIndex(const std::string& path) const;
69 virtual bool subscribe();
70 virtual bool unsubscribe();
72 virtual bool publish();
73 virtual bool unpublish();
76 HLAInteractionClass(const HLAInteractionClass&);
77 HLAInteractionClass& operator=(const HLAInteractionClass&);
79 void _setRTIInteractionClass(RTIInteractionClass* interactionClass);
80 void _resolveParameterIndex(const std::string& name, unsigned index);
81 void _clearRTIInteractionClass();
85 Parameter(const std::string& name) : _name(name) {}
87 SGSharedPtr<const HLADataType> _dataType;
89 typedef std::vector<Parameter> ParameterVector;
90 typedef std::map<std::string,unsigned> NameIndexMap;
92 /// The parent federate.
93 SGWeakPtr<HLAFederate> _federate;
95 /// The rti class if already instantiated.
96 RTIInteractionClass* _rtiInteractionClass;
98 /// The interaction class name
101 /// The configured subscription and publication type
102 HLASubscriptionType _subscriptionType;
103 HLAPublicationType _publicationType;
105 /// The parameter data
106 ParameterVector _parameterVector;
107 /// The mapping from parameter names to parameter indices
108 NameIndexMap _nameIndexMap;
110 friend class HLAFederate;
113 } // namespace simgear