]> git.mxchange.org Git - flightgear.git/blob - src/Network/protocol.hxx
Create TimeManager subsystem, and collect the time related code out of main.cxx and...
[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 - 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
24 #ifndef _PROTOCOL_HXX
25 #define _PROTOCOL_HXX
26
27
28 #include <simgear/compiler.h>
29 #include <simgear/io/iochannel.hxx>
30
31 #include <string>
32 #include <vector>
33
34 using std::string;
35 using std::vector;
36
37
38 #define FG_MAX_MSG_SIZE 16384
39
40 class FGProtocol {
41
42 private:
43
44     double hz;
45     double count_down;
46     long count;
47
48     SGProtocolDir dir;
49
50     // string protocol_str;
51
52     // char buf[FG_MAX_MSG_SIZE];
53     // int length;
54
55     bool enabled;
56
57     SGIOChannel *io;
58
59 public:
60
61     FGProtocol();
62     virtual ~FGProtocol();
63
64     virtual bool open();
65     virtual bool process();
66     virtual bool close();
67
68     inline SGProtocolDir get_direction() const { return dir; }
69     void set_direction( const string& d );
70
71     inline double get_hz() const { return hz; }
72     inline void set_hz( double t ) { hz = t; }
73     inline double get_count_down() const { return count_down; }
74     inline void set_count_down( double c ) { count_down = c; }
75     inline void inc_count_down( double amt ) { count_down += amt; }
76     inline void dec_count_down( double amt ) { count_down -= amt; }
77     inline void inc_count() { count++; }
78     inline long get_count() { return count; }
79
80     virtual bool gen_message();
81     virtual bool parse_message();
82
83     // inline string get_protocol() const { return protocol_str; }
84     // inline void set_protocol( const string& str ) { protocol_str = str; }
85
86     // inline char *get_buf() { return buf; }
87     // inline int get_length() const { return length; }
88     // inline void set_length( int l ) { length = l; }
89
90     inline bool is_enabled() const { return enabled; }
91     inline void set_enabled( const bool b ) { enabled = b; }
92
93     inline SGIOChannel *get_io_channel() const { return io; }
94     inline void set_io_channel( SGIOChannel *c ) { io = c; }
95 };
96
97
98 typedef vector < FGProtocol * > io_container;
99 typedef io_container::iterator io_iterator;
100 typedef io_container::const_iterator const_io_iterator;
101
102 #include <stdexcept>
103 using std::invalid_argument;
104
105 //namespace flightgear { namespace network {
106 class FGProtocolConfigError : public invalid_argument
107 {
108 public:
109     FGProtocolConfigError( const string& what_string )
110         : invalid_argument(what_string) {}
111 };
112 //}} // end namespace flightgear::network
113
114
115 #endif // _PROTOCOL_HXX
116
117