#endif
#include "realwx_ctrl.hxx"
-#include "metarproperties.hxx"
-#include "metarairportfilter.hxx"
-#include "fgmetar.hxx"
-
-#include <Main/fg_props.hxx>
+#include <algorithm>
#include <boost/foreach.hpp>
#include <simgear/structure/exception.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/props/tiedpropertylist.hxx>
-#include <simgear/io/HTTPClient.hxx>
#include <simgear/io/HTTPRequest.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/structure/event_mgr.hxx>
-#include <algorithm>
+#include "metarproperties.hxx"
+#include "metarairportfilter.hxx"
+#include "fgmetar.hxx"
+#include <Network/HTTPClient.hxx>
+#include <Main/fg_props.hxx>
namespace Environment {
-/* -------------------------------------------------------------------------------- */
-class FGHTTPClient : public simgear::HTTP::Client {
-public:
- FGHTTPClient();
-};
-
-FGHTTPClient::FGHTTPClient()
-{
- string proxyHost(fgGetString("/sim/presets/proxy/host"));
- int proxyPort(fgGetInt("/sim/presets/proxy/port"));
- string proxyAuth(fgGetString("/sim/presets/proxy/auth"));
-
- if (!proxyHost.empty()) {
- setProxy(proxyHost, proxyPort, proxyAuth);
- }
-}
/* -------------------------------------------------------------------------------- */
fgGetNode( rootNode->getStringValue("metar", "/environment/metar"), true ), metarRequester ));
BOOST_FOREACH( SGPropertyNode_ptr n, rootNode->getChildren("metar") ) {
- SG_LOG( SG_ENVIRONMENT, SG_INFO, "Adding metar properties at " << n->getStringValue() );
- _metarProperties.push_back( new LiveMetarProperties(
- fgGetNode( n->getStringValue(), true ), metarRequester ));
+ SGPropertyNode_ptr metarNode = fgGetNode( n->getStringValue(), true );
+
+ // check for duplicate entries
+ bool existingElement = false;
+ BOOST_FOREACH( LiveMetarProperties_ptr p, _metarProperties ) {
+ if( p->get_root_node()->getPath() == metarNode->getPath() ) {
+ existingElement = true;
+ break;
+ }
+ }
+
+ if( existingElement )
+ continue;
+
+ SG_LOG( SG_ENVIRONMENT, SG_INFO, "Adding metar properties at " << metarNode->getPath() );
+ _metarProperties.push_back( new LiveMetarProperties( metarNode, metarRequester ));
}
}
class NoaaMetarRealWxController : public BasicRealWxController, MetarRequester {
public:
NoaaMetarRealWxController( SGPropertyNode_ptr rootNode );
- virtual ~NoaaMetarRealWxController();
- virtual void update( double dt );
// implementation of MetarRequester
virtual void requestMetar( MetarDataHandler * metarDataHandler, const std::string & id );
private:
- FGHTTPClient _http;
+
};
NoaaMetarRealWxController::NoaaMetarRealWxController( SGPropertyNode_ptr rootNode ) :
{
}
-NoaaMetarRealWxController::~NoaaMetarRealWxController()
-{
-}
-
-void NoaaMetarRealWxController::update( double dt )
-{
- _http.update();
- BasicRealWxController::update( dt );
-}
-
void NoaaMetarRealWxController::requestMetar( MetarDataHandler * metarDataHandler, const std::string & id )
{
class NoaaMetarGetRequest : public simgear::HTTP::Request
virtual void responseComplete()
{
if (responseCode() == 200) {
- _metarDataHandler->handleMetarData( _metar);
+ _metarDataHandler->handleMetarData( simgear::strutils::simplify(_metar) );
} else {
SG_LOG(SG_ENVIRONMENT, SG_WARN, "metar download failed:" << url() << ": reason:" << responseReason());
}
}
- bool fromMetarProxy() const
- { return _fromProxy; }
+// bool fromMetarProxy() const
+// { return _fromProxy; }
private:
string _metar;
bool _fromProxy;
SG_LOG(SG_ENVIRONMENT, SG_INFO,
"NoaaMetarRealWxController::update(): spawning load request for station-id '" << id << "'" );
- _http.makeRequest(new NoaaMetarGetRequest(metarDataHandler, id));
+ FGHTTPClient::instance()->makeRequest(new NoaaMetarGetRequest(metarDataHandler, id));
}
/* -------------------------------------------------------------------------------- */