]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/realwx_ctrl.cxx
Remove un-needed header.
[flightgear.git] / src / Environment / realwx_ctrl.cxx
index 6be99082e6fa942bb03933a7545df663be8ed514..f7d09fba72bd2bd60f5aea1af702cdeb9070a2da 100644 (file)
@@ -68,7 +68,8 @@ public:
     virtual void update( double dt );
 
     virtual double getTimeToLive() const { return _timeToLive; }
-    virtual void setTimeToLive( double value ) { _timeToLive = value; }
+    virtual void resetTimeToLive()
+    { _timeToLive = 0.00; _pollingTimer = 0.0; }
 
     // implementation of MetarDataHandler
     virtual void handleMetarData( const std::string & data );
@@ -102,7 +103,7 @@ void LiveMetarProperties::update( double dt )
 {
     _timeToLive -= dt;
     _pollingTimer -= dt;
-    if( _timeToLive < 0.0 ) {
+    if( _timeToLive <= 0.0 ) {
         _timeToLive = 0.0;
         std::string stationId = getStationId();
         if( stationId.empty() ) return;
@@ -234,6 +235,8 @@ BasicRealWxController::~BasicRealWxController()
 void BasicRealWxController::init()
 {
     _wasEnabled = false;
+    
+    checkNearbyMetar();
     update(0); // fetch data ASAP
     
     globals->get_event_mgr()->addTask("checkNearbyMetar", this,
@@ -243,6 +246,8 @@ void BasicRealWxController::init()
 void BasicRealWxController::reinit()
 {
     _wasEnabled = false;
+    checkNearbyMetar();
+    update(0); // fetch data ASAP
 }
     
 void BasicRealWxController::shutdown()
@@ -262,14 +267,13 @@ void BasicRealWxController::unbind()
 }
 
 void BasicRealWxController::update( double dt )
-{
+{  
   if( _enabled ) {
     bool firstIteration = !_wasEnabled;
-
     // clock tick for every METAR in stock
     BOOST_FOREACH(LiveMetarProperties* p, _metarProperties) {
       // first round? All received METARs are outdated
-      if( firstIteration ) p->setTimeToLive( 0.0 );
+      if( firstIteration ) p->resetTimeToLive();
       p->update(dt);
     }
 
@@ -287,7 +291,7 @@ void BasicRealWxController::addMetarAtPath(const string& propPath, const string&
       // already exists
       if (p->getStationId() != icao) {
         p->setStationId(icao);
-        p->setTimeToLive(0.0);
+        p->resetTimeToLive();
       }
       
       return;
@@ -340,7 +344,7 @@ void BasicRealWxController::checkNearbyMetar()
               _metarProperties[0]->getStationId() <<
               "', new: '" << nearestAirport->ident() << "'" );
           _metarProperties[0]->setStationId( nearestAirport->ident() );
-          _metarProperties[0]->setTimeToLive( 0.0 );
+          _metarProperties[0]->resetTimeToLive();
       }
     }
     catch( sg_exception & ) {
@@ -419,6 +423,11 @@ void NoaaMetarRealWxController::requestMetar( MetarDataHandler * metarDataHandle
                   SG_LOG(SG_ENVIRONMENT, SG_WARN, "metar download failed:" << url() << ": reason:" << responseReason());
               }
           }
+        
+        virtual void failed()
+        {
+            SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failure");
+        }
 
 //          bool fromMetarProxy() const
 //          { return _fromProxy; }