1 // Copyright (C) 2009 - 2011 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();
87 bool enableTimeConstrained();
88 bool disableTimeConstrained();
90 bool enableTimeRegulation(const SGTimeStamp& lookahead);
91 bool disableTimeRegulation();
92 bool modifyLookahead(const SGTimeStamp& lookahead);
94 /// Advance the logical time by the given time increment.
95 /// Depending on the time constrained mode, this might
96 /// block until the time advance is granted.
97 bool timeAdvanceBy(const SGTimeStamp& timeIncrement);
98 /// Advance the logical time to the given time.
99 /// Depending on the time constrained mode, this might
100 /// block until the time advance is granted.
101 bool timeAdvance(const SGTimeStamp& timeStamp);
102 /// Advance the logical time as far as time advances are available.
103 /// This call should not block and advance the logical time
104 /// as far as currently possible.
105 bool timeAdvanceAvailable();
107 bool queryFederateTime(SGTimeStamp& timeStamp);
108 bool queryLookahead(SGTimeStamp& timeStamp);
110 /// Process one messsage
111 bool processMessage();
112 /// Process one message but do not wait longer than the relative timeout.
113 bool processMessage(const SGTimeStamp& timeout);
114 /// Process messages until the federate can proceed with the
115 /// next simulation step. That is flush all pending messages and
116 /// depending on the time constrained mode process messages until
117 /// a pending time advance is granted.
118 bool processMessages();
121 bool tick(const double& minimum, const double& maximum);
123 class ObjectModelFactory {
125 virtual ~ObjectModelFactory()
128 virtual HLAObjectClass* createObjectClass(const std::string& name, HLAFederate& federate)
129 { return new HLAObjectClass(name, federate); }
130 virtual bool subscribeObjectClass(const std::string& objectClassName, const std::string& sharing)
131 { return sharing.find("Subscribe") != std::string::npos; }
132 virtual bool publishObjectClass(const std::string& objectClassName, const std::string& sharing)
133 { return sharing.find("Publish") != std::string::npos; }
134 virtual bool subscribeAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
135 { return sharing.find("Subscribe") != std::string::npos; }
136 virtual bool publishAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
137 { return sharing.find("Publish") != std::string::npos; }
141 /// Read an omt xml file
142 bool readObjectModelTemplate(const std::string& objectModel,
143 ObjectModelFactory& objectModelFactory);
145 HLAObjectClass* getObjectClass(const std::string& name);
146 const HLAObjectClass* getObjectClass(const std::string& name) const;
148 HLAInteractionClass* getInteractionClass(const std::string& name);
149 const HLAInteractionClass* getInteractionClass(const std::string& name) const;
152 HLAFederate(const HLAFederate&);
153 HLAFederate& operator=(const HLAFederate&);
155 /// The underlying interface to the rti implementation
156 SGSharedPtr<RTIFederate> _rtiFederate;
158 /// Parameters required to connect to an rti
160 std::list<std::string> _connectArguments;
162 /// Parameters for the federation execution
163 std::string _federationExecutionName;
164 std::string _federationObjectModel;
166 /// Parameters for the federate
167 std::string _federateType;
168 std::string _federateName;
170 typedef std::map<std::string, SGSharedPtr<HLAObjectClass> > ObjectClassMap;
171 ObjectClassMap _objectClassMap;
173 typedef std::map<std::string, SGSharedPtr<HLAInteractionClass> > InteractionClassMap;
174 InteractionClassMap _interactionClassMap;
176 friend class HLAInteractionClass;
177 friend class HLAObjectClass;
180 } // namespace simgear