]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/props.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / Network / props.cxx
index 8752da41b927eb48ec5d9c2cd96ec6813d22443f..51b293177a83f5fafa938f6081715f28e208a1f6 100644 (file)
 
 #include <simgear/compiler.h>
 #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/commands.hxx>
 #include <simgear/misc/strutils.hxx>
-#include <simgear/misc/props.hxx>
-#include <simgear/misc/props_io.hxx>
+#include <simgear/props/props.hxx>
+#include <simgear/props/props_io.hxx>
 
 #include STL_STRSTREAM
 
@@ -203,15 +204,7 @@ PropsChannel::foundTerminator()
            for (int i = 0; i < dir->nChildren(); i++)
            {
                SGPropertyNode * child = dir->getChild(i);
-               string name = child->getName();
-               string line = name;
-
-               if (dir->getChild( name.c_str(), 1 ))
-               {
-                   char buf[16];
-                   sprintf(buf, "[%d]", child->getIndex());
-                   line += buf;
-               }
+               string line = child->getDisplayName(true);
 
                if ( child->nChildren() > 0 )
                {
@@ -221,10 +214,9 @@ PropsChannel::foundTerminator()
                {
                    if (mode == PROMPT)
                    {
-                       string value = dir->getStringValue( name.c_str(), "" );
+                       string value = child->getStringValue();
                        line += " =\t'" + value + "'\t(";
-                       line += getValueTypeString(
-                                       dir->getNode( name.c_str() ) );
+                       line += getValueTypeString( child );
                        line += ")";
                    }
                }
@@ -319,21 +311,53 @@ PropsChannel::foundTerminator()
        }
        else if ( command == "set" )
        {
-           if ( tokens.size() == 3 )
-           {
-               node->getNode( tokens[1].c_str(), true )->setStringValue(tokens[2].c_str());
+           if ( tokens.size() >= 2 )
+            {
+                string value, tmp;
+                if ( tokens.size() == 3 ) {
+                    value = tokens[2];
+                } else {
+                    value = "";
+                }
+                node->getNode( tokens[1].c_str(), true )
+                    ->setStringValue(value.c_str());
 
                if ( mode == PROMPT )
                {
                    // now fetch and write out the new value as confirmation
                    // of the change
-                   string value = node->getStringValue ( tokens[1].c_str(), "" );
-                   string tmp = tokens[1] + " = '" + value + "' (";
+                   value = node->getStringValue ( tokens[1].c_str(), "" );
+                   tmp = tokens[1] + " = '" + value + "' (";
                    tmp += getValueTypeString( node->getNode( tokens[1].c_str() ) );
                    tmp += ")";
                    push( tmp.c_str() );
                    push( getTerminator() );
                }
+           } 
+       }
+       else if ( command == "run" )
+       {
+           if ( tokens.size() == 2 )
+           {
+               string tmp;     
+                SGPropertyNode args;
+                if ( !globals->get_commands()
+                         ->execute(tokens[1].c_str(), &args) )
+                {
+                    SG_LOG( SG_GENERAL, SG_ALERT,
+                            "Command " << tokens[1] << " failed.");
+                    if ( mode == PROMPT ) {
+                        tmp += "*failed*";
+                        push( tmp.c_str() );
+                        push( getTerminator() );
+                    }
+                } else {
+                    if ( mode == PROMPT ) {
+                        tmp += "<completed>";
+                        push( tmp.c_str() );
+                        push( getTerminator() );
+                    }
+                }
            }
        }
        else if (command == "quit")
@@ -364,6 +388,7 @@ ls [<dir>]         list directory\r\n\
 prompt             switch to interactive mode (default)\r\n\
 pwd                display your current path\r\n\
 quit               terminate connection\r\n\
+run <command>      run built in command\r\n\
 set <var> <val>    set <var> to a new <val>\r\n\
 show <var>         synonym for get\r\n";
            push( msg );
@@ -393,12 +418,25 @@ FGProps::FGProps( const vector<string>& tokens )
     // tokens:
     //   props,port#
     //   props,medium,direction,hz,hostname,port#,style
-    if (tokens.size() == 2)
+    if (tokens.size() == 2) {
        port = atoi( tokens[1].c_str() );
-    else if (tokens.size() == 7)
+        set_hz( 5 );                // default to processing requests @ 5Hz
+    } else if (tokens.size() == 7) {
+        char* endptr;
+        errno = 0;
+        int hz = strtol( tokens[3].c_str(), &endptr, 10 );
+        if (errno != 0) {
+           SG_LOG( SG_IO, SG_ALERT, "I/O poll frequency out of range" );
+           set_hz( 5 );           // default to processing requests @ 5Hz
+        } else {
+            SG_LOG( SG_IO, SG_INFO, "Setting I/O poll frequency to "
+                    << hz << " Hz");
+            set_hz( hz );
+        }
        port = atoi( tokens[5].c_str() );
-    else
+    } else {
        throw FGProtocolConfigError( "FGProps: incorrect number of configuration arguments" );
+    }
 }
 
 /**
@@ -426,7 +464,6 @@ FGProps::open()
     netChannel::listen( 5 );
     SG_LOG( SG_IO, SG_INFO, "Props server started on port " << port );
 
-    set_hz( 5 );                // default to processing requests @ 5Hz
     set_enabled( true );
     return true;
 }