]> git.mxchange.org Git - flightgear.git/blob - src/Network/protocol.hxx
UIUC flight model contribution. This is based on LaRCsim, but can read
[flightgear.git] / src / Network / protocol.hxx
1 // protocol.hxx -- High level protocal class
2 //
3 // Written by Curtis Olson, started November 1999.
4 //
5 // Copyright (C) 1999  Curtis L. Olson - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _PROTOCOL_HXX
25 #define _PROTOCOL_HXX
26
27
28 #include <simgear/compiler.h>
29
30 #include STL_STRING
31 #include <vector>
32
33 FG_USING_STD(string);
34 FG_USING_STD(vector);
35
36
37 #define FG_MAX_MSG_SIZE 16384
38
39 // forward declaration
40 class FGIOChannel;
41
42
43 class FGProtocol {
44
45 public:
46
47     enum fgProtocolDir {
48         none = 0,
49         in = 1,
50         out = 2,
51         bi = 3
52     };
53
54 private:
55
56     double hz;
57     int count_down;
58
59     fgProtocolDir dir;
60
61     // string protocol_str;
62
63     // char buf[FG_MAX_MSG_SIZE];
64     // int length;
65
66     bool enabled;
67
68     FGIOChannel *io;
69
70 public:
71
72     FGProtocol();
73     virtual ~FGProtocol();
74
75     virtual bool open();
76     virtual bool process();
77     virtual bool close();
78
79     inline fgProtocolDir get_direction() const { return dir; }
80     inline void set_direction( const string& d ) {
81         if ( d == "in" ) {
82             dir = in;
83         } else if ( d == "out" ) {
84             dir = out;
85         } else if ( d == "bi" ) {
86             dir = bi;
87         } else {
88             dir = none;
89         }
90     }
91
92     inline double get_hz() const { return hz; }
93     inline void set_hz( double t ) { hz = t; }
94     inline int get_count_down() const { return count_down; }
95     inline void set_count_down( int c ) { count_down = c; }
96     inline void dec_count_down( int c ) { count_down -= c; }
97
98     virtual bool gen_message();
99     virtual bool parse_message();
100
101     // inline string get_protocol() const { return protocol_str; }
102     // inline void set_protocol( const string& str ) { protocol_str = str; }
103
104     // inline char *get_buf() { return buf; }
105     // inline int get_length() const { return length; }
106     // inline void set_length( int l ) { length = l; }
107
108     inline bool is_enabled() const { return enabled; }
109     inline void set_enabled( const bool b ) { enabled = b; }
110
111     inline FGIOChannel *get_io_channel() const { return io; }
112     inline void set_io_channel( FGIOChannel *c ) { io = c; }
113 };
114
115
116 typedef vector < FGProtocol * > io_container;
117 typedef io_container::iterator io_iterator;
118 typedef io_container::const_iterator const_io_iterator;
119
120
121 #endif // _PROTOCOL_HXX
122
123