FlightGear
next
native.cxx
Go to the documentation of this file.
1
// native.cxx -- FGFS "Native" 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
#ifdef HAVE_CONFIG_H
24
# include <config.h>
25
#endif
26
27
#include <simgear/debug/logstream.hxx>
28
29
30
#include "
native.hxx
"
31
32
#include <
Main/globals.hxx
>
33
#include <
FDM/fdm_shell.hxx
>
34
#include <
FDM/flight.hxx
>
35
36
FGNative::FGNative
() {
37
}
38
39
FGNative::~FGNative
() {
40
}
41
42
43
// open hailing frequencies
44
bool
FGNative::open
() {
45
if
(
is_enabled
() ) {
46
SG_LOG( SG_IO, SG_ALERT,
"This shouldn't happen, but the channel "
47
<<
"is already in use, ignoring"
);
48
return
false
;
49
}
50
51
SGIOChannel *io =
get_io_channel
();
52
53
if
( ! io->open(
get_direction
() ) ) {
54
SG_LOG( SG_IO, SG_ALERT,
"Error opening channel communication layer."
);
55
return
false
;
56
}
57
58
set_enabled
(
true
);
59
60
return
true
;
61
}
62
63
// process work for this port
64
bool
FGNative::process
()
65
{
66
auto
fdm =
globals
->get_subsystem<
FDMShell
>();
67
FGInterface
* fdmState = fdm->getInterface();
68
if
(!fdmState) {
69
return
false
;
70
}
71
72
SGIOChannel *io =
get_io_channel
();
73
if
(
get_direction
() == SG_IO_OUT ) {
74
return
fdmState->writeState(io);
75
}
else
{
76
return
fdmState->readState(io);
77
}
78
}
79
80
81
// close the channel
82
bool
FGNative::close
() {
83
SGIOChannel *io =
get_io_channel
();
84
85
set_enabled
(
false
);
86
87
if
( ! io->close() ) {
88
return
false
;
89
}
90
91
return
true
;
92
}
FDMShell
Wrap an FDM implementation in a subsystem with standard semantics Notably, deal with the various case...
Definition
fdm_shell.hxx:44
FGInterface
Definition
flight.hxx:134
FGNative::FGNative
FGNative()
Definition
native.cxx:36
FGNative::close
bool close()
Definition
native.cxx:82
FGNative::open
bool open()
Definition
native.cxx:44
FGNative::process
bool process()
Definition
native.cxx:64
FGNative::~FGNative
~FGNative()
Definition
native.cxx:39
FGProtocol::get_direction
SGProtocolDir get_direction() const
Definition
protocol.hxx:65
FGProtocol::get_io_channel
SGIOChannel * get_io_channel() const
Definition
protocol.hxx:90
FGProtocol::set_enabled
void set_enabled(const bool b)
Definition
protocol.hxx:88
FGProtocol::is_enabled
bool is_enabled() const
Definition
protocol.hxx:87
fdm_shell.hxx
flight.hxx
globals
FGGlobals * globals
Definition
globals.cxx:142
globals.hxx
native.hxx
src
Network
native.cxx
Generated on Tue Jun 3 2025 12:58:41 for FlightGear by
1.13.2