Add support for a proxy server when retreiving metar data.
This commit is contained in:
parent
bca8c29795
commit
061f1688c3
2 changed files with 144 additions and 127 deletions
|
@ -317,6 +317,9 @@ FGInterpolateEnvironmentCtrl::bucket::operator< (const bucket &b) const
|
||||||
FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
|
FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
|
||||||
: env( new FGInterpolateEnvironmentCtrl ),
|
: env( new FGInterpolateEnvironmentCtrl ),
|
||||||
_icao( fgGetString("/sim/presets/airport-id") ),
|
_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 ),
|
update_interval_sec( 60.0 ),
|
||||||
elapsed( 60.0 )
|
elapsed( 60.0 )
|
||||||
{
|
{
|
||||||
|
@ -475,30 +478,25 @@ FGMetarEnvironmentCtrl::fetch_data (const string &icao)
|
||||||
SGMetar *m = NULL;
|
SGMetar *m = NULL;
|
||||||
#ifdef ENABLE_THREADS
|
#ifdef ENABLE_THREADS
|
||||||
|
|
||||||
bool valid_data = false;
|
// We are only interested in the latest metar report
|
||||||
if (!metar_queue.empty())
|
// FIXME: Do we want to keep the latest valid report instead?
|
||||||
{
|
while (!metar_queue.empty()) {
|
||||||
m = metar_queue.pop();
|
|
||||||
|
|
||||||
if (m != NULL)
|
if (m != NULL)
|
||||||
valid_data = true;
|
delete m;
|
||||||
|
|
||||||
|
m = metar_queue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( valid_data == false ) {
|
if ( m != NULL ) {
|
||||||
mutex.lock();
|
|
||||||
metar_cond.signal();
|
|
||||||
mutex.unlock();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
try {
|
try {
|
||||||
m = new SGMetar( _icao.c_str() );
|
string host = proxy_host->getStringValue();
|
||||||
} catch (const sg_io_exception& e) {
|
string auth = proxy_auth->getStringValue();
|
||||||
SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
|
string port = proxy_port->getStringValue();
|
||||||
<< e.getFormattedMessage().c_str() );
|
m = new SGMetar( _icao, host, port, auth);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif // ENABLE_THREADS
|
#endif // ENABLE_THREADS
|
||||||
|
|
||||||
d = m->getMinVisibility().getVisibility_m();
|
d = m->getMinVisibility().getVisibility_m();
|
||||||
|
@ -606,10 +604,22 @@ FGMetarEnvironmentCtrl::fetch_data (const string &icao)
|
||||||
|
|
||||||
delete m;
|
delete m;
|
||||||
|
|
||||||
|
}
|
||||||
#ifdef ENABLE_THREADS
|
#ifdef ENABLE_THREADS
|
||||||
|
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
metar_cond.signal();
|
metar_cond.signal();
|
||||||
mutex.unlock();
|
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
|
#endif // ENABLE_THREADS
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -632,7 +642,10 @@ FGMetarEnvironmentCtrl::MetarThread::run()
|
||||||
{
|
{
|
||||||
cout << "Fetching ..." << endl;
|
cout << "Fetching ..." << endl;
|
||||||
// if (m != NULL) m = NULL;
|
// 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) {
|
} catch (const sg_io_exception& e) {
|
||||||
// SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
|
// SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
|
||||||
|
|
|
@ -158,13 +158,17 @@ public:
|
||||||
private:
|
private:
|
||||||
FGInterpolateEnvironmentCtrl *env;
|
FGInterpolateEnvironmentCtrl *env;
|
||||||
|
|
||||||
string _icao;
|
|
||||||
float station_elevation_ft;
|
float station_elevation_ft;
|
||||||
float update_interval_sec;
|
float update_interval_sec;
|
||||||
float elapsed;
|
float elapsed;
|
||||||
bool fetch_data (const string &icao);
|
bool fetch_data (const string &icao);
|
||||||
void update_env_config();
|
void update_env_config();
|
||||||
|
|
||||||
|
string _icao;
|
||||||
|
SGPropertyNode *proxy_host;
|
||||||
|
SGPropertyNode *proxy_port;
|
||||||
|
SGPropertyNode *proxy_auth;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#ifdef ENABLE_THREADS
|
#ifdef ENABLE_THREADS
|
||||||
|
|
Loading…
Add table
Reference in a new issue