]> git.mxchange.org Git - flightgear.git/blob - src/Network/props.cxx
aaa4d159c984a38e180bbb2a38feeb289c95ec89
[flightgear.git] / src / Network / props.cxx
1 // props.hxx -- FGFS property manager interaction class
2 //
3 // Written by Curtis Olson, started September 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #include <simgear/compiler.h>
25 #include <simgear/debug/logstream.hxx>
26 #include <simgear/io/iochannel.hxx>
27 #include <simgear/math/sg_types.hxx>
28
29 #include <strstream.h>
30
31 #include "props.hxx"
32
33
34 FGProps::FGProps() {
35 }
36
37 FGProps::~FGProps() {
38 }
39
40
41 // open hailing frequencies
42 bool FGProps::open() {
43     if ( is_enabled() ) {
44         FG_LOG( FG_IO, FG_ALERT, "This shouldn't happen, but the channel " 
45                 << "is already in use, ignoring" );
46         return false;
47     }
48
49     SGIOChannel *io = get_io_channel();
50
51     if ( ! io->open( get_direction() ) ) {
52         FG_LOG( FG_IO, FG_ALERT, "Error opening channel communication layer." );
53         return false;
54     }
55
56     set_enabled( true );
57
58     return true;
59 }
60
61
62 bool FGProps::process_command( const char *cmd ) {
63     string_list tokens;
64     tokens.clear();
65
66     istrstream in(cmd);
67     
68     while ( !in.eof() ) {
69         string token;
70         in >> token;
71         tokens.push_back( token );
72     }
73
74     string command = tokens[0];
75
76     if ( command == "ls" ) {
77         
78     }
79 }
80
81
82 // process work for this port
83 bool FGProps::process() {
84     SGIOChannel *io = get_io_channel();
85
86     if ( get_direction() == SG_IO_BI ) {
87         while ( io->read( buf, max_cmd_len ) > 0 ) {
88             FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
89             process_command( buf );
90         }
91     }
92
93     return true;
94 }
95
96
97 // close the channel
98 bool FGProps::close() {
99     SGIOChannel *io = get_io_channel();
100
101     set_enabled( false );
102
103     if ( ! io->close() ) {
104         return false;
105     }
106
107     return true;
108 }