From: curt Date: Wed, 16 Jan 2002 23:02:52 +0000 (+0000) Subject: Changes to support optional screen snap shot httpd server. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e75f6a8f0100f847cbe1bb8fc83a0c466dbe44f5;p=flightgear.git Changes to support optional screen snap shot httpd server. --- diff --git a/acconfig.h b/acconfig.h index cf7c32d07..dc4d593f8 100644 --- a/acconfig.h +++ b/acconfig.h @@ -53,7 +53,10 @@ /* Define to enable plib joystick support (recommended) */ #undef ENABLE_PLIB_JOYSTICK - + +/* Define to enable http jpeg server code */ +#undef FG_JPEG_SERVER + /* Define to eliminate all trace of debugging messages such as for a release build */ #undef FG_NDEBUG diff --git a/src/Cockpit/hud.hxx b/src/Cockpit/hud.hxx index a5ccd24bf..f92432974 100644 --- a/src/Cockpit/hud.hxx +++ b/src/Cockpit/hud.hxx @@ -172,6 +172,7 @@ extern float get_elev_trimval( void ); extern float get_rudderval ( void ); extern float get_speed ( void ); extern float get_aoa ( void ); +extern float get_nlf ( void ); extern float get_roll ( void ); extern float get_pitch ( void ); extern float get_heading ( void ); diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index ba1ce3681..9bd5d460c 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -40,6 +40,9 @@ #include #include #include +#ifdef FG_JPEG_SERVER +# include +#endif #include #include #include @@ -99,6 +102,14 @@ static FGProtocol *parse_port_config( const string& config ) FGHttpd *httpd = new FGHttpd( atoi(port.c_str()) ); io = httpd; short_circuit = true; +#ifdef FG_JPEG_SERVER + } else if ( protocol == "jpg-httpd" ) { + // determine port + string port = config.substr(begin); + FGJpegHttpd *jpeg_httpd = new FGJpegHttpd( atoi(port.c_str()) ); + io = jpeg_httpd; + short_circuit = true; +#endif } else if ( protocol == "joyclient" ) { FGJoyClient *joyclient = new FGJoyClient; io = joyclient; diff --git a/src/Main/options.cxx b/src/Main/options.cxx index ff7660b1d..d8b53bd13 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -787,6 +787,10 @@ parse_option (const string& arg) add_channel( "atlas", arg.substr(8) ); } else if ( arg.find( "--httpd=" ) == 0 ) { add_channel( "httpd", arg.substr(8) ); +#ifdef FG_JPEG_SERVER + } else if ( arg.find( "--jpg-httpd=" ) == 0 ) { + add_channel( "jpg-httpd", arg.substr(12) ); +#endif } else if ( arg.find( "--native=" ) == 0 ) { add_channel( "native", arg.substr(9) ); } else if ( arg.find( "--native-ctrls=" ) == 0 ) { @@ -1228,11 +1232,14 @@ fgUsage () << "\t\tdate/time. Uses Greenwich Mean Time" << endl; cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl << "\t\tdate/time. Uses Local Aircraft Time" << endl; -#ifdef FG_NETWORK_OLK cout << endl; cout << "Network Options:" << endl; cout << "\t--httpd=port: enable http server on the specified port" << endl; +#ifdef FG_JPEG_SERVER + cout << "\t--jpg-httpd=port: enable screen shot http server on the specified port" << endl; +#endif +#ifdef FG_NETWORK_OLK cout << "\t--enable-network-olk: enable Multipilot mode" << endl; cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl; cout << "\t--net-hud: Hud displays network info" << endl; diff --git a/src/Network/Makefile.am b/src/Network/Makefile.am index 5c1596cef..2eb3ace49 100644 --- a/src/Network/Makefile.am +++ b/src/Network/Makefile.am @@ -1,10 +1,17 @@ noinst_LIBRARIES = libNetwork.a +if ENABLE_JPEG_SERVER +JPEG_SERVER = jpg-httpd.cxx jpg-httpd.hxx +else +JPEG_SERVER = +endif + libNetwork_a_SOURCES = \ protocol.cxx protocol.hxx \ atlas.cxx atlas.hxx \ garmin.cxx garmin.hxx \ httpd.cxx httpd.hxx \ + $(JPEG_SERVER) \ joyclient.cxx joyclient.hxx \ native.cxx native.hxx \ native_ctrls.cxx native_ctrls.hxx \ diff --git a/src/Network/httpd.cxx b/src/Network/httpd.cxx index 4a8392525..ea67b700b 100644 --- a/src/Network/httpd.cxx +++ b/src/Network/httpd.cxx @@ -5,6 +5,9 @@ // // Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org // +// Jpeg Image Support added August 2001 +// by Norman Vine - nhv@cape.com +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the @@ -28,16 +31,16 @@ #include -#include -#include -#include -#include - #include // atoi() atof() #include STL_STRING #include STL_STRSTREAM +#include +#include +#include +#include + #include
#include
@@ -58,7 +61,7 @@ bool FGHttpd::open() { } server = new HttpdServer( port ); - + set_hz( 5 ); // default to processing requests @ 5Hz set_enabled( true ); @@ -82,6 +85,9 @@ bool FGHttpd::close() { // Handle http GET requests void HttpdChannel::foundTerminator (void) { + + closeWhenDone (); + const string s = buffer.getData(); if ( s.find( "GET " ) == 0 ) { diff --git a/src/Network/httpd.hxx b/src/Network/httpd.hxx index 56bdbedef..27aeb9b9d 100644 --- a/src/Network/httpd.hxx +++ b/src/Network/httpd.hxx @@ -5,6 +5,9 @@ // // Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org // +// Jpeg Image Support added August 2001 +// by Norman Vine - nhv@cape.com +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the @@ -71,11 +74,11 @@ class HttpdServer : private netChannel public: HttpdServer ( int port ) { - open () ; - bind ("", port) ; - listen (5) ; + open() ; + bind( "", port ); + listen( 5 ); - printf ( "Httpd server started on port %d\n", port ) ; + printf( "Httpd server started on port %d\n", port ) ; } }; @@ -84,7 +87,7 @@ class FGHttpd : public FGProtocol { int port; HttpdServer *server; - + public: inline FGHttpd( int p ) { port = p; } diff --git a/src/Network/jpg-httpd.cxx b/src/Network/jpg-httpd.cxx new file mode 100644 index 000000000..63afbffbd --- /dev/null +++ b/src/Network/jpg-httpd.cxx @@ -0,0 +1,126 @@ +// httpd.hxx -- FGFS http property manager interface / external script +// and control class +// +// Written by Curtis Olson, started June 2001. +// +// Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org +// +// Jpeg Image Support added August 2001 +// by Norman Vine - nhv@cape.com +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include // atoi() atof() + +#include STL_STRING +#include STL_STRSTREAM + +#include +#include +#include +#include + +#include
+#include
+ +#include "jpg-httpd.hxx" + +SG_USING_STD(string); +#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS) +SG_USING_STD(cout); +SG_USING_STD(istrstream); +#endif + + +bool FGJpegHttpd::open() { + if ( is_enabled() ) { + SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel " + << "is already in use, ignoring" ); + return false; + } + + imageServer = new HttpdImageServer( port ); + + set_hz( 5 ); // default to processing requests @ 5Hz + set_enabled( true ); + + return true; +} + + +bool FGJpegHttpd::process() { + netChannel::poll(); + + return true; +} + + +bool FGJpegHttpd::close() { + delete imageServer; + + return true; +} + + +// Handle http GET requests +void HttpdImageChannel::foundTerminator (void) { + + closeWhenDone (); + + string response; + + const string s = buffer.getData(); + if ( s.find( "GET " ) == 0 ) { + + printf("echo: %s\n", s.c_str()); + + int ImageLen = JpgFactory->render(); + + if( ImageLen ) { + response = "HTTP/1.1 200 OK"; + response += getTerminator(); + response += "Content-Type: image/jpeg"; + response += getTerminator(); + push( response.c_str() ); + + char ctmp[256]; + printf( "info->numbytes = %d\n", ImageLen ); + sprintf( ctmp, "Content-Length: %d", ImageLen ); + push( ctmp ); + + response = getTerminator(); + response += "Connection: close"; + response += getTerminator(); + response += getTerminator(); + push( response.c_str() ); + + /* can't use strlen on binary data */ + bufferSend ( (char *)JpgFactory->data(), ImageLen ) ; + } else { + printf("!!! NO IMAGE !!!\n\tinfo->numbytes = %d\n", ImageLen ); + } + } + + buffer.remove(); +} diff --git a/src/Network/jpg-httpd.hxx b/src/Network/jpg-httpd.hxx new file mode 100644 index 000000000..b51b6d376 --- /dev/null +++ b/src/Network/jpg-httpd.hxx @@ -0,0 +1,125 @@ +// httpd.hxx -- FGFS http property manager interface / external script +// and control class +// +// Written by Curtis Olson, started June 2001. +// +// Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org +// +// Jpeg Image Support added August 2001 +// by Norman Vine - nhv@cape.com +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifndef _FG_JPEG_HTTPD_HXX +#define _FG_JPEG_HTTPD_HXX + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#ifdef FG_JPEG_SERVER +# include +#endif + +#include "protocol.hxx" + +class trJpgFactory; + + +/* simple httpd server that makes an hasty stab at following the http + 1.1 rfc. */ + +class HttpdImageChannel : public netChat +{ + + netBuffer buffer ; + trJpgFactory *JpgFactory; + +public: + + HttpdImageChannel() : buffer(512) { + setTerminator("\r\n"); + JpgFactory = new trJpgFactory(); + + // This is a terrible hack but it can't be initialized until + // after OpenGL is up an running + JpgFactory->init(400,300); + } + + ~HttpdImageChannel() { + JpgFactory->destroy(); + delete JpgFactory; + } + + virtual void collectIncomingData (const char* s, int n) { + buffer.append(s,n); + } + + // Handle the actual http request + virtual void foundTerminator (void); +}; + + +class HttpdImageServer : private netChannel +{ + virtual bool writable (void) { return false ; } + + virtual void handleAccept (void) { + netAddress addr ; + int handle = accept ( &addr ) ; + printf("Client %s:%d connected\n", addr.getHost(), addr.getPort()); + + HttpdImageChannel *hc = new HttpdImageChannel; + hc->setHandle ( handle ) ; + } + +public: + + HttpdImageServer ( int port ) { + open (); + bind( "", port ); + listen( 5 ); + + printf( "HttpdImage server started on port %d\n", port ) ; + } + +}; + + +class FGJpegHttpd : public FGProtocol { + + int port; + HttpdImageServer *imageServer; + +public: + + inline FGJpegHttpd( int p ) { port = p; } + + inline ~FGJpegHttpd() { } + + bool open(); + + bool process(); + + bool close(); +}; + + +#endif // _FG_JPEG_HTTPD_HXX