]> git.mxchange.org Git - flightgear.git/blob - src/Network/jpg-httpd.hxx
Merge branch 'jmt/track-bug' into next
[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 #ifdef HAVE_CONFIG_H
32 #  include <config.h>
33 #endif
34
35 #include <plib/netChat.h>
36
37 #ifdef FG_JPEG_SERVER
38 #  include <simgear/screen/jpgfactory.hxx>
39 #else
40 // dummy it in to keep the compiler happy
41 class trJpgFactory {
42 public:
43     trJpgFactory();
44     void init(int, int);
45     void destroy();
46     int render();
47     void setFrustum(double,double,double,double,double,double);
48   void *data();
49 };
50 #endif
51
52 #include "protocol.hxx"
53
54 class trJpgFactory;
55
56
57 /* simple httpd server that makes an hasty stab at following the http
58    1.1 rfc.  */
59
60 class HttpdImageChannel : public netChat
61 {
62
63     netBuffer buffer ;
64     trJpgFactory *JpgFactory;
65     
66 public:
67
68     HttpdImageChannel() : buffer(512) {
69
70         int nWidth  = fgGetInt( "/sim/startup/xsize", 800 );
71         int nHeight = fgGetInt( "/sim/startup/ysize", 600 );
72
73         setTerminator("\r\n");
74         JpgFactory = new trJpgFactory();
75         JpgFactory -> init( nWidth, nHeight );
76     }
77
78     ~HttpdImageChannel() {
79         JpgFactory -> destroy();
80         delete JpgFactory;
81     }
82
83     virtual void collectIncomingData (const char* s, int n) {
84         buffer.append(s,n);
85     }
86
87     // Handle the actual http request
88     virtual void foundTerminator (void);
89 };
90
91
92 class HttpdImageServer : private netChannel
93 {
94     virtual bool writable (void) { return false ; }
95
96     virtual void handleAccept (void) {
97         netAddress addr ;
98         int handle = accept ( &addr ) ;
99         SG_LOG( SG_IO, SG_INFO, "Client " << addr.getHost() << ":" << addr.getPort() << " connected" );
100
101         HttpdImageChannel *hc = new HttpdImageChannel;
102         hc->setHandle ( handle ) ;
103     }
104
105 public:
106
107     HttpdImageServer ( int port ) {
108         open ();
109         bind( "", port );
110         listen( 5 );
111
112         printf( "HttpdImage server started on port %d\n", port ) ;
113     }
114         
115 };
116
117
118 class FGJpegHttpd : public FGProtocol {
119
120     int port;
121     HttpdImageServer *imageServer;
122     
123 public:
124
125     inline FGJpegHttpd( int p ) { port = p; }
126
127     inline ~FGJpegHttpd() { }
128
129     bool open();
130
131     bool process();
132
133     bool close();
134 };
135
136
137 #endif // _FG_JPEG_HTTPD_HXX