]> git.mxchange.org Git - flightgear.git/blob - src/FDM/ExternalNet/ExternalNet.hxx
make headers include headers they depend on, don't rely on the c(xx)
[flightgear.git] / src / FDM / ExternalNet / ExternalNet.hxx
1 // ExternalNet.hxx -- an net interface to an external flight dynamics model
2 //
3 // Written by Curtis Olson, started November 2001.
4 //
5 // Copyright (C) 2001  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifndef _EXTERNAL_NET_HXX
24 #define _EXTERNAL_NET_HXX
25
26 #include <plib/netBuffer.h>
27 #include <plib/netSocket.h>
28
29 #include <simgear/timing/timestamp.hxx> // fine grained timing measurements
30
31 #include <Network/net_ctrls.hxx>
32 #include <Network/net_fdm.hxx>
33 #include <FDM/flight.hxx>
34
35
36 class HTTPClient : public netBufferChannel
37 {
38
39     bool done;
40     SGTimeStamp start;
41
42 public:
43
44     HTTPClient ( const char* host, int port, const char* path ) :
45         done( false )
46     {
47         open ();
48         connect (host, port);
49
50         const char* s = netFormat ( "GET %s HTTP/1.0\r\n\r\n", path );
51         bufferSend( s, strlen(s) ) ;
52
53         start.stamp();
54     }
55
56     virtual void handleBufferRead (netBuffer& buffer)
57     {
58         const char* s = buffer.getData();
59         while (*s)
60             fputc(*s++,stdout);
61
62         printf("done\n");
63         buffer.remove();
64         printf("after buffer.remove()\n");
65         done = true;
66     }
67
68     bool isDone() const { return done; }
69     bool isDone( long usec ) const { 
70         SGTimeStamp now;
71         now.stamp();
72         if ( (now - start) > usec ) {
73             return true;
74         } else {
75             return done;
76         }
77     }
78 };
79
80
81 class FGExternalNet: public FGInterface {
82
83 private:
84
85     int data_in_port;
86     int data_out_port;
87     int cmd_port;
88     string fdm_host;
89
90     netSocket data_client;
91     netSocket data_server;
92
93     bool valid;
94
95     FGNetCtrls ctrls;
96     FGNetFDM fdm;
97
98 public:
99
100     // Constructor
101     FGExternalNet( double dt, string host, int dop, int dip, int cp );
102
103     // Destructor
104     ~FGExternalNet();
105
106     // Reset flight params to a specific position
107     void init();
108
109     // update the fdm
110     void update( double dt );
111
112 };
113
114
115 #endif // _EXTERNAL_NET_HXX