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 {
42 virtual ~HLAFederate();
45 bool connect(Version version, const std::list<std::string>& stringList);
48 /// Get the name of the joined federate/federation
49 std::string getFederateType() const;
50 std::string getFederationName() const;
52 /// Create a federation execution
53 /// Semantically this methods should be static,
54 /// but the nonstatic case could reuse the connection to the server
55 /// FIXME: cannot determine from the return value if we created the execution
56 bool createFederationExecution(const std::string& federation, const std::string& objectModel);
57 bool destroyFederationExecution(const std::string& federation);
59 /// Join with federateType the federation execution
60 bool join(const std::string& federateType, const std::string& federation);
63 bool enableTimeConstrained();
64 bool disableTimeConstrained();
66 bool enableTimeRegulation(const SGTimeStamp& lookahead);
67 bool disableTimeRegulation();
69 bool timeAdvanceRequestBy(const SGTimeStamp& dt);
70 bool timeAdvanceRequest(const SGTimeStamp& dt);
72 bool queryFederateTime(SGTimeStamp& timeStamp);
73 bool modifyLookahead(const SGTimeStamp& timeStamp);
74 bool queryLookahead(SGTimeStamp& timeStamp);
78 bool tick(const double& minimum, const double& maximum);
80 class ObjectModelFactory {
82 virtual ~ObjectModelFactory()
85 virtual HLAObjectClass* createObjectClass(const std::string& name, HLAFederate& federate)
86 { return new HLAObjectClass(name, federate); }
87 virtual bool subscribeObjectClass(const std::string& objectClassName, const std::string& sharing)
88 { return sharing.find("Subscribe") != std::string::npos; }
89 virtual bool publishObjectClass(const std::string& objectClassName, const std::string& sharing)
90 { return sharing.find("Publish") != std::string::npos; }
91 virtual bool subscribeAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
92 { return sharing.find("Subscribe") != std::string::npos; }
93 virtual bool publishAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
94 { return sharing.find("Publish") != std::string::npos; }
98 /// Read an omt xml file
99 bool readObjectModelTemplate(const std::string& objectModel,
100 ObjectModelFactory& objectModelFactory);
102 HLAObjectClass* getObjectClass(const std::string& name);
103 const HLAObjectClass* getObjectClass(const std::string& name) const;
105 HLAInteractionClass* getInteractionClass(const std::string& name);
106 const HLAInteractionClass* getInteractionClass(const std::string& name) const;
109 SGSharedPtr<RTIFederate> _rtiFederate;
111 typedef std::map<std::string, SGSharedPtr<HLAObjectClass> > ObjectClassMap;
112 ObjectClassMap _objectClassMap;
114 typedef std::map<std::string, SGSharedPtr<HLAInteractionClass> > InteractionClassMap;
115 InteractionClassMap _interactionClassMap;
117 friend class HLAInteractionClass;
118 friend class HLAObjectClass;
121 } // namespace simgear