1 // native.cxx -- FGFS "Native" protocal class
3 // Written by Curtis Olson, started November 1999.
5 // Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
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.
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.
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.
24 #include <simgear/debug/logstream.hxx>
25 #include <simgear/io/iochannel.hxx>
30 FGNative::FGNative() {
33 FGNative::~FGNative() {
37 // open hailing frequencies
38 bool FGNative::open() {
40 FG_LOG( FG_IO, FG_ALERT, "This shouldn't happen, but the channel "
41 << "is already in use, ignoring" );
45 SGIOChannel *io = get_io_channel();
47 if ( ! io->open( get_direction() ) ) {
48 FG_LOG( FG_IO, FG_ALERT, "Error opening channel communication layer." );
58 // process work for this port
59 bool FGNative::process() {
60 SGIOChannel *io = get_io_channel();
61 int length = sizeof(*cur_fdm_state);
63 if ( get_direction() == SG_IO_OUT ) {
64 // cout << "size of cur_fdm_state = " << length << endl;
66 if ( ! io->write( (char *)(& buf), length ) ) {
67 FG_LOG( FG_IO, FG_ALERT, "Error writing data." );
70 } else if ( get_direction() == SG_IO_IN ) {
71 if ( io->get_type() == sgFileType ) {
72 if ( io->read( (char *)(& buf), length ) == length ) {
73 FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
77 while ( io->read( (char *)(& buf), length ) == length ) {
78 FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
89 bool FGNative::close() {
90 SGIOChannel *io = get_io_channel();
94 if ( ! io->close() ) {