]> git.mxchange.org Git - flightgear.git/commitdiff
Changes to support optional screen snap shot httpd server.
authorcurt <curt>
Wed, 16 Jan 2002 23:02:52 +0000 (23:02 +0000)
committercurt <curt>
Wed, 16 Jan 2002 23:02:52 +0000 (23:02 +0000)
acconfig.h
src/Cockpit/hud.hxx
src/Main/fg_io.cxx
src/Main/options.cxx
src/Network/Makefile.am
src/Network/httpd.cxx
src/Network/httpd.hxx
src/Network/jpg-httpd.cxx [new file with mode: 0644]
src/Network/jpg-httpd.hxx [new file with mode: 0644]

index cf7c32d078e96a80f1ecff7e2beee69b642a65e2..dc4d593f85ad49985f78582f75c20c61e13a15d0 100644 (file)
    
 /* 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
index a5ccd24bfa233bb265ece731c6b6897d1cd32ae1..f9243297417809eca59154f97d204f2da8d6f1f0 100644 (file)
@@ -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 );
index ba1ce3681c8f57f23144606bbc0c9b1e29bb4893..9bd5d460cb87c28da644564771c2121a13b11cf2 100644 (file)
@@ -40,6 +40,9 @@
 #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>
@@ -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;
index ff7660b1db8da71a3482560e2fe063bb655fdff1..d8b53bd13466f0d6d686c076e1bf443ba7faf89e 100644 (file)
@@ -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;
index 5c1596cefc1cc678240de66a7c586a91c361f156..2eb3ace49849db59de5a1e54be4d46f4ddac3f5a 100644 (file)
@@ -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 \
index 4a839252580d33d10a7076a5719a248020bcc536..ea67b700b67676c294ddfff2f38d1c37424c241d 100644 (file)
@@ -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
 
 #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>
 
@@ -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 ) {
index 56bdbedef7d1491b802ecda98374a09b8627fa57..27aeb9b9d17c4ed8b14b191e45caa341d969d6ec 100644 (file)
@@ -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 (file)
index 0000000..63afbff
--- /dev/null
@@ -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();
+}
diff --git a/src/Network/jpg-httpd.hxx b/src/Network/jpg-httpd.hxx
new file mode 100644 (file)
index 0000000..b51b6d3
--- /dev/null
@@ -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