]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAFederate.hxx
hla: Move callbacks into the rti federate implementation.
[simgear.git] / simgear / hla / HLAFederate.hxx
1 // Copyright (C) 2009 - 2010  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
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.
7 //
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.
12 //
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.
16 //
17
18 #ifndef HLAFederate_hxx
19 #define HLAFederate_hxx
20
21 #include <map>
22
23 #include "HLAObjectInstance.hxx"
24 #include "HLAObjectClass.hxx"
25 #include "HLAInteractionClass.hxx"
26
27 class SGTimeStamp;
28
29 namespace simgear {
30
31 class RTIFederate;
32
33 class HLAFederate : public SGWeakReferenced {
34 public:
35     enum Version {
36         RTI13,
37         RTI1516,
38         RTI1516E
39     };
40
41     HLAFederate();
42     virtual ~HLAFederate();
43
44     /// connect to an rti
45     bool connect(Version version, const std::list<std::string>& stringList);
46     bool disconnect();
47
48     /// Get the name of the joined federate/federation
49     std::string getFederateType() const;
50     std::string getFederationName() const;
51
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);
58
59     /// Join with federateType the federation execution
60     bool join(const std::string& federateType, const std::string& federation);
61     bool resign();
62
63     bool enableTimeConstrained();
64     bool disableTimeConstrained();
65
66     bool enableTimeRegulation(const SGTimeStamp& lookahead);
67     bool disableTimeRegulation();
68
69     bool timeAdvanceRequestBy(const SGTimeStamp& dt);
70     bool timeAdvanceRequest(const SGTimeStamp& dt);
71
72     bool queryFederateTime(SGTimeStamp& timeStamp);
73     bool modifyLookahead(const SGTimeStamp& timeStamp);
74     bool queryLookahead(SGTimeStamp& timeStamp);
75
76     /// Process messages
77     bool tick();
78     bool tick(const double& minimum, const double& maximum);
79
80     class ObjectModelFactory {
81     public:
82         virtual ~ObjectModelFactory()
83         { }
84
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; }
95
96     };
97
98     /// Read an omt xml file
99     bool readObjectModelTemplate(const std::string& objectModel,
100                                  ObjectModelFactory& objectModelFactory);
101
102     HLAObjectClass* getObjectClass(const std::string& name);
103     const HLAObjectClass* getObjectClass(const std::string& name) const;
104
105     HLAInteractionClass* getInteractionClass(const std::string& name);
106     const HLAInteractionClass* getInteractionClass(const std::string& name) const;
107
108 private:
109     SGSharedPtr<RTIFederate> _rtiFederate;
110
111     typedef std::map<std::string, SGSharedPtr<HLAObjectClass> > ObjectClassMap;
112     ObjectClassMap _objectClassMap;
113
114     typedef std::map<std::string, SGSharedPtr<HLAInteractionClass> > InteractionClassMap;
115     InteractionClassMap _interactionClassMap;
116
117     friend class HLAInteractionClass;
118     friend class HLAObjectClass;
119 };
120
121 } // namespace simgear
122
123 #endif