-void NoaaMetarRealWxController::update( bool first, double dt )
-{
- _positionTimeToLive -= dt;
- _requestTimer -= dt;
-
- if( _positionTimeToLive <= 0.0 ) {
- // check nearest airport
- SG_LOG(SG_ALL, SG_INFO, "NoaaMetarRealWxController::update(): (re) checking nearby airport with METAR" );
- _positionTimeToLive = 60.0;
-
- SGGeod pos = SGGeod::fromDeg(_longitude_n->getDoubleValue(), _latitude_n->getDoubleValue());
-
- FGAirport * nearestAirport = FGAirport::findClosest(pos, 10000.0, MetarAirportFilter::instance() );
- if( nearestAirport == NULL ) {
- SG_LOG(SG_ALL,SG_WARN,"RealWxController::update can't find airport with METAR within 10000NM" );
- return;
- }
-
- SG_LOG(SG_ALL, SG_INFO,
- "NoaaMetarRealWxController::update(): nearest airport with METAR is: " << nearestAirport->ident() );
-
- // if it has changed, invalidate the associated METAR
- if( _metarProperties[0]->getStationId() != nearestAirport->ident() ) {
- SG_LOG(SG_ALL, SG_INFO,
- "NoaaMetarRealWxController::update(): nearest airport with METAR has changed. Old: '" <<
- _metarProperties[0]->getStationId() <<
- "', new: '" << nearestAirport->ident() << "'" );
- _metarProperties[0]->setStationId( nearestAirport->ident() );
- _metarProperties[0]->setTimeToLive( 0.0 );
- }
- }
-
- if( _requestTimer <= 0.0 ) {
- _requestTimer = 10.0;
-
- for( MetarPropertiesList::iterator it = _metarProperties.begin();
- it != _metarProperties.end(); it++ ) {
-
- if( (*it)->getTimeToLive() > 0.0 ) continue;
- const std::string & stationId = (*it)->getStationId();
- if( stationId.empty() ) continue;
-
- SG_LOG(SG_ALL, SG_INFO,
- "NoaaMetarRealWxController::update(): spawning load request for station-id '" << stationId << "'" );
-
- MetarLoadRequest request( stationId );
- // load the metar for the nearest airport in the foreground if the fdm is uninitialized
- // to make sure a metar is received
- // before the automatic runway selection code runs. All subsequent calls
- // run in the background
- bool background = fgGetBool("/sim/fdm-initialized", false ) || it != _metarProperties.begin();
- _metarLoadThread->requestMetar( request, background );
- }
- }
-
- // pick all the received responses from the result queue and update the associated
- // property tree
- while( _metarLoadThread->hasMetar() ) {
- MetarLoadResponse metar = _metarLoadThread->getMetar();
- SG_LOG( SG_ALL, SG_INFO, "NoaaMetarRwalWxController::update() received METAR for " << metar._stationId << ": " << metar._metar );
- for( MetarPropertiesList::iterator it = _metarProperties.begin();
- it != _metarProperties.end(); it++ ) {
- if( (*it)->getStationId() != metar._stationId )
- continue;
- (*it)->setTimeToLive(900);
- (*it)->setMetar( metar._metar );
- }
- }
-}
-
-/* -------------------------------------------------------------------------------- */
-
-#if defined(ENABLE_THREADS)
-NoaaMetarRealWxController::MetarLoadThread::MetarLoadThread( long maxAge ) :
- _maxAge(maxAge),
- _minRequestInterval(2000),
- _stop(false)
-{
-}
-
-void NoaaMetarRealWxController::MetarLoadThread::requestMetar( const MetarLoadRequest & metarRequest, bool background )
-{
- if( background ) {
- if( _requestQueue.size() > 10 ) {
- SG_LOG(SG_ALL,SG_ALERT,
- "NoaaMetarRealWxController::MetarLoadThread::requestMetar() more than 10 outstanding METAR requests, dropping "
- << metarRequest._stationId );
- return;
- }
-
- _requestQueue.push( metarRequest );
- } else {
- fetch( metarRequest );
- }
-}
-
-void NoaaMetarRealWxController::MetarLoadThread::stop()