17 #include "libopenrave.h"
23 RegisterCommand(
"help",boost::bind(&InterfaceBase::_GetCommandHelp,
this,_1,_2),
24 "display help commands.");
29 boost::unique_lock< boost::shared_mutex > lock(_mutexInterface);
30 __mapCommands.clear();
31 __mapUserData.clear();
32 __mapReadableInterfaces.clear();
40 boost::unique_lock< boost::shared_mutex > lock(_mutexInterface);
41 std::map<std::string, UserDataPtr>::iterator it = __mapUserData.find(key);
42 if( it == __mapUserData.end() ) {
43 __mapUserData[key] = data;
46 olduserdata = it->second;
55 boost::shared_lock< boost::shared_mutex > lock(_mutexInterface);
56 std::map<std::string, UserDataPtr>::const_iterator it = __mapUserData.find(key);
57 if( it == __mapUserData.end() ) {
68 boost::unique_lock< boost::shared_mutex > lock(_mutexInterface);
69 std::map<std::string, UserDataPtr>::iterator it = __mapUserData.find(key);
70 if( it == __mapUserData.end() ) {
73 olduserdata = it->second;
74 __mapUserData.erase(it);
85 __mapUserData = preference->__mapUserData;
86 __struri = preference->__struri;
87 __mapReadableInterfaces = preference->__mapReadableInterfaces;
98 boost::shared_ptr<InterfaceCommand> interfacecmd;
100 boost::shared_lock< boost::shared_mutex > lock(_mutexInterface);
101 CMDMAP::iterator it = __mapCommands.find(cmd);
102 if( it == __mapCommands.end() ) {
105 interfacecmd = it->second;
107 if( !interfacecmd->fn(sout,sinput) ) {
116 FOREACHC(it, __mapReadableInterfaces) {
117 it->second->Serialize(writer,options);
123 boost::unique_lock< boost::shared_mutex > lock(_mutexInterface);
124 if((cmdname.size() == 0)|| !
utils::IsValidName(cmdname) ||(_stricmp(cmdname.c_str(),
"commands") == 0)) {
127 if( __mapCommands.find(cmdname) != __mapCommands.end() ) {
130 __mapCommands[cmdname] = boost::shared_ptr<InterfaceCommand>(
new InterfaceCommand(fncmd, strhelp));
135 boost::unique_lock< boost::shared_mutex > lock(_mutexInterface);
136 CMDMAP::iterator it = __mapCommands.find(cmdname);
137 if( it != __mapCommands.end() ) {
138 __mapCommands.erase(it);
142 bool InterfaceBase::_GetCommandHelp(std::ostream& o, std::istream& sinput)
const
144 boost::shared_lock< boost::shared_mutex > lock(_mutexInterface);
146 CMDMAP::const_iterator it;
147 while(!sinput.eof()) {
152 std::transform(cmd.begin(), cmd.end(), cmd.begin(), ::tolower);
154 if( cmd ==
"commands" ) {
155 for(it = __mapCommands.begin(); it != __mapCommands.end(); ++it) {
156 o << it->first <<
" ";
160 else if( cmd ==
"label" ) {
164 it = __mapCommands.find(cmd);
165 if( it != __mapCommands.end() ) {
166 o << it->second->help;
172 RAVELOG_ERROR(str(boost::format(
"failed processing command %s\n")%cmd));
178 o << endl <<
GetXMLId() <<
" Commands" << endl;
179 for(
size_t i = 0; i <
GetXMLId().size(); ++i) {
182 o <<
"=========" << endl << endl;
183 for(it = __mapCommands.begin(); it != __mapCommands.end(); ++it) {
184 if( label.size() > 0 ) {
185 string strlower = it->first;
186 std::transform(strlower.begin(), strlower.end(), strlower.begin(), ::tolower);
187 o << endl <<
".. _" << label << strlower <<
":" << endl << endl;
189 o << endl << it->first << endl;
190 for(
size_t i = 0; i < it->first.size(); ++i) {
193 o << endl << endl << it->second->help << endl << endl <<
"~~~~" << endl << endl;
200 boost::shared_lock< boost::shared_mutex > lock(_mutexInterface);
201 READERSMAP::const_iterator it = __mapReadableInterfaces.find(xmltag);
202 return it != __mapReadableInterfaces.end() ? it->second :
XMLReadablePtr();
207 boost::unique_lock< boost::shared_mutex > lock(_mutexInterface);
208 READERSMAP::iterator it = __mapReadableInterfaces.find(xmltag);
209 if( it == __mapReadableInterfaces.end() ) {
210 __mapReadableInterfaces[xmltag] = readable;
214 it->second = readable;