]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAFederate.hxx
f3b84afeb916fd44893d14fa65ff0dd596562878
[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     HLAFederate();
36     virtual ~HLAFederate();
37
38     enum Version {
39         RTI13,
40         RTI1516,
41         RTI1516E
42     };
43
44     Version getVersion() const;
45     bool setVersion(HLAFederate::Version version);
46
47     const std::list<std::string>& getConnectArguments() const;
48     bool setConnectArguments(const std::list<std::string>& connectArguments);
49
50     const std::string& getFederationExecutionName() const;
51     bool setFederationExecutionName(const std::string& federationExecutionName);
52
53     const std::string& getFederationObjectModel() const;
54     bool setFederationObjectModel(const std::string& federationObjectModel);
55
56     const std::string& getFederateType() const;
57     bool setFederateType(const std::string& federateType);
58
59     const std::string& getFederateName() const;
60     bool setFederateName(const std::string& federateName);
61
62     /// connect to an rti
63     bool connect(Version version, const std::list<std::string>& stringList);
64     bool connect();
65     bool disconnect();
66
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();
74
75     /// Join with federateType the federation execution
76     bool join(const std::string& federateType, const std::string& federation);
77     bool join();
78     bool resign();
79     
80     /// Try to create and join the federation execution.
81     bool createJoinFederationExecution();
82     bool resignDestroyFederationExecution();
83
84
85     bool enableTimeConstrained();
86     bool disableTimeConstrained();
87
88     bool enableTimeRegulation(const SGTimeStamp& lookahead);
89     bool disableTimeRegulation();
90
91     bool timeAdvanceRequestBy(const SGTimeStamp& dt);
92     bool timeAdvanceRequest(const SGTimeStamp& dt);
93
94     bool queryFederateTime(SGTimeStamp& timeStamp);
95     bool modifyLookahead(const SGTimeStamp& timeStamp);
96     bool queryLookahead(SGTimeStamp& timeStamp);
97
98     /// Process messages
99     bool tick();
100     bool tick(const double& minimum, const double& maximum);
101
102     class ObjectModelFactory {
103     public:
104         virtual ~ObjectModelFactory()
105         { }
106
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; }
117
118     };
119
120     /// Read an omt xml file
121     bool readObjectModelTemplate(const std::string& objectModel,
122                                  ObjectModelFactory& objectModelFactory);
123
124     HLAObjectClass* getObjectClass(const std::string& name);
125     const HLAObjectClass* getObjectClass(const std::string& name) const;
126
127     HLAInteractionClass* getInteractionClass(const std::string& name);
128     const HLAInteractionClass* getInteractionClass(const std::string& name) const;
129
130 private:
131     SGSharedPtr<RTIFederate> _rtiFederate;
132
133     Version _version;
134     std::list<std::string> _connectArguments;
135
136     std::string _federationExecutionName;
137     std::string _federationObjectModel;
138     std::string _federateType;
139     std::string _federateName;
140
141     typedef std::map<std::string, SGSharedPtr<HLAObjectClass> > ObjectClassMap;
142     ObjectClassMap _objectClassMap;
143
144     typedef std::map<std::string, SGSharedPtr<HLAInteractionClass> > InteractionClassMap;
145     InteractionClassMap _interactionClassMap;
146
147     friend class HLAInteractionClass;
148     friend class HLAObjectClass;
149 };
150
151 } // namespace simgear
152
153 #endif