]> git.mxchange.org Git - flightgear.git/blob - src/FDM/ExternalNet/ExternalNet.hxx
Merge branch 'maint' into next
[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         if ( start + SGTimeStamp::fromUSec(usec) < SGTimeStamp::now() ) {
71             return true;
72         } else {
73             return done;
74         }
75     }
76 };
77
78
79 class FGExternalNet: public FGInterface {
80
81 private:
82
83     int data_in_port;
84     int data_out_port;
85     int cmd_port;
86     string fdm_host;
87
88     netSocket data_client;
89     netSocket data_server;
90
91     bool valid;
92
93     FGNetCtrls ctrls;
94     FGNetFDM fdm;
95
96 public:
97
98     // Constructor
99     FGExternalNet( double dt, string host, int dop, int dip, int cp );
100
101     // Destructor
102     ~FGExternalNet();
103
104     // Reset flight params to a specific position
105     void init();
106
107     // update the fdm
108     void update( double dt );
109
110 };
111
112
113 #endif // _EXTERNAL_NET_HXX