From 1cd070de8cbf00c861bfb0c98cc2cda30027e3fc Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Tue, 7 Apr 2015 11:59:07 +0200 Subject: [PATCH] Better fix for NoaaMetarGetRequest::onDone Keep a reference to the LiveMetarProperties while the HTTP request is active Also, drop the MetarDataHandler which was unneeded overhead --- src/Environment/realwx_ctrl.cxx | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Environment/realwx_ctrl.cxx b/src/Environment/realwx_ctrl.cxx index ac89e2862..a0abb7837 100644 --- a/src/Environment/realwx_ctrl.cxx +++ b/src/Environment/realwx_ctrl.cxx @@ -49,20 +49,11 @@ namespace Environment { /* -------------------------------------------------------------------------------- */ -class MetarDataHandler { -public: - virtual void handleMetarData( const std::string & data ) = 0; - virtual void handleMetarFailure() = 0; -}; - -class MetarRequester { -public: - virtual void requestMetar( MetarDataHandler * metarDataHandler, const std::string & id ) = 0; -}; +class MetarRequester; /* -------------------------------------------------------------------------------- */ -class LiveMetarProperties : public MetarProperties, MetarDataHandler { +class LiveMetarProperties : public MetarProperties { public: LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequester * metarRequester, int maxAge ); virtual ~LiveMetarProperties(); @@ -89,6 +80,12 @@ private: typedef SGSharedPtr LiveMetarProperties_ptr; +class MetarRequester { +public: + virtual void requestMetar( LiveMetarProperties_ptr metarDataHandler, const std::string & id ) = 0; +}; + + LiveMetarProperties::LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequester * metarRequester, int maxAge ) : MetarProperties( rootNode ), _timeToLive(0.0), @@ -346,10 +343,10 @@ void BasicRealWxController::removeMetarAtPath(const string &propPath) MetarPropertiesList::iterator it = findMetarAtPath( propPath ); if( it != _metarProperties.end() ) { SG_LOG(SG_ENVIRONMENT, SG_INFO, "removing metar properties at " << propPath); - LiveMetarProperties_ptr p(*it); // delay deletion until this goes out of scope when we return; no longer needed? +// LiveMetarProperties_ptr p(*it); // delay deletion until this goes out of scope when we return; no longer needed? // TODO: this doesn't actually delete it, because doing so invalidates the // BasicRealWxController::update iterator, causing a crash on Go To Airport - // _metarProperties.erase(it); + _metarProperties.erase(it); } else { SG_LOG(SG_ENVIRONMENT, SG_WARN, "no metar properties at " << propPath); } @@ -411,7 +408,7 @@ public: NoaaMetarRealWxController( SGPropertyNode_ptr rootNode ); // implementation of MetarRequester - virtual void requestMetar( MetarDataHandler * metarDataHandler, const std::string & id ); + virtual void requestMetar( LiveMetarProperties_ptr metarDataHandler, const std::string & id ); virtual ~NoaaMetarRealWxController() { @@ -427,7 +424,7 @@ NoaaMetarRealWxController::NoaaMetarRealWxController( SGPropertyNode_ptr rootNod void NoaaMetarRealWxController::requestMetar ( - MetarDataHandler* metarDataHandler, + LiveMetarProperties_ptr metarDataHandler, const std::string& id ) { @@ -437,7 +434,7 @@ void NoaaMetarRealWxController::requestMetar public simgear::HTTP::MemoryRequest { public: - NoaaMetarGetRequest( MetarDataHandler* metarDataHandler, + NoaaMetarGetRequest( LiveMetarProperties_ptr metarDataHandler, const std::string& stationId ): MemoryRequest(NOAA_BASE_URL + stationId + ".TXT"), _metarDataHandler(metarDataHandler) @@ -473,7 +470,7 @@ void NoaaMetarRealWxController::requestMetar } private: - MetarDataHandler * _metarDataHandler; + LiveMetarProperties_ptr _metarDataHandler; }; string upperId = boost::to_upper_copy(id); -- 2.39.5