1
0
Fork 0

Add support for a proxy server when retreiving metar data.

This commit is contained in:
ehofman 2004-02-26 10:23:48 +00:00
parent bca8c29795
commit 061f1688c3
2 changed files with 144 additions and 127 deletions

View file

@ -317,6 +317,9 @@ FGInterpolateEnvironmentCtrl::bucket::operator< (const bucket &b) const
FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
: env( new FGInterpolateEnvironmentCtrl ),
_icao( fgGetString("/sim/presets/airport-id") ),
proxy_host( fgGetNode("/sim/presets/proxy/host", true) ),
proxy_port( fgGetNode("/sim/presets/proxy/port", true) ),
proxy_auth( fgGetNode("/sim/presets/proxy/authentication", true) ),
update_interval_sec( 60.0 ),
elapsed( 60.0 )
{
@ -475,30 +478,25 @@ FGMetarEnvironmentCtrl::fetch_data (const string &icao)
SGMetar *m = NULL;
#ifdef ENABLE_THREADS
bool valid_data = false;
if (!metar_queue.empty())
{
m = metar_queue.pop();
// We are only interested in the latest metar report
// FIXME: Do we want to keep the latest valid report instead?
while (!metar_queue.empty()) {
if (m != NULL)
valid_data = true;
delete m;
m = metar_queue.pop();
}
if ( valid_data == false ) {
mutex.lock();
metar_cond.signal();
mutex.unlock();
if ( m != NULL ) {
return false;
}
#else
try {
m = new SGMetar( _icao.c_str() );
} catch (const sg_io_exception& e) {
SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
<< e.getFormattedMessage().c_str() );
return false;
}
string host = proxy_host->getStringValue();
string auth = proxy_auth->getStringValue();
string port = proxy_port->getStringValue();
m = new SGMetar( _icao, host, port, auth);
#endif // ENABLE_THREADS
d = m->getMinVisibility().getVisibility_m();
@ -606,10 +604,22 @@ FGMetarEnvironmentCtrl::fetch_data (const string &icao)
delete m;
}
#ifdef ENABLE_THREADS
mutex.lock();
metar_cond.signal();
mutex.unlock();
if (m == NULL)
return false;
#else
catch (const sg_io_exception& e) {
SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
<< e.getFormattedMessage().c_str() );
return false;
}
#endif // ENABLE_THREADS
return true;
@ -632,7 +642,10 @@ FGMetarEnvironmentCtrl::MetarThread::run()
{
cout << "Fetching ..." << endl;
// if (m != NULL) m = NULL;
m = new SGMetar( fetcher->_icao.c_str() );
string host = fetcher->proxy_host->getStringValue();
string auth = fetcher->proxy_auth->getStringValue();
string port = fetcher->proxy_port->getStringValue();
m = new SGMetar( fetcher->_icao, host, port, auth );
} catch (const sg_io_exception& e) {
// SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "

View file

@ -158,13 +158,17 @@ public:
private:
FGInterpolateEnvironmentCtrl *env;
string _icao;
float station_elevation_ft;
float update_interval_sec;
float elapsed;
bool fetch_data (const string &icao);
void update_env_config();
string _icao;
SGPropertyNode *proxy_host;
SGPropertyNode *proxy_port;
SGPropertyNode *proxy_auth;
private:
#ifdef ENABLE_THREADS