X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fcommands.cxx;h=6b4b11ea189a2cc35199f4a5b43c4032a7e10d3f;hb=1a835a2e1b06ac4eb87fc1c72175cf54728b3fb3;hp=16706d96ecde648e8095fdb78cd2674ccbecd086;hpb=22c7df5936a7b8a1bee437b51100374bd6ff7645;p=simgear.git diff --git a/simgear/structure/commands.cxx b/simgear/structure/commands.cxx index 16706d96..6b4b11ea 100644 --- a/simgear/structure/commands.cxx +++ b/simgear/structure/commands.cxx @@ -4,14 +4,20 @@ // // $Id$ +#ifdef HAVE_CONFIG_H +# include +#endif + #include #include -#include -#include - #include "commands.hxx" +#include +#include +#include +#include +#include //////////////////////////////////////////////////////////////////////// @@ -29,7 +35,7 @@ SGCommandMgr::~SGCommandMgr () // no-op } -OpenThreads::Mutex SGCommandMgr::_instanceMutex; +SGMutex SGCommandMgr::_instanceMutex; SGCommandMgr* SGCommandMgr::instance() @@ -38,7 +44,7 @@ SGCommandMgr::instance() if (mgr.get()) return mgr.get(); - OpenThreads::ScopedLock lock(_instanceMutex); + SGGuard lock(_instanceMutex); if (mgr.get()) return mgr.get(); @@ -47,39 +53,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_list SGCommandMgr::getCommandNames () const { - vector 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