]> git.mxchange.org Git - flightgear.git/commitdiff
Fix ATIS /environment/attention handling
authorThomas Geymayer <tomgey@gmail.com>
Wed, 26 Sep 2012 22:41:23 +0000 (00:41 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Wed, 26 Sep 2012 22:42:06 +0000 (00:42 +0200)
Using a tied property works only for one single usage of the
property. In reality FGATIS is normally instantiated four
times (nav/comm/1/2) where only the first instantiation
works correctly. All subsequent instantions fail to tie
and show some error messages.
Also tied properties shouldn't be used anymore.

src/ATCDCL/atis.cxx
src/ATCDCL/atis.hxx

index 23918619dc153be64fe3d550c836061a5d5562b0..56e6c618bf4290ff3715808cc98e9d6da02a6915 100644 (file)
@@ -71,18 +71,17 @@ using flightgear::CommStation;
 FGATIS::FGATIS(const std::string& name, int num) :
   _name(name),
   _num(num),
+  _cb_attention(this, &FGATIS::attend, fgGetNode("/environment/attention", true)),
   transmission(""),
   trans_ident(""),
   old_volume(0),
   atis_failed(false),
   msg_OK(0),
-  attention(0),
+  _attention(false),
   _prev_display(0),
   _time_before_search_sec(0),
   _last_frequency(0)
 {
-  fgTie("/environment/attention", this, (int_getter)0, &FGATIS::attend);
-
   _root         = fgGetNode("/instrumentation", true)->getNode(_name, num, true);
   _volume       = _root->getNode("volume",true);
   _serviceable  = _root->getNode("serviceable",true);
@@ -130,10 +129,6 @@ FGATIS::FGATIS(const std::string& name, int num) :
 // Hint:
 // http://localhost:5400/environment/attention?value=1&submit=update
 
-FGATIS::~FGATIS() {
-  fgUntie("/environment/attention");
-}
-
 FGATCVoice* FGATIS::GetVoicePointer()
 {
     FGATISMgr* pAtisMgr = globals->get_ATIS_mgr();
@@ -151,9 +146,9 @@ void FGATIS::init() {
 }
 
 void
-FGATIS::attend (int attn)
+FGATIS::attend(SGPropertyNode* node)
 {
-  attention = attn;
+  _attention = node->getBoolValue();
 #ifdef ATMO_TEST
   int flag = fgGetInt("/sim/logging/atmo");
   if (flag) {
@@ -209,7 +204,7 @@ void FGATIS::update(double dt) {
     // - basically every hour and if the weather changes significantly at the station
     // If !_prev_display, the radio had been detuned for a while and our
     // "transmission" variable was lost when we were de-instantiated.
-    int changed = GenTransmission(!_prev_display, attention);
+    int changed = GenTransmission(!_prev_display, _attention);
 
     // update output property
     TreeOut(msg_OK);
@@ -225,7 +220,7 @@ void FGATIS::update(double dt) {
     NoRender(_name);
     _prev_display = false;
   }
-  attention = 0;
+  _attention = false;
 }
 
 string uppercase(const string &s) {
@@ -296,7 +291,7 @@ int Apt_US_CA(const string id) {
 // Regen means regenerate the /current/ transmission.
 // Special means generate a new transmission, with a new sequence.
 // Returns 1 if we actually generated something.
-int FGATIS::GenTransmission(const int regen, const int special) {
+int FGATIS::GenTransmission(const int regen, const bool special) {
   using namespace atmodel;
   using namespace lex;
 
index bd67d8ec8be2df1712c1c1fda4744e310e4edee5..673cb3a037a2fe4bbc5c8307c3031db8b3b79fba 100644 (file)
@@ -52,6 +52,8 @@ class FGATIS : public FGATC {
     SGPropertyNode_ptr _lat_node;
     SGPropertyNode_ptr _elev_node;
 
+    SGPropertyChangeCallback<FGATIS> _cb_attention;
+
     // The actual ATIS transmission
     // This is generated from the prevailing conditions when required.
     // This is the version with markup, suitable for voice synthesis:
@@ -67,7 +69,7 @@ class FGATIS : public FGATC {
     time_t msg_time;         // for moderating error messages
     time_t cur_time;
     int msg_OK;
-    int attention;
+    bool _attention;
 
     bool _prev_display;      // Previous value of _display flag
     MSS _remap;              // abbreviations to be expanded
@@ -79,9 +81,9 @@ class FGATIS : public FGATC {
 public:
 
     FGATIS(const std::string& name, int num);
-    ~FGATIS(void);
+
     virtual void init();
-    void attend (int);
+    void attend(SGPropertyNode* node);
 
     //run the ATIS instance
     void update(double dt);
@@ -95,7 +97,7 @@ protected:
 private:
 
     // Generate the ATIS transmission text:
-    int GenTransmission(const int regen, const int special);
+    int GenTransmission(const int regen, const bool special);
 
     // Put the text into the property tree
     // (and in debug mode, print it on the console):