]> git.mxchange.org Git - flightgear.git/blob - src/Network/jpg-httpd.hxx
Add properties for raw axis and button values, for use
[flightgear.git] / src / Network / jpg-httpd.hxx
1 // httpd.hxx -- FGFS http property manager interface / external script
2 //              and control class
3 //
4 // Written by Curtis Olson, started June 2001.
5 //
6 // Copyright (C) 2001  Curtis L. Olson - http://www.flightgear.org/~curt
7 //
8 // Jpeg Image Support added August 2001
9 //  by Norman Vine - nhv@cape.com
10 //
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of the
14 // License, or (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 // General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24 //
25 // $Id$
26
27
28 #ifndef _FG_JPEG_HTTPD_HXX
29 #define _FG_JPEG_HTTPD_HXX
30
31 #include <simgear/io/sg_netChat.hxx>
32 #include <simgear/screen/jpgfactory.hxx>
33
34 #include "protocol.hxx"
35
36
37 /* simple httpd server that makes an hasty stab at following the http
38    1.1 rfc.  */
39
40 class HttpdImageChannel : public simgear::NetChat
41 {
42
43     simgear::NetBuffer buffer ;
44     trJpgFactory *JpgFactory;
45     
46 public:
47
48     HttpdImageChannel() : buffer(512) {
49
50         int nWidth  = fgGetInt( "/sim/startup/xsize", 800 );
51         int nHeight = fgGetInt( "/sim/startup/ysize", 600 );
52
53         setTerminator("\r\n");
54         JpgFactory = new trJpgFactory();
55         JpgFactory -> init( nWidth, nHeight );
56     }
57
58     ~HttpdImageChannel() {
59         JpgFactory -> destroy();
60         delete JpgFactory;
61     }
62
63     virtual void collectIncomingData (const char* s, int n) {
64         buffer.append(s,n);
65     }
66
67     // Handle the actual http request
68     virtual void foundTerminator (void);
69 };
70
71
72 class HttpdImageServer : private simgear::NetChannel
73 {
74     virtual bool writable (void) { return false ; }
75
76     virtual void handleAccept (void) {
77         simgear::IPAddress addr ;
78         int handle = accept ( &addr ) ;
79         SG_LOG( SG_IO, SG_INFO, "Client " << addr.getHost() << ":" << addr.getPort() << " connected" );
80
81         HttpdImageChannel *hc = new HttpdImageChannel;
82         hc->setHandle ( handle ) ;
83     }
84
85 public:
86
87     HttpdImageServer ( int port ) {
88         open ();
89         bind( "", port );
90         listen( 5 );
91
92         printf( "HttpdImage server started on port %d\n", port ) ;
93     }
94         
95 };
96
97
98 class FGJpegHttpd : public FGProtocol {
99
100     int port;
101     HttpdImageServer *imageServer;
102     
103 public:
104
105     inline FGJpegHttpd( int p ) { port = p; }
106
107     inline ~FGJpegHttpd() { }
108
109     bool open();
110
111     bool process();
112
113     bool close();
114 };
115
116
117 #endif // _FG_JPEG_HTTPD_HXX