]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAFederate.hxx
241f60935a38f6905fc89c53eb82313f71ef5120
[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     virtual ~HLAFederate();
36
37     /// Get the name of the joined federate/federation
38     const std::string& getFederateType() const;
39     const std::string& getFederationName() const;
40
41     /// Create a federation execution
42     /// Semantically this methods should be static,
43     /// but the nonstatic case could reuse the connection to the server
44     /// FIXME: cannot determine from the return value if we created the execution
45     bool createFederationExecution(const std::string& federation, const std::string& objectModel);
46     bool destroyFederationExecution(const std::string& federation);
47
48     /// Join with federateType the federation execution
49     bool join(const std::string& federateType, const std::string& federation);
50     bool resign();
51
52     bool enableTimeConstrained();
53     bool disableTimeConstrained();
54
55     bool enableTimeRegulation(const SGTimeStamp& lookahead);
56     bool disableTimeRegulation();
57
58     bool timeAdvanceRequestBy(const SGTimeStamp& dt);
59     bool timeAdvanceRequest(const SGTimeStamp& dt);
60
61     bool queryFederateTime(SGTimeStamp& timeStamp);
62     bool queryLookahead(SGTimeStamp& timeStamp);
63
64     /// Process messages
65     bool tick();
66     bool tick(const double& minimum, const double& maximum);
67
68     class ObjectModelFactory {
69     public:
70         virtual ~ObjectModelFactory()
71         { }
72
73         virtual HLAObjectClass* createObjectClass(const std::string& name, HLAFederate& federate)
74         { return new HLAObjectClass(name, federate); }
75         virtual bool subscribeObjectClass(const std::string& objectClassName, const std::string& sharing)
76         { return sharing.find("Subscribe") != std::string::npos; }
77         virtual bool publishObjectClass(const std::string& objectClassName, const std::string& sharing)
78         { return sharing.find("Publish") != std::string::npos; }
79         virtual bool subscribeAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
80         { return sharing.find("Subscribe") != std::string::npos; }
81         virtual bool publishAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
82         { return sharing.find("Publish") != std::string::npos; }
83
84     };
85
86     /// Read an omt xml file
87     bool readObjectModelTemplate(const std::string& objectModel,
88                                  ObjectModelFactory& objectModelFactory);
89
90     HLAObjectClass* getObjectClass(const std::string& name);
91     const HLAObjectClass* getObjectClass(const std::string& name) const;
92
93     HLAInteractionClass* getInteractionClass(const std::string& name);
94     const HLAInteractionClass* getInteractionClass(const std::string& name) const;
95
96 protected:
97     HLAFederate(const SGSharedPtr<RTIFederate>& rtiFederate);
98
99 private:
100     SGSharedPtr<RTIFederate> _rtiFederate;
101
102     typedef std::map<std::string, SGSharedPtr<HLAObjectClass> > ObjectClassMap;
103     ObjectClassMap _objectClassMap;
104
105     typedef std::map<std::string, SGSharedPtr<HLAInteractionClass> > InteractionClassMap;
106     InteractionClassMap _interactionClassMap;
107
108     friend class HLAInteractionClass;
109     friend class HLAObjectClass;
110 };
111
112 } // namespace simgear
113
114 #endif