1 // Copyright (C) 2009 - 2010 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 HLAFederate_hxx
19 #define HLAFederate_hxx
23 #include "HLAObjectInstance.hxx"
24 #include "HLAObjectClass.hxx"
25 #include "HLAInteractionClass.hxx"
33 class HLAFederate : public SGWeakReferenced {
36 virtual ~HLAFederate();
44 Version getVersion() const;
45 bool setVersion(HLAFederate::Version version);
47 const std::list<std::string>& getConnectArguments() const;
48 bool setConnectArguments(const std::list<std::string>& connectArguments);
50 const std::string& getFederationExecutionName() const;
51 bool setFederationExecutionName(const std::string& federationExecutionName);
53 const std::string& getFederationObjectModel() const;
54 bool setFederationObjectModel(const std::string& federationObjectModel);
56 const std::string& getFederateType() const;
57 bool setFederateType(const std::string& federateType);
59 const std::string& getFederateName() const;
60 bool setFederateName(const std::string& federateName);
63 bool connect(Version version, const std::list<std::string>& stringList);
67 /// Create a federation execution
68 /// Semantically this methods should be static,
69 /// but the nonstatic case could reuse the connection to the server
70 bool createFederationExecution(const std::string& federation, const std::string& objectModel);
71 bool destroyFederationExecution(const std::string& federation);
72 bool createFederationExecution();
73 bool destroyFederationExecution();
75 /// Join with federateType the federation execution
76 bool join(const std::string& federateType, const std::string& federation);
80 /// Try to create and join the federation execution.
81 bool createJoinFederationExecution();
82 bool resignDestroyFederationExecution();
85 bool enableTimeConstrained();
86 bool disableTimeConstrained();
88 bool enableTimeRegulation(const SGTimeStamp& lookahead);
89 bool disableTimeRegulation();
91 bool timeAdvanceRequestBy(const SGTimeStamp& dt);
92 bool timeAdvanceRequest(const SGTimeStamp& dt);
94 bool queryFederateTime(SGTimeStamp& timeStamp);
95 bool modifyLookahead(const SGTimeStamp& timeStamp);
96 bool queryLookahead(SGTimeStamp& timeStamp);
100 bool tick(const double& minimum, const double& maximum);
102 class ObjectModelFactory {
104 virtual ~ObjectModelFactory()
107 virtual HLAObjectClass* createObjectClass(const std::string& name, HLAFederate& federate)
108 { return new HLAObjectClass(name, federate); }
109 virtual bool subscribeObjectClass(const std::string& objectClassName, const std::string& sharing)
110 { return sharing.find("Subscribe") != std::string::npos; }
111 virtual bool publishObjectClass(const std::string& objectClassName, const std::string& sharing)
112 { return sharing.find("Publish") != std::string::npos; }
113 virtual bool subscribeAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
114 { return sharing.find("Subscribe") != std::string::npos; }
115 virtual bool publishAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
116 { return sharing.find("Publish") != std::string::npos; }
120 /// Read an omt xml file
121 bool readObjectModelTemplate(const std::string& objectModel,
122 ObjectModelFactory& objectModelFactory);
124 HLAObjectClass* getObjectClass(const std::string& name);
125 const HLAObjectClass* getObjectClass(const std::string& name) const;
127 HLAInteractionClass* getInteractionClass(const std::string& name);
128 const HLAInteractionClass* getInteractionClass(const std::string& name) const;
131 SGSharedPtr<RTIFederate> _rtiFederate;
134 std::list<std::string> _connectArguments;
136 std::string _federationExecutionName;
137 std::string _federationObjectModel;
138 std::string _federateType;
139 std::string _federateName;
141 typedef std::map<std::string, SGSharedPtr<HLAObjectClass> > ObjectClassMap;
142 ObjectClassMap _objectClassMap;
144 typedef std::map<std::string, SGSharedPtr<HLAInteractionClass> > InteractionClassMap;
145 InteractionClassMap _interactionClassMap;
147 friend class HLAInteractionClass;
148 friend class HLAObjectClass;
151 } // namespace simgear