]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/realwx_ctrl.cxx
Added support for shared JSBSim engine and system configurations in fgdata.
[flightgear.git] / src / Environment / realwx_ctrl.cxx
index f80a518e3c51f58cf331058ba3e4b831b4bc57c9..afa41c62b123798c634d420b3808e7a29f9a9044 100644 (file)
@@ -52,6 +52,7 @@ namespace Environment {
 class MetarDataHandler {
 public:
     virtual void handleMetarData( const std::string & data ) = 0;
+    virtual void handleMetarFailure() = 0;
 };
 
 class MetarRequester {
@@ -73,7 +74,8 @@ public:
 
     // implementation of MetarDataHandler
     virtual void handleMetarData( const std::string & data );
-
+    virtual void handleMetarFailure();
+  
     static const unsigned MAX_POLLING_INTERVAL_SECONDS = 10;
     static const unsigned DEFAULT_TIME_TO_LIVE_SECONDS = 900;
 
@@ -82,6 +84,7 @@ private:
     double _pollingTimer;
     MetarRequester * _metarRequester;
     int _maxAge;
+    bool _failure;
 };
 
 typedef SGSharedPtr<LiveMetarProperties> LiveMetarProperties_ptr;
@@ -91,9 +94,11 @@ LiveMetarProperties::LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequ
     _timeToLive(0.0),
     _pollingTimer(0.0),
     _metarRequester(metarRequester),
-    _maxAge(maxAge)
+    _maxAge(maxAge),
+    _failure(false)
 {
     _tiedProperties.Tie("time-to-live", &_timeToLive );
+    _tiedProperties.Tie("failure", &_failure);
 }
 
 LiveMetarProperties::~LiveMetarProperties()
@@ -126,6 +131,7 @@ void LiveMetarProperties::handleMetarData( const std::string & data )
     }
     catch( sg_io_exception ) {
         SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << data );
+        _failure = true;
         return;
     }
 
@@ -134,10 +140,16 @@ void LiveMetarProperties::handleMetarData( const std::string & data )
         SG_LOG( SG_ENVIRONMENT, SG_DEBUG, "Ignoring outdated METAR for " << getStationId());
         return;
     }
-    
+  
+    _failure = false;
     setMetar( m );
 }
 
+void LiveMetarProperties::handleMetarFailure()
+{
+  _failure = true;
+}
+  
 /* -------------------------------------------------------------------------------- */
 
 class BasicRealWxController : public RealWxController
@@ -232,30 +244,32 @@ BasicRealWxController::BasicRealWxController( SGPropertyNode_ptr rootNode, Metar
   _wasEnabled(false),
   _requester(metarRequester)
 {
-    // at least instantiate MetarProperties for /environment/metar
-    _metarProperties.push_back( new LiveMetarProperties( 
-            fgGetNode( rootNode->getStringValue("metar", "/environment/metar"), true ),
-            metarRequester,
-            getMetarMaxAgeMin()));
-
-    BOOST_FOREACH( SGPropertyNode_ptr n, rootNode->getChildren("metar") ) {
-        SGPropertyNode_ptr metarNode = fgGetNode( n->getStringValue(), true );
-        addMetarAtPath(metarNode->getPath(), "");
-    }
-  
-    SGCommandMgr::instance()->addCommand("request-metar", commandRequestMetar);
-    SGCommandMgr::instance()->addCommand("clear-metar", commandClearMetar);
+    
+    globals->get_commands()->addCommand("request-metar", commandRequestMetar);
+    globals->get_commands()->addCommand("clear-metar", commandClearMetar);
 }
 
 BasicRealWxController::~BasicRealWxController()
 {
-  //SGCommandMgr::instance()->removeCommand("request-metar");
+    globals->get_commands()->removeCommand("request-metar");
+    globals->get_commands()->removeCommand("clear-metar");
 }
 
 void BasicRealWxController::init()
 {
     _wasEnabled = false;
     
+    // at least instantiate MetarProperties for /environment/metar
+    SGPropertyNode_ptr metarNode = fgGetNode( _rootNode->getStringValue("metar", "/environment/metar"), true );
+    _metarProperties.push_back( new LiveMetarProperties(metarNode,
+                                                        _requester,
+                                                        getMetarMaxAgeMin()));
+    
+    BOOST_FOREACH( SGPropertyNode_ptr n, _rootNode->getChildren("metar") ) {
+        SGPropertyNode_ptr metarNode = fgGetNode( n->getStringValue(), true );
+        addMetarAtPath(metarNode->getPath(), "");
+    }
+
     checkNearbyMetar();
     update(0); // fetch data ASAP
     
@@ -382,6 +396,9 @@ public:
     // implementation of MetarRequester
     virtual void requestMetar( MetarDataHandler * metarDataHandler, const std::string & id );
 
+    virtual ~NoaaMetarRealWxController()
+    {
+    }
 private:
     
 };
@@ -435,6 +452,7 @@ void NoaaMetarRealWxController::requestMetar
       virtual void onFail()
       {
         SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failure");
+        _metarDataHandler->handleMetarFailure();
       }
 
     private:
@@ -457,11 +475,15 @@ void NoaaMetarRealWxController::requestMetar
 }
 
 /* -------------------------------------------------------------------------------- */
-
+    
 RealWxController * RealWxController::createInstance( SGPropertyNode_ptr rootNode )
 {
   return new NoaaMetarRealWxController( rootNode );
 }
+    
+RealWxController::~RealWxController()
+{
+}
 
 /* -------------------------------------------------------------------------------- */