1 // httpd.hxx -- FGFS http property manager interface / external script
4 // Written by Curtis Olson, started June 2001.
6 // Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
8 // Jpeg Image Support added August 2001
9 // by Norman Vine - nhv@cape.com
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.
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.
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.
28 #ifndef _FG_JPEG_HTTPD_HXX
29 #define _FG_JPEG_HTTPD_HXX
35 #include <plib/netChat.h>
38 # include <simgear/screen/jpgfactory.hxx>
40 // dummy it in to keep the compiler happy
51 #include "protocol.hxx"
56 /* simple httpd server that makes an hasty stab at following the http
59 class HttpdImageChannel : public netChat
63 trJpgFactory *JpgFactory;
67 HttpdImageChannel() : buffer(512) {
69 int nWidth = fgGetInt( "/sim/startup/xsize", 800 );
70 int nHeight = fgGetInt( "/sim/startup/ysize", 600 );
72 setTerminator("\r\n");
73 JpgFactory = new trJpgFactory();
74 JpgFactory -> init( nWidth, nHeight );
77 ~HttpdImageChannel() {
78 JpgFactory -> destroy();
82 virtual void collectIncomingData (const char* s, int n) {
86 // Handle the actual http request
87 virtual void foundTerminator (void);
91 class HttpdImageServer : private netChannel
93 virtual bool writable (void) { return false ; }
95 virtual void handleAccept (void) {
97 int handle = accept ( &addr ) ;
98 SG_LOG( SG_IO, SG_INFO, "Client " << addr.getHost() << ":" << addr.getPort() << " connected" );
100 HttpdImageChannel *hc = new HttpdImageChannel;
101 hc->setHandle ( handle ) ;
106 HttpdImageServer ( int port ) {
111 printf( "HttpdImage server started on port %d\n", port ) ;
117 class FGJpegHttpd : public FGProtocol {
120 HttpdImageServer *imageServer;
124 inline FGJpegHttpd( int p ) { port = p; }
126 inline ~FGJpegHttpd() { }
136 #endif // _FG_JPEG_HTTPD_HXX