]> git.mxchange.org Git - flightgear.git/blob - src/Network/jpg-httpd.hxx
Update to the Mini FDM network protocal (mostly renaming class and file names)
[flightgear.git] / src / Network / jpg-httpd.hxx
1 // httpd.hxx -- FGFS http property manager interface / external script
2 //              and control class
3 //
4 // Written by Curtis Olson, started June 2001.
5 //
6 // Copyright (C) 2001  Curtis L. Olson - curt@flightgear.org
7 //
8 // Jpeg Image Support added August 2001
9 //  by Norman Vine - nhv@cape.com
10 //
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.
15 //
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.
20 //
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., 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // $Id$
26
27
28 #ifndef _FG_JPEG_HTTPD_HXX
29 #define _FG_JPEG_HTTPD_HXX
30
31 #ifdef HAVE_CONFIG_H
32 #  include <config.h>
33 #endif
34
35 #include <plib/netChat.h>
36
37 #ifdef FG_JPEG_SERVER
38 #  include <simgear/screen/jpgfactory.hxx>
39 #else
40 // dummy it in to keep the compiler happy
41 class trJpgFactory {
42 public:
43     trJpgFactory();
44     void init(int, int);
45     void destroy();
46     int render();
47   void *data();
48 };
49 #endif
50
51 #include "protocol.hxx"
52
53 class trJpgFactory;
54
55
56 /* simple httpd server that makes an hasty stab at following the http
57    1.1 rfc.  */
58
59 class HttpdImageChannel : public netChat
60 {
61
62     netBuffer buffer ;
63     trJpgFactory *JpgFactory;
64     
65 public:
66
67     HttpdImageChannel() : buffer(512) {
68         setTerminator("\r\n");
69         JpgFactory = new trJpgFactory();
70
71         // This is a terrible hack but it can't be initialized until
72         // after OpenGL is up an running
73         JpgFactory->init(400,300);
74     }
75
76     ~HttpdImageChannel() {
77         JpgFactory->destroy();
78         delete JpgFactory;
79     }
80
81     virtual void collectIncomingData (const char* s, int n) {
82         buffer.append(s,n);
83     }
84
85     // Handle the actual http request
86     virtual void foundTerminator (void);
87 };
88
89
90 class HttpdImageServer : private netChannel
91 {
92     virtual bool writable (void) { return false ; }
93
94     virtual void handleAccept (void) {
95         netAddress addr ;
96         int handle = accept ( &addr ) ;
97         printf("Client %s:%d connected\n", addr.getHost(), addr.getPort());
98
99         HttpdImageChannel *hc = new HttpdImageChannel;
100         hc->setHandle ( handle ) ;
101     }
102
103 public:
104
105     HttpdImageServer ( int port ) {
106         open ();
107         bind( "", port );
108         listen( 5 );
109
110         printf( "HttpdImage server started on port %d\n", port ) ;
111     }
112         
113 };
114
115
116 class FGJpegHttpd : public FGProtocol {
117
118     int port;
119     HttpdImageServer *imageServer;
120     
121 public:
122
123     inline FGJpegHttpd( int p ) { port = p; }
124
125     inline ~FGJpegHttpd() { }
126
127     bool open();
128
129     bool process();
130
131     bool close();
132 };
133
134
135 #endif // _FG_JPEG_HTTPD_HXX