class MetarDataHandler {
public:
virtual void handleMetarData( const std::string & data ) = 0;
+ virtual void handleMetarFailure() = 0;
};
class MetarRequester {
// 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;
double _pollingTimer;
MetarRequester * _metarRequester;
int _maxAge;
+ bool _failure;
};
typedef SGSharedPtr<LiveMetarProperties> LiveMetarProperties_ptr;
_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()
}
catch( sg_io_exception ) {
SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << data );
+ _failure = true;
return;
}
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
_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
// implementation of MetarRequester
virtual void requestMetar( MetarDataHandler * metarDataHandler, const std::string & id );
+ virtual ~NoaaMetarRealWxController()
+ {
+ }
private:
};
virtual void onFail()
{
SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failure");
+ _metarDataHandler->handleMetarFailure();
}
private:
}
/* -------------------------------------------------------------------------------- */
-
+
RealWxController * RealWxController::createInstance( SGPropertyNode_ptr rootNode )
{
return new NoaaMetarRealWxController( rootNode );
}
+
+RealWxController::~RealWxController()
+{
+}
/* -------------------------------------------------------------------------------- */