From: James Turner <zakalawe@mac.com>
Date: Thu, 24 Mar 2016 15:08:38 +0000 (+0000)
Subject: HTTP subsystem has a default name.
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=733e3b3f0c8ed5c880b57e3175dd6e5e3fd0ce9c;p=flightgear.git

HTTP subsystem has a default name.

Switch to using type-safe accessors now.
---

diff --git a/src/Canvas/FGCanvasSystemAdapter.cxx b/src/Canvas/FGCanvasSystemAdapter.cxx
index c85b0fa28..e95f86efc 100644
--- a/src/Canvas/FGCanvasSystemAdapter.cxx
+++ b/src/Canvas/FGCanvasSystemAdapter.cxx
@@ -109,8 +109,7 @@ namespace canvas
   //----------------------------------------------------------------------------
   simgear::HTTP::Client* FGCanvasSystemAdapter::getHTTPClient() const
   {
-    FGHTTPClient* http =
-      static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+    FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
 
     if( http )
       return http->client();
diff --git a/src/Environment/realwx_ctrl.cxx b/src/Environment/realwx_ctrl.cxx
index 104d7db59..d01419794 100644
--- a/src/Environment/realwx_ctrl.cxx
+++ b/src/Environment/realwx_ctrl.cxx
@@ -479,7 +479,7 @@ void NoaaMetarRealWxController::requestMetar
     "NoaaMetarRealWxController::update(): "
     "spawning load request for station-id '" << upperId << "'"
   );
-  FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+  FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
   if (http) {
       http->makeRequest(new NoaaMetarGetRequest(metarDataHandler, upperId));
   }
diff --git a/src/GUI/PathsDialog.cxx b/src/GUI/PathsDialog.cxx
index c68cc1ecf..1809c7114 100644
--- a/src/GUI/PathsDialog.cxx
+++ b/src/GUI/PathsDialog.cxx
@@ -182,7 +182,7 @@ void PathsDialog::onAddCatalog()
 void PathsDialog::onAddDefaultCatalog()
 {
     // check it's not a duplicate somehow
-    FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+    FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
     if (http->isDefaultCatalogInstalled())
         return;
 
@@ -199,7 +199,7 @@ void PathsDialog::onAddDefaultCatalog()
 void PathsDialog::onRemoveCatalog()
 {
     QModelIndex mi = m_ui->catalogsList->currentIndex();
-    FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+    FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
 
     if (mi.isValid()) {
         QString s = QString("Remove aircraft hangar '%1'? All installed aircraft from this "
@@ -260,6 +260,6 @@ void PathsDialog::updateUi()
     QString m = tr("Download location: %1").arg(s);
     m_ui->downloadLocation->setText(m);
 
-    FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+    FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
     m_ui->addDefaultCatalogButton->setEnabled(!http->isDefaultCatalogInstalled());
 }
diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx
index 6357e94b3..c95fc907a 100644
--- a/src/GUI/QtLauncher.cxx
+++ b/src/GUI/QtLauncher.cxx
@@ -415,8 +415,8 @@ bool runLauncherDialog()
     fgInitPackageRoot();
 
     // startup the HTTP system now since packages needs it
-    FGHTTPClient* http = new FGHTTPClient;
-    globals->add_subsystem("http", http);
+    FGHTTPClient* http = globals->add_new_subsystem<FGHTTPClient>();
+    
     // we guard against re-init in the global phase; bind and postinit
     // will happen as normal
     http->init();
diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx
index 3febb590c..0c47e860b 100644
--- a/src/Main/fg_init.cxx
+++ b/src/Main/fg_init.cxx
@@ -738,8 +738,8 @@ void fgCreateSubsystems(bool duringReset) {
     }
 
     // may exist already due to GUI startup
-    if (!globals->get_subsystem("http")) {
-        globals->add_subsystem( "http", new FGHTTPClient );
+    if (!globals->get_subsystem<FGHTTPClient>()) {
+        globals->add_new_subsystem<FGHTTPClient>();
     }
 
     ////////////////////////////////////////////////////////////////////
diff --git a/src/MultiPlayer/multiplaymgr.cxx b/src/MultiPlayer/multiplaymgr.cxx
index 0883bc1bf..4cb5b6b4b 100644
--- a/src/MultiPlayer/multiplaymgr.cxx
+++ b/src/MultiPlayer/multiplaymgr.cxx
@@ -435,7 +435,7 @@ static bool do_multiplayer_refreshserverlist(const SGPropertyNode * arg) {
 		return false;
 	}
 
-	FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+    FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
 	if (!http) {
 		SG_LOG(SG_IO, SG_ALERT,
 				"do_multiplayer.refreshserverlist: HTTP client not running");
diff --git a/src/Network/HTTPClient.cxx b/src/Network/HTTPClient.cxx
index e6d2b29d7..cf4b490db 100644
--- a/src/Network/HTTPClient.cxx
+++ b/src/Network/HTTPClient.cxx
@@ -342,6 +342,8 @@ void FGHTTPClient::shutdown()
 
     _packageDelegate.reset();
     _http.reset();
+
+    _inited = false;
 }
 
 void FGHTTPClient::update(double)
diff --git a/src/Network/HTTPClient.hxx b/src/Network/HTTPClient.hxx
index 3a92ee1ef..fe2396585 100644
--- a/src/Network/HTTPClient.hxx
+++ b/src/Network/HTTPClient.hxx
@@ -46,6 +46,8 @@ public:
 
     std::string getDefaultCatalogId() const;
     std::string getDefaultCatalogUrl() const;
+
+    static const char* subsystemName() { return "http"; } 
 private:
     class FGDelegate;
     
diff --git a/src/Scripting/NasalHTTP.cxx b/src/Scripting/NasalHTTP.cxx
index 637e3a3ac..7556db721 100644
--- a/src/Scripting/NasalHTTP.cxx
+++ b/src/Scripting/NasalHTTP.cxx
@@ -39,8 +39,7 @@ typedef nasal::Ghost<simgear::HTTP::MemoryRequestRef> NasalMemoryRequest;
 
 FGHTTPClient& requireHTTPClient(naContext c)
 {
-  FGHTTPClient* http =
-    static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+  FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
   if( !http )
     naRuntimeError(c, "Failed to get HTTP subsystem");