]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGfdmSocket.h
Merge branch 'luff/kln89'
[flightgear.git] / src / FDM / JSBSim / input_output / FGfdmSocket.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGfdmSocket.h
4  Author:       Jon S. Berndt
5  Date started: 11/08/99
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 11/08/99   JSB   Created
29 11/08/07   HDW   Added Generic Socket Send
30
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 SENTRY
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34
35 #ifndef FGfdmSocket_H
36 #define FGfdmSocket_H
37
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42 #include <string>
43 #include <sstream>
44 #include <sys/types.h>
45 #include "FGJSBBase.h"
46
47 #if defined(_MSC_VER) || defined(__MINGW32__)
48   #include <winsock.h>
49   #include <io.h>
50 #else
51   #include <unistd.h>
52   #include <sys/socket.h>
53   #include <netinet/in.h>
54   #include <netdb.h>
55   #include <errno.h>
56   #include <sys/ioctl.h>
57 #endif
58
59 #ifdef _MSC_VER
60 #  pragma comment (lib,"WSock32.lib")
61 #endif
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 DEFINITIONS
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 #define ID_FDMSOCKET "$Id$"
68
69 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 FORWARD DECLARATIONS
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72
73 namespace JSBSim {
74
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 CLASS DOCUMENTATION
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78
79 /** Encapsulates an object that enables JSBSim to communicate via socket (input
80     and/or output).
81     
82   */
83
84 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 CLASS DECLARATION
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
87
88 class FGfdmSocket : public FGJSBBase
89 {
90 public:
91   FGfdmSocket(const std::string&, int);
92   FGfdmSocket(const std::string&, int, int);
93   FGfdmSocket(int);
94   ~FGfdmSocket();
95   void Send(void);
96   void Send(const char *data, int length);
97
98   std::string Receive(void);
99   int Reply(const std::string& text);
100   void Append(const std::string& s) {Append(s.c_str());}
101   void Append(const char*);
102   void Append(double);
103   void Append(long);
104   void Clear(void);
105   void Clear(const std::string& s);
106   void Close(void);
107   bool GetConnectStatus(void) {return connected;}
108
109   enum {ptUDP, ptTCP};
110
111 private:
112   int sckt;
113   int sckt_in;
114   struct sockaddr_in scktName;
115   struct hostent *host;
116   std::ostringstream buffer;
117   bool connected;
118   void Debug(int from);
119 };
120 }
121 #endif