Avoid some statics, and incidentally make the proxy host/port settings dynamic (re-init the subsystem to update proxy settings, woo).
SG_LOG(SG_ENVIRONMENT, SG_INFO,
"NoaaMetarRealWxController::update(): spawning load request for station-id '" << upperId << "'" );
- FGHTTPClient::instance()->makeRequest(new NoaaMetarGetRequest(metarDataHandler, upperId));
+ FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+ if (http) {
+ http->makeRequest(new NoaaMetarGetRequest(metarDataHandler, upperId));
+ }
}
/* -------------------------------------------------------------------------------- */
static bool
do_load_xml_from_url(const SGPropertyNode * arg)
{
+ FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+ if (!http) {
+ SG_LOG(SG_IO, SG_ALERT, "xmlhttprequest: HTTP client not running");
+ return false;
+ }
+
std::string url(arg->getStringValue("url"));
if (url.empty())
return false;
if (arg->hasValue("status"))
req->setStatusProp(fgGetNode(arg->getStringValue("status"), true));
- FGHTTPClient::instance()->makeRequest(req);
-
+ http->makeRequest(req);
return true;
}
#include <Navaids/NavDataCache.hxx>
#include <Instrumentation/HUD/HUD.hxx>
#include <Cockpit/cockpitDisplayManager.hxx>
+#include <Network/HTTPClient.hxx>
#include "fg_init.hxx"
#include "fg_io.hxx"
// Initialize the Input-Output subsystem
////////////////////////////////////////////////////////////////////
globals->add_subsystem( "io", new FGIO );
-
+ globals->add_subsystem( "http", new FGHTTPClient );
+
////////////////////////////////////////////////////////////////////
// Create and register the logger.
////////////////////////////////////////////////////////////////////
#include <Network/ray.hxx>
#include <Network/rul.hxx>
#include <Network/generic.hxx>
-#include <Network/HTTPClient.hxx>
#ifdef FG_HAVE_HLA
#include <Network/HLA/hla.hxx>
void
FGIO::update( double /* delta_time_sec */ )
{
- if (FGHTTPClient::haveInstance()) {
- FGHTTPClient::instance()->update();
- }
-
// use wall-clock, not simulation, delta time, so that network
// protocols update when the simulation is paused
// see http://code.google.com/p/flightgear-bugs/issues/detail?id=125
#include "HTTPClient.hxx"
#include <Main/fg_props.hxx>
+#include <simgear/sg_inlines.h>
-static FGHTTPClient* static_instance = NULL;
+FGHTTPClient::FGHTTPClient()
+{
+}
-FGHTTPClient* FGHTTPClient::instance()
+FGHTTPClient::~FGHTTPClient()
{
- if (!static_instance) {
- static_instance = new FGHTTPClient;
- }
-
- return static_instance;
}
-bool FGHTTPClient::haveInstance()
+void FGHTTPClient::init()
{
- return (static_instance != NULL);
+ _http.reset(new simgear::HTTP::Client);
+
+ std::string proxyHost(fgGetString("/sim/presets/proxy/host"));
+ int proxyPort(fgGetInt("/sim/presets/proxy/port"));
+ std::string proxyAuth(fgGetString("/sim/presets/proxy/auth"));
+
+ if (!proxyHost.empty()) {
+ _http->setProxy(proxyHost, proxyPort, proxyAuth);
+ }
}
-FGHTTPClient::FGHTTPClient()
+void FGHTTPClient::shutdown()
{
- std::string proxyHost(fgGetString("/sim/presets/proxy/host"));
- int proxyPort(fgGetInt("/sim/presets/proxy/port"));
- std::string proxyAuth(fgGetString("/sim/presets/proxy/auth"));
-
- if (!proxyHost.empty()) {
- setProxy(proxyHost, proxyPort, proxyAuth);
- }
+ _http.reset();
}
+
+void FGHTTPClient::update(double dt)
+{
+ SG_UNUSED(dt);
+ _http->update();
+}
+
+void FGHTTPClient::makeRequest(const simgear::HTTP::Request_ptr& req)
+{
+ _http->makeRequest(req);
+}
\ No newline at end of file
#ifndef FG_HTTP_CLIENT_HXX
#define FG_HTTP_CLIENT_HXX
+#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/io/HTTPClient.hxx>
+#include <memory>
-class FGHTTPClient : public simgear::HTTP::Client {
+class FGHTTPClient : public SGSubsystem
+{
public:
- static FGHTTPClient* instance();
-
- static bool haveInstance();
-private:
FGHTTPClient();
+ virtual ~FGHTTPClient();
+
+ void makeRequest(const simgear::HTTP::Request_ptr& req);
+
+ virtual void init();
+ virtual void shutdown();
+ virtual void update(double dt);
+
+private:
+ std::auto_ptr<simgear::HTTP::Client> _http;
};
#endif // FG_HTTP_CLIENT_HXX