]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/protocol.cxx
Erik Hofman:
[flightgear.git] / src / Network / protocol.cxx
index 2954f04b659e3691e0d93c0e67cf83f00d582ff9..be4883ecfd09db29b692ed75f6d37c8abf17eaf2 100644 (file)
@@ -21,7 +21,8 @@
 // $Id$
 
 
-#include <Debug/logstream.hxx>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/io/iochannel.hxx>
 
 #include "protocol.hxx"
 
@@ -38,39 +39,70 @@ FGProtocol::~FGProtocol() {
 }
 
 
-// dummy open routine
+// standard I/O channel open routine
 bool FGProtocol::open() {
-    FG_LOG( FG_IO, FG_INFO, "dummy FGProtocol::open()" );
-    enabled = false;
-    return false;
+    if ( is_enabled() ) {
+       SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel " 
+               << "is already in use, ignoring" );
+       return false;
+    }
+
+    SGIOChannel *io = get_io_channel();
+
+    if ( ! io->open( get_direction() ) ) {
+       SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." );
+       return false;
+    }
+
+    set_enabled( true );
+
+    return true;
 }
 
 
 // dummy process routine
 bool FGProtocol::process() {
-    FG_LOG( FG_IO, FG_INFO, "dummy FGProtocol::process()" );
+    SG_LOG( SG_IO, SG_INFO, "dummy FGProtocol::process()" );
     return false;
 }
 
 
 // dummy close routine
 bool FGProtocol::close() {
-    FG_LOG( FG_IO, FG_INFO, "dummy FGProtocol::close()" );
+    SG_LOG( SG_IO, SG_INFO, "dummy FGProtocol::close()" );
     return false;
 }
 
 
-// dummy close routine
+// standard I/O channel close routine
 bool FGProtocol::gen_message() {
-    FG_LOG( FG_IO, FG_INFO, "dummy FGProtocol::gen_message()" );
-    return false;
+    SGIOChannel *io = get_io_channel();
+
+    set_enabled( false );
+
+    if ( ! io->close() ) {
+       return false;
+    }
+
+    return true;
 }
 
 
 // dummy close routine
 bool FGProtocol::parse_message() {
-    FG_LOG( FG_IO, FG_INFO, "dummy FGProtocol::close()" );
+    SG_LOG( SG_IO, SG_INFO, "dummy FGProtocol::close()" );
     return false;
 }
 
 
+void FGProtocol::set_direction( const string& d ) {
+    if ( d == "in" ) {
+       dir = SG_IO_IN;
+    } else if ( d == "out" ) {
+       dir = SG_IO_OUT;
+    } else if ( d == "bi" ) {
+       dir = SG_IO_BI;
+    } else {
+       dir = SG_IO_NONE;
+    }
+}