/* 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
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 );
#include <Network/atlas.hxx>
#include <Network/garmin.hxx>
#include <Network/httpd.hxx>
+#ifdef FG_JPEG_SERVER
+# include <Network/jpg-httpd.hxx>
+#endif
#include <Network/joyclient.hxx>
#include <Network/native.hxx>
#include <Network/native_ctrls.hxx>
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;
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 ) {
<< "\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;
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 \
//
// 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
#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 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>
}
server = new HttpdServer( port );
-
+
set_hz( 5 ); // default to processing requests @ 5Hz
set_enabled( true );
// Handle http GET requests
void HttpdChannel::foundTerminator (void) {
+
+ closeWhenDone ();
+
const string s = buffer.getData();
if ( s.find( "GET " ) == 0 ) {
//
// 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
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 ) ;
}
};
int port;
HttpdServer *server;
-
+
public:
inline FGHttpd( int p ) { port = p; }
--- /dev/null
+// 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();
+}
--- /dev/null
+// 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