]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGfdmSocket.h
Clean up header file use of iostream and "using" declarations
[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 (jsb@hal-pc.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
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGfdmSocket_H
35 #define FGfdmSocket_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <stdio.h>
42
43 #ifdef FGFS
44 #  include <simgear/compiler.h>
45 #  include STL_STRING
46 #else
47 #  include <string>
48 #endif
49
50 #include <sys/types.h>
51 #include "FGJSBBase.h"
52
53 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
54   #include <winsock.h>
55   #include <io.h>
56 #else
57   #include <unistd.h>
58   #include <sys/socket.h>
59   #include <netinet/in.h>
60   #include <netdb.h>
61   #include <errno.h>
62   #include <sys/ioctl.h>
63 #endif
64
65 #ifdef _MSC_VER
66
67 #pragma comment (lib,"WSock32.lib")
68
69 #endif
70
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 DEFINITIONS
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 #define ID_FDMSOCKET "$Id$"
76
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 FORWARD DECLARATIONS
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80
81 namespace JSBSim {
82
83 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 CLASS DOCUMENTATION
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86
87 /** Encapsulates an object that enables JSBSim to communicate via socket (input
88     and/or output).
89     
90   */
91
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 CLASS DECLARATION
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95
96 using std::string;
97 using std::cerr;
98
99 class FGfdmSocket : public FGJSBBase
100 {
101 public:
102   FGfdmSocket(string, int);
103   FGfdmSocket(int);
104   ~FGfdmSocket();
105   void Send(void);
106   string Receive(void);
107   int Reply(string text);
108   void Append(const string s) {Append(s.c_str());}
109   void Append(const char*);
110   void Append(double);
111   void Append(long);
112   void Clear(void);
113   void Clear(string s);
114   void Close(void);
115   bool GetConnectStatus(void) {return connected;}
116
117 private:
118   int sckt;
119   int sckt_in;
120   int size;
121   struct sockaddr_in scktName;
122   struct hostent *host;
123   string buffer;
124   bool connected;
125   void Debug(int from);
126 };
127 }
128 #endif