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
_requester(metarRequester)
{
- 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");
- SGCommandMgr::instance()->removeCommand("clear-metar");
+ globals->get_commands()->removeCommand("request-metar");
+ globals->get_commands()->removeCommand("clear-metar");
}
void BasicRealWxController::init()
virtual void onFail()
{
SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failure");
+ _metarDataHandler->handleMetarFailure();
}
private: