Debian Codegraph @

src/FDM/JSBSim/input_output/FGfdmSocket.h

raw symbols SCIP
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 ([email protected]) -------------
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
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later 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
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on 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 "FGJSBBase.h"
43
44 #if defined(_MSC_VER) || defined(__MINGW32__)
45 #include <winsock.h>
46 #include <io.h>
47 #else
48 #include <netdb.h>
49 #endif
50
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FORWARD DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55 namespace JSBSim {
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS DOCUMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 /** Encapsulates an object that enables JSBSim to communicate via socket (input
62 and/or output).
63
64 */
65
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS DECLARATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69
70 class FGfdmSocket : public FGJSBBase
71 {
72 public:
73 FGfdmSocket(const std::string& address, int port, int protocol, int precision = 7);
74 FGfdmSocket(int port, int protocol, int precision = 7);
75 ~FGfdmSocket();
76 void Send(void);
77 void Send(const char *data, int length);
78
79 std::string Receive(void);
80 int Reply(const std::string& text);
81 void Append(const std::string& s) {Append(s.c_str());}
82 void Append(const char*);
83 void Append(double);
84 void Append(long);
85 void Clear(void);
86 void Clear(const std::string& s);
87 void Close(void);
88 bool GetConnectStatus(void) {return connected;}
89 void WaitUntilReadable(void);
90
91 enum ProtocolType {ptUDP, ptTCP};
92
93 private:
94 #if defined(_MSC_VER) || defined(__MINGW32__)
95 SOCKET sckt;
96 SOCKET sckt_in;
97 #else
98 int sckt;
99 int sckt_in;
100 #endif
101 ProtocolType Protocol;
102 struct sockaddr_in scktName;
103 struct hostent *host;
104 std::ostringstream buffer;
105 int precision;
106 bool connected;
107 void Debug(int from);
108 };
109 }
110 #endif