~ubuntu-branches/debian/sid/flightgear/sid

« back to all changes in this revision

Viewing changes to src/Main/metar_main.cxx

  • Committer: Package Import Robot
  • Author(s): Markus Wanner, Markus Wanner, Rebecca Palmer
  • Date: 2014-01-21 22:31:02 UTC
  • mfrom: (1.3.1) (15.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20140121223102-cjw7g9le25acd119
Tags: 3.0.0~git20140204+c99ea4-1
[ Markus Wanner ]
* Upload to unstable.
* Adjust B-D to allow building on kfreebsd-*. Closes: #724686.
* Add a lintian-overrides on autotools; we use cmake.
* Upstream corrected the fgfs manpage. Closes: #556362.
* Drop unnecessary man page for gl-info. Closes: #698308.
* Drop README.Linux: it's outdated to the point of uselessness.
  Closes: #574173.
* Add an upper limit of libsimgear-dev versions that flightgear can be
  built with. Closes: #738436.
* Drop the libsvn-dev dependency, neither flightgear nor simgear depend
  on libsvn, anymore. Closes: #682947.
* List icons in debian/install rather than copying around from rules.
* Update menu entry for flightgear, add one for fgcom; add .xpm icons.
  Closes: #713924.
* flightgear.desktop: add German translation
* Bump Standards-Version to 3.9.5; no changes needed.

[ Rebecca Palmer ]
* New upstream release.
* Install the icons (based on code by Saikrishna Arcot).  (Not a
  complete fix for LP908153 as it only sets the menu/Dash icon, not the
  running window's icon, but better than nothing).
* Disable screensaver while running. Closes: LP#793599. Add required
  libdbus-1-dev dependency.
* Remove outdated README.Debian.
* Terrasync now works after just ticking the box. Closes: #252899.
* Always set Terrasync directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <string.h>
27
27
#include <time.h>
28
28
#include <cstdlib>
29
 
 
30
 
#include <simgear/debug/logstream.hxx>
 
29
#include <cstdio>
 
30
 
 
31
#include <boost/algorithm/string.hpp>
 
32
 
31
33
#include <simgear/environment/metar.hxx>
32
34
#include <simgear/structure/exception.hxx>
33
35
 
34
36
#include <simgear/io/HTTPClient.hxx>
35
 
#include <simgear/io/HTTPRequest.hxx>
 
37
#include <simgear/io/HTTPMemoryRequest.hxx>
36
38
#include <simgear/io/raw_socket.hxx>
37
39
#include <simgear/timing/timestamp.hxx>
38
40
 
39
41
using namespace std;
40
42
using namespace simgear;
41
43
 
42
 
class MetarRequest : public HTTP::Request
43
 
{
44
 
public:
45
 
    bool complete;
46
 
    bool failed;
47
 
    string metarData;
48
 
    bool fromProxy;
49
 
    
50
 
    MetarRequest(const std::string& stationId) : 
51
 
        HTTP::Request("http://weather.noaa.gov/pub/data/observations/metar/stations/" + stationId + ".TXT"),
52
 
        complete(false),
53
 
        failed(false)
54
 
    {
55
 
        fromProxy = false;
56
 
    }
57
 
    
58
 
protected:
59
 
    
60
 
    virtual void responseHeader(const string& key, const string& value)
61
 
    {
62
 
        if (key == "x-metarproxy") {
63
 
            fromProxy = true;
64
 
        }
65
 
    }
66
 
 
67
 
    virtual void gotBodyData(const char* s, int n)
68
 
    {
69
 
        metarData += string(s, n);
70
 
    }
71
 
 
72
 
    virtual void responseComplete()
73
 
    {
74
 
        if (responseCode() == 200) {
75
 
            complete = true;
76
 
        } else {
77
 
            SG_LOG(SG_ENVIRONMENT, SG_WARN, "metar download failed:" << url() << ": reason:" << responseReason());
78
 
            failed = true;
79
 
        }
80
 
    }
81
 
};
82
 
 
83
44
// text color
84
45
#if defined(__linux__) || defined(__sun) || defined(__CYGWIN__) \
85
46
    || defined( __FreeBSD__ ) || defined ( sgi )
329
290
                        surface.push_back(buf);
330
291
                }
331
292
 
332
 
                if (surface.size()) {
 
293
                if (! surface.empty()) {
333
294
                        vector<string>::iterator rwysurf = surface.begin();
334
295
                        for (i = 0; rwysurf != surface.end(); rwysurf++, i++) {
335
296
                                if (i)
576
537
                                shown = true;
577
538
                        }
578
539
 
579
 
                        try {
580
 
                MetarRequest* mr = new MetarRequest(argv[i]);
 
540
                        try
 
541
                        {
 
542
              static const std::string NOAA_BASE_URL =
 
543
                "http://weather.noaa.gov/pub/data/observations/metar/stations/";
 
544
                HTTP::MemoryRequest* mr = new HTTP::MemoryRequest
 
545
                (
 
546
                    NOAA_BASE_URL
 
547
                  + boost::to_upper_copy<std::string>(argv[i]) + ".TXT"
 
548
                );
581
549
                HTTP::Request_ptr own(mr);
582
550
                http.makeRequest(mr);
583
551
                
585
553
                SGTimeStamp start(SGTimeStamp::now());
586
554
                while (start.elapsedMSec() <  8000) {
587
555
                    http.update();
588
 
                    if (mr->complete || mr->failed) {
 
556
                    if( mr->isComplete() )
589
557
                        break;
590
 
                    }
591
558
                    SGTimeStamp::sleepForMSec(1);
592
559
                }
593
560
                
594
 
                if (!mr->complete) {
595
 
                    throw sg_io_exception("metar download failed (or timed out)");
 
561
                if( !mr->isComplete() )
 
562
                  throw sg_io_exception("metar download timed out");
 
563
                if( mr->responseCode() != 200 )
 
564
                {
 
565
                  std::cerr << "metar download failed: "
 
566
                            << mr->url()
 
567
                            << " (" << mr->responseCode()
 
568
                            << " " << mr->responseReason() << ")"
 
569
                            << std::endl;
 
570
                  throw sg_io_exception("metar download failed");
596
571
                }
597
 
                                SGMetar *m = new SGMetar(mr->metarData);
 
572
 
 
573
                                SGMetar *m = new SGMetar(mr->responseBody());
598
574
                                
599
575
                                //SGMetar *m = new SGMetar("2004/01/11 01:20\nLOWG 110120Z AUTO VRB01KT 0050 1600N R35/0600 FG M06/M06 Q1019 88//////\n");
600
576