]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/commands.cxx
Fix some compiler warnings. size_t/int/unsigned conversions and extra ';'
[simgear.git] / simgear / structure / commands.cxx
index b2391e3ba7f1cff7986f8eacf5364e985739ee56..266cdb4ce3b0177b269e102295647a32515b262e 100644 (file)
 #include <memory>
 #include <simgear/props/props_io.hxx>
 
-#include <OpenThreads/Mutex>
-#include <OpenThreads/ScopedLock>
-
 #include "commands.hxx"
 
-#include <simgear/math/SGMath.hxx>
-
+#include <simgear/structure/exception.hxx>
+#include <simgear/threads/SGThread.hxx>
+#include <simgear/threads/SGGuard.hxx>
+#include <simgear/debug/logstream.hxx>
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -35,7 +34,7 @@ SGCommandMgr::~SGCommandMgr ()
   // no-op
 }
 
-OpenThreads::Mutex SGCommandMgr::_instanceMutex;
+SGMutex SGCommandMgr::_instanceMutex;
 
 SGCommandMgr*
 SGCommandMgr::instance()
@@ -44,7 +43,7 @@ SGCommandMgr::instance()
   if (mgr.get())
     return mgr.get();
 
-  OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
+  SGGuard<SGMutex> lock(_instanceMutex);
   if (mgr.get())
     return mgr.get();
 
@@ -53,39 +52,46 @@ SGCommandMgr::instance()
 }
 
 void
-SGCommandMgr::addCommand (const string &name, command_t command)
+SGCommandMgr::addCommand (const std::string &name, command_t command)
 {
   _commands[name] = command;
 }
 
 SGCommandMgr::command_t
-SGCommandMgr::getCommand (const string &name) const
+SGCommandMgr::getCommand (const std::string &name) const
 {
   const command_map::const_iterator it = _commands.find(name);
   return (it != _commands.end() ? it->second : 0);
 }
 
-vector<string>
+string_list
 SGCommandMgr::getCommandNames () const
 {
-  vector<string> names;
+  string_list names;
   command_map::const_iterator it = _commands.begin();
   command_map::const_iterator last = _commands.end();
   while (it != last) {
     names.push_back(it->first);
-    it++;
+    ++it;
   }
   return names;
 }
 
 bool
-SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
+SGCommandMgr::execute (const std::string &name, const SGPropertyNode * arg) const
 {
   command_t command = getCommand(name);
   if (command == 0)
     return false;
-  else
+
+
+  try {
     return (*command)(arg);
+  } catch (sg_exception& e) {
+    SG_LOG(SG_GENERAL, SG_ALERT, "command '" << name << "' failed with exception\n"
+      << "\tmessage:" << e.getMessage() << " (from " << e.getOrigin() << ")");
+    return false;
+  }
 }
 
 // end of commands.cxx