Debian Codegraph @

src/Network/native.cxx

raw symbols SCIP
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 }