]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAFederate.hxx
Merge remote branch 'origin/releases/2.2.0' into next
[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     /// Process messages
62     bool tick();
63     bool tick(const double& minimum, const double& maximum);
64
65     class ObjectModelFactory {
66     public:
67         virtual ~ObjectModelFactory()
68         { }
69
70         virtual HLAObjectClass* createObjectClass(const std::string& name, HLAFederate& federate)
71         { return new HLAObjectClass(name, federate); }
72         virtual bool subscribeObjectClass(const std::string& objectClassName, const std::string& sharing)
73         { return sharing.find("Subscribe") != std::string::npos; }
74         virtual bool publishObjectClass(const std::string& objectClassName, const std::string& sharing)
75         { return sharing.find("Publish") != std::string::npos; }
76         virtual bool subscribeAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
77         { return sharing.find("Subscribe") != std::string::npos; }
78         virtual bool publishAttribute(const std::string& objectClassName, const std::string& attributeName, const std::string& sharing)
79         { return sharing.find("Publish") != std::string::npos; }
80
81     };
82
83     /// Read an omt xml file
84     bool readObjectModelTemplate(const std::string& objectModel,
85                                  ObjectModelFactory& objectModelFactory);
86
87     HLAObjectClass* getObjectClass(const std::string& name);
88     const HLAObjectClass* getObjectClass(const std::string& name) const;
89
90     HLAInteractionClass* getInteractionClass(const std::string& name);
91     const HLAInteractionClass* getInteractionClass(const std::string& name) const;
92
93 protected:
94     HLAFederate(const SGSharedPtr<RTIFederate>& rtiFederate);
95
96 private:
97     SGSharedPtr<RTIFederate> _rtiFederate;
98
99     typedef std::map<std::string, SGSharedPtr<HLAObjectClass> > ObjectClassMap;
100     ObjectClassMap _objectClassMap;
101
102     typedef std::map<std::string, SGSharedPtr<HLAInteractionClass> > InteractionClassMap;
103     InteractionClassMap _interactionClassMap;
104
105     friend class HLAInteractionClass;
106     friend class HLAObjectClass;
107 };
108
109 } // namespace simgear
110
111 #endif