2,733
edits
Red Leader (talk | contribs) (Trim leading space to fix syntaxhighlight) |
Red Leader (talk | contribs) (→Patch prototype: Fix diff indent) |
||
Line 66: | Line 66: | ||
@@ -55,7 +62,7 @@ using std::endl; | @@ -55,7 +62,7 @@ using std::endl; | ||
* Props connection class. | * Props connection class. | ||
* This class represents a connection to props client. | * This class represents a connection to props client. | ||
*/ | */ | ||
-class PropsChannel : public simgear::NetChat | -class PropsChannel : public simgear::NetChat | ||
+class PropsChannel : public simgear::NetChat, public SGPropertyChangeListener | +class PropsChannel : public simgear::NetChat, public SGPropertyChangeListener | ||
{ | { | ||
simgear::NetBuffer buffer; | simgear::NetBuffer buffer; | ||
@@ -75,6 +82,7 @@ public: | @@ -75,6 +82,7 @@ public: | ||
* Constructor. | * Constructor. | ||
*/ | */ | ||
PropsChannel(); | PropsChannel(); | ||
+ ~PropsChannel(); | + ~PropsChannel(); | ||
/** | /** | ||
* Append incoming data to our request buffer. | * Append incoming data to our request buffer. | ||
@@ -89,10 +97,38 @@ public: | @@ -89,10 +97,38 @@ public: | ||
*/ | */ | ||
void foundTerminator(); | void foundTerminator(); | ||
+ // callback for registered listeners (subscriptions) | + // callback for registered listeners (subscriptions) | ||
Line 93: | Line 93: | ||
+ | + | ||
+ | + | ||
inline void node_not_found_error( const string& s ) const { | inline void node_not_found_error( const string& s ) const { | ||
throw "node '" + s + "' not found"; | throw "node '" + s + "' not found"; | ||
} | } | ||
+ | + | ||
+ void error(std::string msg) { // wrapper: prints errors to STDERR and to the telnet client | + void error(std::string msg) { // wrapper: prints errors to STDERR and to the telnet client | ||
Line 122: | Line 122: | ||
/** | /** | ||
@@ -104,6 +140,67 @@ PropsChannel::PropsChannel() | @@ -104,6 +140,67 @@ PropsChannel::PropsChannel() | ||
mode(PROMPT) | mode(PROMPT) | ||
{ | { | ||
setTerminator( "\r\n" ); | setTerminator( "\r\n" ); | ||
+ callback_map["subscribe"] = &PropsChannel::subscribe; | + callback_map["subscribe"] = &PropsChannel::subscribe; | ||
+ callback_map["unsubscribe"] = &PropsChannel::unsubscribe; | + callback_map["unsubscribe"] = &PropsChannel::unsubscribe; | ||
Line 190: | Line 190: | ||
/** | /** | ||
@@ -160,7 +257,7 @@ PropsChannel::foundTerminator() | @@ -160,7 +257,7 @@ PropsChannel::foundTerminator() | ||
const char* cmd = buffer.getData(); | const char* cmd = buffer.getData(); | ||
SG_LOG( SG_IO, SG_INFO, "processing command = \"" << cmd << "\"" ); | SG_LOG( SG_IO, SG_INFO, "processing command = \"" << cmd << "\"" ); | ||
- vector<string> tokens = simgear::strutils::split( cmd ); | - vector<string> tokens = simgear::strutils::split( cmd ); | ||
+ ParameterList tokens = simgear::strutils::split( cmd ); | + ParameterList tokens = simgear::strutils::split( cmd ); | ||
SGPropertyNode* node = globals->get_props()->getNode( path.c_str() ); | SGPropertyNode* node = globals->get_props()->getNode( path.c_str() ); | ||
@@ -292,7 +389,7 @@ PropsChannel::foundTerminator() | @@ -292,7 +389,7 @@ PropsChannel::foundTerminator() | ||
if ( !globals->get_commands() | if ( !globals->get_commands() | ||
->execute( "reinit", &args) ) | ->execute( "reinit", &args) ) | ||
{ | { | ||
- SG_LOG( SG_NETWORK, SG_ALERT, | - SG_LOG( SG_NETWORK, SG_ALERT, | ||
+ SG_LOG( SG_GENERAL, SG_ALERT, | + SG_LOG( SG_GENERAL, SG_ALERT, | ||
"Command " << tokens[1] << " failed."); | "Command " << tokens[1] << " failed."); | ||
if ( mode == PROMPT ) { | if ( mode == PROMPT ) { | ||
tmp += "*failed*"; | tmp += "*failed*"; | ||
@@ -357,7 +454,7 @@ PropsChannel::foundTerminator() | @@ -357,7 +454,7 @@ PropsChannel::foundTerminator() | ||
if ( !globals->get_commands() | if ( !globals->get_commands() | ||
->execute(tokens[1].c_str(), &args) ) | ->execute(tokens[1].c_str(), &args) ) | ||
{ | { | ||
- SG_LOG( SG_NETWORK, SG_ALERT, | - SG_LOG( SG_NETWORK, SG_ALERT, | ||
+ SG_LOG( SG_GENERAL, SG_ALERT, | + SG_LOG( SG_GENERAL, SG_ALERT, | ||
"Command " << tokens[1] << " failed."); | "Command " << tokens[1] << " failed."); | ||
if ( mode == PROMPT ) { | if ( mode == PROMPT ) { | ||
tmp += "*failed*"; | tmp += "*failed*"; | ||
@@ -386,7 +483,14 @@ PropsChannel::foundTerminator() | @@ -386,7 +483,14 @@ PropsChannel::foundTerminator() | ||
mode = DATA; | mode = DATA; | ||
} else if ( command == "prompt" ) { | } else if ( command == "prompt" ) { | ||
mode = PROMPT; | mode = PROMPT; | ||
- } else { | - } else { | ||
+ } else if (command == "subscribe" || command == "unsubscribe") { | + } else if (command == "subscribe" || command == "unsubscribe") { | ||
Line 229: | Line 229: | ||
+ } | + } | ||
+ else { | + else { | ||
const char* msg = "\ | const char* msg = "\ | ||
Valid commands are:\r\n\ | Valid commands are:\r\n\ | ||
\r\n\ | \r\n\ | ||
Line 240: | Line 240: | ||
+subscribe <var> subscribe to property changes (returns hash code for property)\r\n\ | +subscribe <var> subscribe to property changes (returns hash code for property)\r\n\ | ||
+unscubscribe <id> unscubscribe from property changes (id must be the property hash as returned from subscribe command)\r\n"; | +unscubscribe <id> unscubscribe from property changes (id must be the property hash as returned from subscribe command)\r\n"; | ||
push( msg ); | push( msg ); | ||
} | } | ||
} | } | ||
diff --git a/src/Network/props.hxx b/src/Network/props.hxx | diff --git a/src/Network/props.hxx b/src/Network/props.hxx | ||
index e55f7c1..09b5a09 100644 | index e55f7c1..09b5a09 100644 | ||
Line 248: | Line 248: | ||
+++ b/src/Network/props.hxx | +++ b/src/Network/props.hxx | ||
@@ -40,7 +40,8 @@ | @@ -40,7 +40,8 @@ | ||
* FlightGear properties. | * FlightGear properties. | ||
*/ | */ | ||
class FGProps : public FGProtocol, | class FGProps : public FGProtocol, | ||
- public simgear::NetChannel | - public simgear::NetChannel |