]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/ATCmgr.hxx
Merge branch 'next' of gitorious.org:fg/flightgear into atcdcl
[flightgear.git] / src / ATCDCL / ATCmgr.hxx
1 // ATCMgr.hxx - definition of FGATCMgr 
2 // - a global management class for FlightGear generated ATC
3 //
4 // Written by David Luff, started February 2002.
5 //
6 // Copyright (C) 2002  David C Luff - david.luff@nottingham.ac.uk
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifndef _FG_ATCMGR_HXX
23 #define _FG_ATCMGR_HXX
24
25 #include <simgear/structure/subsystem_mgr.hxx>
26
27 #include <Main/fg_props.hxx>
28 #include <GUI/gui.h>
29
30 #include <string>
31 #include <list>
32 #include <map>
33
34 #include "ATC.hxx"
35
36 using std::string;
37 using std::list;
38 using std::map;
39
40 // Structure for holding details of the ATC frequencies at a given airport, and whether they are in the active list or not.
41 // These can then be cross referenced with the commlists which are stored by frequency or bucket.
42 // Non-available services are denoted by a frequency of zero.
43 // These structures are only intended to be created for in-use airports, and removed when no longer needed. 
44 struct AirportATC {
45         AirportATC();
46         
47     SGGeod geod;
48     float atis_freq;
49     bool atis_active;
50 };
51
52 class FGATCMgr : public SGSubsystem
53 {
54
55 private:
56
57     bool initDone;      // Hack - guard against update getting called before init
58
59     // A map of airport ID vs frequencies and ATC provision
60     typedef map < string, AirportATC* > airport_atc_map_type;
61     typedef airport_atc_map_type::iterator airport_atc_map_iterator;
62     typedef airport_atc_map_type::const_iterator airport_atc_map_const_iterator;
63
64     airport_atc_map_type airport_atc_map;
65     airport_atc_map_iterator airport_atc_map_itr;
66
67     // A list of pointers to all currently active ATC classes
68     typedef map<string,FGATC*> atc_list_type;
69     typedef atc_list_type::iterator atc_list_iterator;
70     typedef atc_list_type::const_iterator atc_list_const_iterator;
71
72     // Everything put in this list should be created dynamically
73     // on the heap and ***DELETED WHEN REMOVED!!!!!***
74     atc_list_type* atc_list;
75     atc_list_iterator atc_list_itr;
76     // Any member function of FGATCMgr is permitted to leave this iterator pointing
77     // at any point in or at the end of the list.
78     // Hence any new access must explicitly first check for atc_list.end() before dereferencing.
79
80     // Position of the Users Aircraft
81     SGGeod _aircraftPos;
82
83     // Pointers to current users position
84     SGPropertyNode_ptr lon_node;
85     SGPropertyNode_ptr lat_node;
86     SGPropertyNode_ptr elev_node;
87
88     //FGATIS atis;
89         
90     // Voice related stuff
91     bool voice;                 // Flag - true if we are using voice
92 #ifdef ENABLE_AUDIO_SUPPORT
93     bool voiceOK;               // Flag - true if at least one voice has loaded OK
94     FGATCVoice* v1;
95 #endif
96
97 public:
98
99     FGATCMgr();
100     ~FGATCMgr();
101
102     void init();
103
104     void bind();
105
106     void unbind();
107
108     void update(double dt);
109
110     // Returns true if the airport is found in the map
111     bool GetAirportATCDetails(const string& icao, AirportATC* a);
112         
113     // Return a pointer to an appropriate voice for a given type of ATC
114     // creating the voice if necessary - ie. make sure exactly one copy
115     // of every voice in use exists in memory.
116     //
117     // TODO - in the future this will get more complex and dole out country/airport
118     // specific voices, and possible make sure that the same voice doesn't get used
119     // at different airports in quick succession if a large enough selection are available.
120     FGATCVoice* GetVoicePointer(const atc_type& type);
121     
122     atc_type GetComm1ATCType() { return(INVALID/* kludge */); }
123     FGATC* GetComm1ATCPointer() { return(0/* kludge */); }
124     atc_type GetComm2ATCType() { return(INVALID); }
125     FGATC* GetComm2ATCPointer() { return(0/* kludge */); }
126     
127     // Get the frequency of a given service at a given airport
128     // Returns zero if not found
129     unsigned short int GetFrequency(const string& ident, const atc_type& tp);
130     
131     // Register the fact that the comm radio is tuned to an airport
132     bool CommRegisterAirport(const string& ident, int chan, const atc_type& tp);
133         
134 private:
135
136     // Remove a class from the atc_list and delete it from memory
137         // *if* no other comm channel or AI plane is using it.
138     void ZapOtherService(const string ncunit, const string svc_name);
139
140     // Return a pointer to a class in the list given ICAO code and type
141     // Return NULL if the given service is not in the list
142     // - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
143     FGATC* FindInList(const string& id, const atc_type& tp);
144
145     // Search the specified radio for stations on the same frequency and in range.
146     void FreqSearch(const string navcomm, const int unit);
147 };
148
149 #endif  // _FG_ATCMGR_HXX