FlightGear next
protocol.hxx
Go to the documentation of this file.
1// protocol.hxx -- High level protocol 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#pragma once
25
26#include <simgear/compiler.h>
27#include <simgear/io/iochannel.hxx>
28
29#include <string>
30#include <vector>
31
32
33#define FG_MAX_MSG_SIZE 16384
34
36
37private:
38
39 double hz;
40 double count_down;
41 unsigned long count;
42
43 SGProtocolDir dir;
44
45 // std::string protocol_str;
46
47 // char buf[FG_MAX_MSG_SIZE];
48 // int length;
49
50 bool enabled;
51
52 SGIOChannel *io;
53 std::string m_name;
54
55public:
56
57 FGProtocol();
58 virtual ~FGProtocol();
59
60 virtual bool open();
61 virtual bool process();
62 virtual bool close();
63 virtual void reinit();
64
65 inline SGProtocolDir get_direction() const { return dir; }
66 void set_direction( const std::string& d );
67
68 inline double get_hz() const { return hz; }
69 inline void set_hz( double t ) { hz = t; }
70 inline double get_count_down() const { return count_down; }
71 inline void set_count_down( double c ) { count_down = c; }
72 inline void inc_count_down( double amt ) { count_down += amt; }
73 inline void dec_count_down( double amt ) { count_down -= amt; }
74 inline void inc_count() { count++; }
75 inline unsigned long get_count() { return count; }
76
77 virtual bool gen_message();
78 virtual bool parse_message();
79
80 // inline std::string get_protocol() const { return protocol_str; }
81 // inline void set_protocol( const std::string& str ) { protocol_str = str; }
82
83 // inline char *get_buf() { return buf; }
84 // inline int get_length() const { return length; }
85 // inline void set_length( int l ) { length = l; }
86
87 inline bool is_enabled() const { return enabled; }
88 inline void set_enabled( const bool b ) { enabled = b; }
89
90 inline SGIOChannel *get_io_channel() const { return io; }
91 inline void set_io_channel( SGIOChannel *c ) { io = c; }
92
93 // allow storing an identifying name on the Protocol instance
94 void set_name(const std::string& n);
95 std::string get_name() const { return m_name; }
96};
97
98
99typedef std::vector < FGProtocol * > io_container;
100typedef io_container::iterator io_iterator;
101typedef io_container::const_iterator const_io_iterator;
102
103#include <stdexcept>
104
105//namespace flightgear { namespace network {
106class FGProtocolConfigError : public std::invalid_argument
107{
108public:
109 FGProtocolConfigError( const std::string& what_string )
110 : std::invalid_argument(what_string) {}
111};
112//}} // end namespace flightgear::network
FGProtocolConfigError(const std::string &what_string)
Definition protocol.hxx:109
void dec_count_down(double amt)
Definition protocol.hxx:73
double get_hz() const
Definition protocol.hxx:68
virtual bool process()
Definition protocol.cxx:72
void set_io_channel(SGIOChannel *c)
Definition protocol.hxx:91
SGProtocolDir get_direction() const
Definition protocol.hxx:65
unsigned long get_count()
Definition protocol.hxx:75
virtual ~FGProtocol()
Definition protocol.cxx:41
double get_count_down() const
Definition protocol.hxx:70
SGIOChannel * get_io_channel() const
Definition protocol.hxx:90
std::string get_name() const
Definition protocol.hxx:95
void inc_count()
Definition protocol.hxx:74
void set_hz(double t)
Definition protocol.hxx:69
void inc_count_down(double amt)
Definition protocol.hxx:72
void set_count_down(double c)
Definition protocol.hxx:71
void set_name(const std::string &n)
Definition protocol.cxx:45
virtual void reinit()
Definition protocol.cxx:85
virtual bool open()
Definition protocol.cxx:51
virtual bool gen_message()
Definition protocol.cxx:91
virtual bool close()
Definition protocol.cxx:79
void set_enabled(const bool b)
Definition protocol.hxx:88
void set_direction(const std::string &d)
Definition protocol.cxx:111
virtual bool parse_message()
Definition protocol.cxx:105
bool is_enabled() const
Definition protocol.hxx:87
io_container::const_iterator const_io_iterator
Definition protocol.hxx:101
io_container::iterator io_iterator
Definition protocol.hxx:100
std::vector< FGProtocol * > io_container
Definition protocol.hxx:99