- NoaaMetarGetRequest(MetarDataHandler* metarDataHandler, const string& stationId ) :
- Request("http://weather.noaa.gov/pub/data/observations/metar/stations/" + stationId + ".TXT"),
- _fromProxy(false),
- _metarDataHandler(metarDataHandler)
- {
- }
-
- virtual string_list requestHeaders() const
- {
- string_list reply;
- reply.push_back("X-TIME");
- return reply;
- }
-
- virtual std::string header(const std::string& name) const
- {
- string reply;
-
- if( name == "X-TIME" ) {
- std::ostringstream buf;
- buf << globals->get_time_params()->get_cur_time();
- reply = buf.str();
- }
-
- return reply;
- }
-
- virtual void responseHeader(const string& key, const string& value)
- {
- if (key == "x-metarproxy") {
- _fromProxy = true;
- }
- }
-
- virtual void gotBodyData(const char* s, int n)
- {
- _metar += string(s, n);
- }
-
- virtual void responseComplete()
- {
- if (responseCode() == 200) {
- _metarDataHandler->handleMetarData( simgear::strutils::simplify(_metar) );
- } else {
- SG_LOG(SG_ENVIRONMENT, SG_WARN, "metar download failed:" << url() << ": reason:" << responseReason());
- }
- }
-
-// bool fromMetarProxy() const
-// { return _fromProxy; }
- private:
- string _metar;
- bool _fromProxy;
- MetarDataHandler * _metarDataHandler;
- };
-
- string upperId = boost::to_upper_copy(id);
-
- SG_LOG(SG_ENVIRONMENT, SG_INFO,
- "NoaaMetarRealWxController::update(): spawning load request for station-id '" << upperId << "'" );
- FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
- if (http) {
- http->makeRequest(new NoaaMetarGetRequest(metarDataHandler, upperId));
- }
+ NoaaMetarGetRequest( MetarDataHandler* metarDataHandler,
+ const std::string& stationId ):
+ MemoryRequest(NOAA_BASE_URL + stationId + ".TXT"),
+ _metarDataHandler(metarDataHandler)
+ {
+ std::ostringstream buf;
+ buf << globals->get_time_params()->get_cur_time();
+ requestHeader("X-TIME") = buf.str();
+ }
+
+ virtual void onDone()
+ {
+ if( responseCode() != 200 )
+ {
+ SG_LOG
+ (
+ SG_ENVIRONMENT,
+ SG_WARN,
+ "metar download failed:" << url() << ": reason:" << responseReason()
+ );
+ return;
+ }
+
+ _metarDataHandler->handleMetarData
+ (
+ simgear::strutils::simplify(responseBody())
+ );
+ }
+
+ virtual void onFail()
+ {
+ SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failure");
+ }
+
+ private:
+ MetarDataHandler * _metarDataHandler;
+ };
+
+ string upperId = boost::to_upper_copy(id);
+
+ SG_LOG
+ (
+ SG_ENVIRONMENT,
+ SG_INFO,
+ "NoaaMetarRealWxController::update(): "
+ "spawning load request for station-id '" << upperId << "'"
+ );
+ FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+ if (http) {
+ http->makeRequest(new NoaaMetarGetRequest(metarDataHandler, upperId));
+ }