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 );
{
_timeToLive -= dt;
_pollingTimer -= dt;
- if( _timeToLive < 0.0 ) {
+ if( _timeToLive <= 0.0 ) {
_timeToLive = 0.0;
std::string stationId = getStationId();
if( stationId.empty() ) return;
void BasicRealWxController::init()
{
_wasEnabled = false;
+
+ checkNearbyMetar();
update(0); // fetch data ASAP
globals->get_event_mgr()->addTask("checkNearbyMetar", this,
void BasicRealWxController::reinit()
{
_wasEnabled = false;
+ checkNearbyMetar();
+ update(0); // fetch data ASAP
}
void BasicRealWxController::shutdown()
}
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);
}
// already exists
if (p->getStationId() != icao) {
p->setStationId(icao);
- p->setTimeToLive(0.0);
+ p->resetTimeToLive();
}
return;
_metarProperties[0]->getStationId() <<
"', new: '" << nearestAirport->ident() << "'" );
_metarProperties[0]->setStationId( nearestAirport->ident() );
- _metarProperties[0]->setTimeToLive( 0.0 );
+ _metarProperties[0]->resetTimeToLive();
}
}
catch( sg_exception & ) {
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; }
SG_LOG(SG_ENVIRONMENT, SG_INFO,
"NoaaMetarRealWxController::update(): spawning load request for station-id '" << upperId << "'" );
- FGHTTPClient::instance()->makeRequest(new NoaaMetarGetRequest(metarDataHandler, upperId));
+ FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+ if (http) {
+ http->makeRequest(new NoaaMetarGetRequest(metarDataHandler, upperId));
+ }
}
/* -------------------------------------------------------------------------------- */