using std::sort;
-class AirportWithMetar : public FGPositioned::Filter
+class AirportWithMetar : public FGAirport::AirportFilter
{
public:
- virtual bool pass(FGPositioned* aPos) const
+ virtual bool passAirport(FGAirport* aApt) const
{
- if ((aPos->type() < FGPositioned::AIRPORT) || (aPos->type() > FGPositioned::SEAPORT)) {
- return false;
- }
-
- FGAirport* apt = static_cast<FGAirport*>(aPos);
- return apt->getMetar();
+ return aApt->getMetar();
}
};
\f
FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
: env( new FGInterpolateEnvironmentCtrl ),
- _icao( "" ),
metar_loaded( false ),
search_interval_sec( 60.0 ), // 1 minute
same_station_interval_sec( 900.0 ), // 15 minutes
while ( !found_metar && (_error_count < 3) ) {
AirportWithMetar filter;
- FGPositionedRef a = FGPositioned::findClosest(pos, 10000.0, &filter);
+ FGAirport* a = FGAirport::findClosest(pos, 10000.0, &filter);
if (!a) {
break;
}
- FGMetarResult result = fetch_data(a->ident());
+ FGMetarResult result = fetch_data(a);
if ( result.m != NULL ) {
SG_LOG( SG_GENERAL, SG_INFO, "closest station w/ metar = "
<< a->ident());
last_apt = a;
- _icao = a->ident();
search_elapsed = 0.0;
fetch_elapsed = 0.0;
update_metar_properties( result.m );
// mark as no metar so it doesn't show up in subsequent
// searches.
SG_LOG( SG_GENERAL, SG_INFO, "no metar at metar = " << a->ident() );
- static_cast<FGAirport*>(a.ptr())->setMetar(false);
+ a->setMetar(false);
}
} // of airprot-with-metar search iteration
// queue
if ( search_elapsed > search_interval_sec ) {
AirportWithMetar filter;
- FGPositionedRef a = FGPositioned::findClosest(pos, 10000.0, &filter);
+ FGAirport* a = FGAirport::findClosest(pos, 10000.0, &filter);
if (a) {
if ( !last_apt || last_apt->ident() != a->ident()
|| fetch_elapsed > same_station_interval_sec )
{
SG_LOG( SG_GENERAL, SG_INFO, "closest station w/ metar = "
<< a->ident());
- request_queue.push( a->ident() );
+ request_queue.push(a);
last_apt = a;
- _icao = a->ident();
search_elapsed = 0.0;
fetch_elapsed = 0.0;
} else {
#if !defined(ENABLE_THREADS)
// No loader thread running so manually fetch the data
- string id = "";
+ FGAirport* apt = NULL;
while ( !request_queue.empty() ) {
- id = request_queue.front();
+ apt = request_queue.front();
request_queue.pop();
}
- if ( !id.empty() ) {
- SG_LOG( SG_GENERAL, SG_INFO, "inline fetching = " << id );
- result = fetch_data( id );
+ if (apt) {
+ SG_LOG( SG_GENERAL, SG_INFO, "inline fetching = " << apt->ident() );
+ result = fetch_data( apt );
result_queue.push( result );
}
#endif // ENABLE_THREADS
// mark as no metar so it doesn't show up in subsequent
// searches, and signal an immediate re-search.
SG_LOG( SG_GENERAL, SG_WARN,
- "no metar at station = " << result.icao );
- const FGAirport* apt = globals->get_airports()->search(result.icao);
- const_cast<FGAirport*>(apt)->setMetar(false);
+ "no metar at station = " << result.airport->ident() );
+ result.airport->setMetar(false);
search_elapsed = 9999.0;
}
}
}
FGMetarResult
-FGMetarEnvironmentCtrl::fetch_data( const string &icao )
+FGMetarEnvironmentCtrl::fetch_data(FGAirport* apt)
{
FGMetarResult result;
- result.icao = icao;
+ result.airport = apt;
// if the last error was more than three seconds ago,
// then pretent nothing happened.
_error_count = 0;
}
- // fetch station elevation if exists
- const FGAirport* a = globals->get_airports()->search( icao );
- if ( a ) {
- station_elevation_ft = a->getElevation();
- }
+ station_elevation_ft = apt->getElevation();
// fetch current metar data
try {
string host = proxy_host->getStringValue();
string auth = proxy_auth->getStringValue();
string port = proxy_port->getStringValue();
- result.m = new FGMetar( icao, host, port, auth);
+ result.m = new FGMetar( apt->ident(), host, port, auth);
long max_age = metar_max_age->getLongValue();
long age = result.m->getAge_min();
void
FGMetarEnvironmentCtrl::thread_stop()
{
- request_queue.push( string() ); // ask thread to terminate
+ request_queue.push(NULL); // ask thread to terminate
thread->join();
}
{
while ( true )
{
- string icao = fetcher->request_queue.pop();
- if (icao.empty())
+ FGAirport* apt = fetcher->request_queue.pop();
+ if (!apt)
return;
- SG_LOG( SG_GENERAL, SG_INFO, "Thread: fetch metar data = " << icao );
- FGMetarResult result = fetcher->fetch_data( icao );
+ SG_LOG( SG_GENERAL, SG_INFO, "Thread: fetch metar data = " << apt->ident() );
+ FGMetarResult result = fetcher->fetch_data( apt );
fetcher->result_queue.push( result );
}
}