Changes to support optional screen snap shot httpd server.
This commit is contained in:
parent
1779e8b8bd
commit
e75f6a8f01
9 changed files with 302 additions and 13 deletions
|
@ -53,7 +53,10 @@
|
||||||
|
|
||||||
/* Define to enable plib joystick support (recommended) */
|
/* Define to enable plib joystick support (recommended) */
|
||||||
#undef ENABLE_PLIB_JOYSTICK
|
#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
|
/* Define to eliminate all trace of debugging messages such as for a
|
||||||
release build */
|
release build */
|
||||||
#undef FG_NDEBUG
|
#undef FG_NDEBUG
|
||||||
|
|
|
@ -172,6 +172,7 @@ extern float get_elev_trimval( void );
|
||||||
extern float get_rudderval ( void );
|
extern float get_rudderval ( void );
|
||||||
extern float get_speed ( void );
|
extern float get_speed ( void );
|
||||||
extern float get_aoa ( void );
|
extern float get_aoa ( void );
|
||||||
|
extern float get_nlf ( void );
|
||||||
extern float get_roll ( void );
|
extern float get_roll ( void );
|
||||||
extern float get_pitch ( void );
|
extern float get_pitch ( void );
|
||||||
extern float get_heading ( void );
|
extern float get_heading ( void );
|
||||||
|
|
|
@ -40,6 +40,9 @@
|
||||||
#include <Network/atlas.hxx>
|
#include <Network/atlas.hxx>
|
||||||
#include <Network/garmin.hxx>
|
#include <Network/garmin.hxx>
|
||||||
#include <Network/httpd.hxx>
|
#include <Network/httpd.hxx>
|
||||||
|
#ifdef FG_JPEG_SERVER
|
||||||
|
# include <Network/jpg-httpd.hxx>
|
||||||
|
#endif
|
||||||
#include <Network/joyclient.hxx>
|
#include <Network/joyclient.hxx>
|
||||||
#include <Network/native.hxx>
|
#include <Network/native.hxx>
|
||||||
#include <Network/native_ctrls.hxx>
|
#include <Network/native_ctrls.hxx>
|
||||||
|
@ -99,6 +102,14 @@ static FGProtocol *parse_port_config( const string& config )
|
||||||
FGHttpd *httpd = new FGHttpd( atoi(port.c_str()) );
|
FGHttpd *httpd = new FGHttpd( atoi(port.c_str()) );
|
||||||
io = httpd;
|
io = httpd;
|
||||||
short_circuit = true;
|
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" ) {
|
} else if ( protocol == "joyclient" ) {
|
||||||
FGJoyClient *joyclient = new FGJoyClient;
|
FGJoyClient *joyclient = new FGJoyClient;
|
||||||
io = joyclient;
|
io = joyclient;
|
||||||
|
|
|
@ -787,6 +787,10 @@ parse_option (const string& arg)
|
||||||
add_channel( "atlas", arg.substr(8) );
|
add_channel( "atlas", arg.substr(8) );
|
||||||
} else if ( arg.find( "--httpd=" ) == 0 ) {
|
} else if ( arg.find( "--httpd=" ) == 0 ) {
|
||||||
add_channel( "httpd", arg.substr(8) );
|
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 ) {
|
} else if ( arg.find( "--native=" ) == 0 ) {
|
||||||
add_channel( "native", arg.substr(9) );
|
add_channel( "native", arg.substr(9) );
|
||||||
} else if ( arg.find( "--native-ctrls=" ) == 0 ) {
|
} else if ( arg.find( "--native-ctrls=" ) == 0 ) {
|
||||||
|
@ -1228,11 +1232,14 @@ fgUsage ()
|
||||||
<< "\t\tdate/time. Uses Greenwich Mean Time" << endl;
|
<< "\t\tdate/time. Uses Greenwich Mean Time" << endl;
|
||||||
cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
|
cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
|
||||||
<< "\t\tdate/time. Uses Local Aircraft Time" << endl;
|
<< "\t\tdate/time. Uses Local Aircraft Time" << endl;
|
||||||
#ifdef FG_NETWORK_OLK
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
cout << "Network Options:" << endl;
|
cout << "Network Options:" << endl;
|
||||||
cout << "\t--httpd=port: enable http server on the specified port" << 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--enable-network-olk: enable Multipilot mode" << endl;
|
||||||
cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
|
cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
|
||||||
cout << "\t--net-hud: Hud displays network info" << endl;
|
cout << "\t--net-hud: Hud displays network info" << endl;
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
noinst_LIBRARIES = libNetwork.a
|
noinst_LIBRARIES = libNetwork.a
|
||||||
|
|
||||||
|
if ENABLE_JPEG_SERVER
|
||||||
|
JPEG_SERVER = jpg-httpd.cxx jpg-httpd.hxx
|
||||||
|
else
|
||||||
|
JPEG_SERVER =
|
||||||
|
endif
|
||||||
|
|
||||||
libNetwork_a_SOURCES = \
|
libNetwork_a_SOURCES = \
|
||||||
protocol.cxx protocol.hxx \
|
protocol.cxx protocol.hxx \
|
||||||
atlas.cxx atlas.hxx \
|
atlas.cxx atlas.hxx \
|
||||||
garmin.cxx garmin.hxx \
|
garmin.cxx garmin.hxx \
|
||||||
httpd.cxx httpd.hxx \
|
httpd.cxx httpd.hxx \
|
||||||
|
$(JPEG_SERVER) \
|
||||||
joyclient.cxx joyclient.hxx \
|
joyclient.cxx joyclient.hxx \
|
||||||
native.cxx native.hxx \
|
native.cxx native.hxx \
|
||||||
native_ctrls.cxx native_ctrls.hxx \
|
native_ctrls.cxx native_ctrls.hxx \
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org
|
// 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
|
// This program is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU General Public License as
|
// modify it under the terms of the GNU General Public License as
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
|
@ -28,16 +31,16 @@
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
|
||||||
#include <simgear/io/iochannel.hxx>
|
|
||||||
#include <simgear/math/sg_types.hxx>
|
|
||||||
#include <simgear/misc/props.hxx>
|
|
||||||
|
|
||||||
#include <stdlib.h> // atoi() atof()
|
#include <stdlib.h> // atoi() atof()
|
||||||
|
|
||||||
#include STL_STRING
|
#include STL_STRING
|
||||||
#include STL_STRSTREAM
|
#include STL_STRSTREAM
|
||||||
|
|
||||||
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
#include <simgear/io/iochannel.hxx>
|
||||||
|
#include <simgear/math/sg_types.hxx>
|
||||||
|
#include <simgear/misc/props.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
|
||||||
|
@ -58,7 +61,7 @@ bool FGHttpd::open() {
|
||||||
}
|
}
|
||||||
|
|
||||||
server = new HttpdServer( port );
|
server = new HttpdServer( port );
|
||||||
|
|
||||||
set_hz( 5 ); // default to processing requests @ 5Hz
|
set_hz( 5 ); // default to processing requests @ 5Hz
|
||||||
set_enabled( true );
|
set_enabled( true );
|
||||||
|
|
||||||
|
@ -82,6 +85,9 @@ bool FGHttpd::close() {
|
||||||
|
|
||||||
// Handle http GET requests
|
// Handle http GET requests
|
||||||
void HttpdChannel::foundTerminator (void) {
|
void HttpdChannel::foundTerminator (void) {
|
||||||
|
|
||||||
|
closeWhenDone ();
|
||||||
|
|
||||||
const string s = buffer.getData();
|
const string s = buffer.getData();
|
||||||
|
|
||||||
if ( s.find( "GET " ) == 0 ) {
|
if ( s.find( "GET " ) == 0 ) {
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org
|
// 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
|
// This program is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU General Public License as
|
// modify it under the terms of the GNU General Public License as
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
|
@ -71,11 +74,11 @@ class HttpdServer : private netChannel
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HttpdServer ( int port ) {
|
HttpdServer ( int port ) {
|
||||||
open () ;
|
open() ;
|
||||||
bind ("", port) ;
|
bind( "", port );
|
||||||
listen (5) ;
|
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;
|
int port;
|
||||||
HttpdServer *server;
|
HttpdServer *server;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline FGHttpd( int p ) { port = p; }
|
inline FGHttpd( int p ) { port = p; }
|
||||||
|
|
126
src/Network/jpg-httpd.cxx
Normal file
126
src/Network/jpg-httpd.cxx
Normal file
|
@ -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 <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
|
#include <stdlib.h> // atoi() atof()
|
||||||
|
|
||||||
|
#include STL_STRING
|
||||||
|
#include STL_STRSTREAM
|
||||||
|
|
||||||
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
#include <simgear/io/iochannel.hxx>
|
||||||
|
#include <simgear/math/sg_types.hxx>
|
||||||
|
#include <simgear/misc/props.hxx>
|
||||||
|
|
||||||
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/globals.hxx>
|
||||||
|
|
||||||
|
#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();
|
||||||
|
}
|
125
src/Network/jpg-httpd.hxx
Normal file
125
src/Network/jpg-httpd.hxx
Normal file
|
@ -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 <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <plib/netChat.h>
|
||||||
|
|
||||||
|
#ifdef FG_JPEG_SERVER
|
||||||
|
# include <simgear/screen/jpgfactory.hxx>
|
||||||
|
#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
|
Loading…
Add table
Reference in a new issue