Changeset 5170 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Sep 7, 2005, 10:25:21 AM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/Makefile.am
r5160 r5170 5 5 6 6 libORXshell_a_SOURCES = shell.cc \ 7 shell_command.cc 7 shell_command.cc \ 8 shell_completion.cc 8 9 9 10 10 11 noinst_HEADERS= shell.h \ 11 shell_command.h 12 shell_command.h \ 13 shell_completion.h -
trunk/src/lib/shell/Makefile.in
r5160 r5170 54 54 libORXshell_a_AR = $(AR) $(ARFLAGS) 55 55 libORXshell_a_LIBADD = 56 am_libORXshell_a_OBJECTS = shell.$(OBJEXT) shell_command.$(OBJEXT) 56 am_libORXshell_a_OBJECTS = shell.$(OBJEXT) shell_command.$(OBJEXT) \ 57 shell_completion.$(OBJEXT) 57 58 libORXshell_a_OBJECTS = $(am_libORXshell_a_OBJECTS) 58 59 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) … … 60 61 am__depfiles_maybe = depfiles 61 62 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/shell.Po \ 62 @AMDEP_TRUE@ ./$(DEPDIR)/shell_command.Po 63 @AMDEP_TRUE@ ./$(DEPDIR)/shell_command.Po \ 64 @AMDEP_TRUE@ ./$(DEPDIR)/shell_completion.Po 63 65 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 64 66 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) … … 183 185 noinst_LIBRARIES = libORXshell.a 184 186 libORXshell_a_SOURCES = shell.cc \ 185 shell_command.cc 187 shell_command.cc \ 188 shell_completion.cc 186 189 187 190 noinst_HEADERS = shell.h \ 188 shell_command.h 191 shell_command.h \ 192 shell_completion.h 189 193 190 194 all: all-am … … 237 241 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell.Po@am__quote@ 238 242 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_command.Po@am__quote@ 243 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_completion.Po@am__quote@ 239 244 240 245 .cc.o: -
trunk/src/lib/shell/shell_command.cc
r5166 r5170 27 27 28 28 using namespace std; 29 30 /** 31 * creates a new ShellCommandClass 32 * @param className the Name of the command-class to create 33 */ 34 ShellCommandClass::ShellCommandClass(const char* className) 35 { 36 this->className = className; 37 this->classID = CL_NULL; 38 this->commandList = new tList<ShellCommandBase>; 39 40 ShellCommandClass::commandClassList->add(this); 41 } 42 43 /** 44 * destructs the shellCommandClass again 45 */ 46 ShellCommandClass::~ShellCommandClass() 47 { 48 tIterator<ShellCommandBase>* iterator = this->commandList->getIterator(); 49 ShellCommandBase* elem = iterator->firstElement(); 50 while(elem != NULL) 51 { 52 delete elem; 53 elem = iterator->nextElement(); 54 } 55 delete iterator; 56 delete this->commandList; 57 } 58 59 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className) 60 { 61 if (ShellCommandClass::commandClassList == NULL) 62 initCommandClassList(); 63 64 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator(); 65 ShellCommandClass* elem = iterator->firstElement(); 66 while(elem != NULL) 67 { 68 if (!strcmp(className, elem->className)) 69 { 70 delete iterator; 71 return elem; 72 } 73 elem = iterator->nextElement(); 74 } 75 delete iterator; 76 return NULL; 77 } 78 79 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className) 80 { 81 if (ShellCommandClass::commandClassList == NULL) 82 initCommandClassList(); 83 84 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator(); 85 ShellCommandClass* elem = iterator->firstElement(); 86 while(elem != NULL) 87 { 88 if (!strcmp(className, elem->className)) 89 { 90 delete iterator; 91 return elem; 92 } 93 elem = iterator->nextElement(); 94 } 95 delete iterator; 96 return new ShellCommandClass(className); 97 } 98 99 100 void ShellCommandClass::initCommandClassList() 101 { 102 if (ShellCommandClass::commandClassList == NULL) 103 { 104 ShellCommandClass::commandClassList = new tList<ShellCommandClass>; 105 ShellCommand<ShellCommandBase>::registerCommand("debug", "ShellCommand", &ShellCommandBase::debugDyn); 106 } 107 } 108 109 tList<ShellCommandClass>* ShellCommandClass::commandClassList = NULL; 29 110 30 111 /** … … 42 123 43 124 // this->classID = classID; 44 this->className = className; //ClassList::IDToString(classID);125 ShellCommandClass::getCommandClass(className)->commandList->add(this); //ClassList::IDToString(classID); 45 126 46 127 // handling parameters, and storing them: … … 85 166 } 86 167 } 87 88 // adding this ShellCommand to the list of known Commands89 ShellCommandBase::commandList->add(this);90 168 } 91 169 … … 104 182 void ShellCommandBase::unregisterAllCommands() 105 183 { 106 tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator();107 ShellCommandBase* elem = iterator->firstElement();108 while(elem != NULL)109 {110 delete elem;111 112 elem = iterator->nextElement();113 }114 delete iterator;115 116 delete ShellCommandBase::commandList;117 ShellCommandBase::commandList = NULL;184 // tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator(); 185 // ShellCommandBase* elem = iterator->firstElement(); 186 // while(elem != NULL) 187 // { 188 // delete elem; 189 // 190 // elem = iterator->nextElement(); 191 // } 192 // delete iterator; 193 // 194 // delete ShellCommandBase::commandList; 195 // ShellCommandBase::commandList = NULL; 118 196 } 119 197 … … 130 208 } 131 209 132 tList<ShellCommandBase>* ShellCommandBase::commandList = NULL;133 210 134 211 … … 145 222 bool ShellCommandBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...) 146 223 { 147 va_list parameterList; 148 va_start(parameterList, paramCount); 149 150 if (ShellCommandBase::commandList == NULL) 151 { 152 ShellCommandBase::commandList = new tList<ShellCommandBase>; 153 ShellCommand<ShellCommandBase>::registerCommand("debug", "ShellCommand", &ShellCommandBase::debugDyn); 224 if (ShellCommandClass::commandClassList == NULL) 225 { 226 ShellCommandClass::initCommandClassList(); 154 227 return false; 155 228 } 156 229 157 tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator(); 158 ShellCommandBase* elem = iterator->firstElement(); 159 while(elem != NULL) 160 { 161 if (!strcmp(className, elem->className) && !strcmp(commandName, elem->getName())) 162 { 163 PRINTF(2)("Command already registered\n"); 164 delete iterator; 165 return true; 166 } 167 elem = iterator->nextElement(); 168 } 169 delete iterator; 170 return false; 230 const ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className); 231 if (checkClass != NULL) 232 { 233 tIterator<ShellCommandBase>* iterator = checkClass->commandList->getIterator(); 234 ShellCommandBase* elem = iterator->firstElement(); 235 while(elem != NULL) 236 { 237 if (!strcmp(commandName, elem->getName())) 238 { 239 PRINTF(2)("Command already registered\n"); 240 delete iterator; 241 return true; 242 } 243 elem = iterator->nextElement(); 244 } 245 delete iterator; 246 return false; 247 } 248 else 249 return false; 171 250 } 172 251 … … 180 259 bool ShellCommandBase::execute(const char* executionString) 181 260 { 182 if (ShellCommandBase::commandList == NULL)183 return false;184 185 tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator();186 ShellCommandBase* elem = iterator->firstElement();187 while(elem != NULL)188 {189 printf("%s::%s\n", elem->className, elem->getName());190 if (!strncasecmp (executionString, elem->className, strlen(elem->className)) &&191 (*(executionString+strlen(elem->className)) == ' ' ||192 *(executionString+strlen(elem->className)) == ':' ))193 {194 const char* commandBegin = executionString + strlen(elem->className);195 196 PRINTF(4)("Class %s matches\n", elem->className);197 BaseObject* objectPointer = NULL;198 if (ClassList::StringToID(elem->className) & CL_MASK_SINGLETON == CL_MASK_SINGLETON)199 {200 while(*commandBegin == ' ')201 commandBegin++;202 if (strncmp (commandBegin, elem->getName(), strlen(elem->getName())) ||203 *(commandBegin + strlen(elem->getName())) != ' ' &&204 *(commandBegin + strlen(elem->getName())) != '\0')205 {206 elem = iterator->nextElement();207 continue;208 }209 PRINTF(4)("Command %s matches\n", elem->getName());210 // getting singleton-reference211 tList<BaseObject>* list = ClassList::getList(elem->className);212 if (list != NULL)213 objectPointer = list->firstElement();214 }215 else216 {217 // checking for the Object218 while(*commandBegin == ' ')219 commandBegin++;220 tList<BaseObject>* list = ClassList::getList(elem->className);221 if (list == NULL)222 break;223 tIterator<BaseObject>* iterBO = list->getIterator();224 BaseObject* enumBO = iterBO->firstElement();225 while(enumBO != NULL)226 {227 if(!strncmp(commandBegin, enumBO->getName(), strlen(enumBO->getName())))228 {229 PRINTF(4)("Object %s matches\n", enumBO->getName());230 objectPointer = enumBO;231 break;232 }233 enumBO = iterBO->nextElement();234 }235 delete iterBO;236 237 // break on no object Found. We cannot operate on Classes, but on Objects238 if (objectPointer == NULL)239 break;240 commandBegin = commandBegin + strlen(objectPointer->getName());241 while(*commandBegin == ' ')242 commandBegin++;243 // checking for the requested function.244 if (strncmp (commandBegin, elem->getName(), strlen(elem->getName())))245 {246 elem = iterator->nextElement();247 continue;248 }249 PRINTF(4)("Function '%s' found\n", commandBegin);250 }251 const char* paramBegin = strchr(commandBegin, ' ');252 if (paramBegin == NULL)253 paramBegin = commandBegin + strlen(elem->getName());254 while (*paramBegin == ' ')255 paramBegin++;256 257 PRINTF(3)("Parameters to Pass: %s\n", paramBegin);258 if (objectPointer != NULL && paramBegin != NULL)259 {260 elem->executeCommand(objectPointer, paramBegin);261 delete iterator;262 return true;263 }264 }265 elem = iterator->nextElement();266 }267 delete iterator;268 return true;261 // if (ShellCommandBase::commandList == NULL) 262 // return false; 263 // 264 // tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator(); 265 // ShellCommandBase* elem = iterator->firstElement(); 266 // while(elem != NULL) 267 // { 268 // printf("%s::%s\n", elem->className, elem->getName()); 269 // if (!strncasecmp (executionString, elem->className, strlen(elem->className)) && 270 // (*(executionString+strlen(elem->className)) == ' ' || 271 // *(executionString+strlen(elem->className)) == ':' )) 272 // { 273 // const char* commandBegin = executionString + strlen(elem->className); 274 // 275 // PRINTF(4)("Class %s matches\n", elem->className); 276 // BaseObject* objectPointer = NULL; 277 // if (ClassList::StringToID(elem->className) & CL_MASK_SINGLETON == CL_MASK_SINGLETON) 278 // { 279 // while(*commandBegin == ' ') 280 // commandBegin++; 281 // if (strncmp (commandBegin, elem->getName(), strlen(elem->getName())) || 282 // *(commandBegin + strlen(elem->getName())) != ' ' && 283 // *(commandBegin + strlen(elem->getName())) != '\0') 284 // { 285 // elem = iterator->nextElement(); 286 // continue; 287 // } 288 // PRINTF(4)("Command %s matches\n", elem->getName()); 289 // // getting singleton-reference 290 // tList<BaseObject>* list = ClassList::getList(elem->className); 291 // if (list != NULL) 292 // objectPointer = list->firstElement(); 293 // } 294 // else 295 // { 296 // // checking for the Object 297 // while(*commandBegin == ' ') 298 // commandBegin++; 299 // tList<BaseObject>* list = ClassList::getList(elem->className); 300 // if (list == NULL) 301 // break; 302 // tIterator<BaseObject>* iterBO = list->getIterator(); 303 // BaseObject* enumBO = iterBO->firstElement(); 304 // while(enumBO != NULL) 305 // { 306 // if(!strncmp(commandBegin, enumBO->getName(), strlen(enumBO->getName()))) 307 // { 308 // PRINTF(4)("Object %s matches\n", enumBO->getName()); 309 // objectPointer = enumBO; 310 // break; 311 // } 312 // enumBO = iterBO->nextElement(); 313 // } 314 // delete iterBO; 315 // 316 // // break on no object Found. We cannot operate on Classes, but on Objects 317 // if (objectPointer == NULL) 318 // break; 319 // commandBegin = commandBegin + strlen(objectPointer->getName()); 320 // while(*commandBegin == ' ') 321 // commandBegin++; 322 // // checking for the requested function. 323 // if (strncmp (commandBegin, elem->getName(), strlen(elem->getName()))) 324 // { 325 // elem = iterator->nextElement(); 326 // continue; 327 // } 328 // PRINTF(4)("Function '%s' found\n", commandBegin); 329 // } 330 // const char* paramBegin = strchr(commandBegin, ' '); 331 // if (paramBegin == NULL) 332 // paramBegin = commandBegin + strlen(elem->getName()); 333 // while (*paramBegin == ' ') 334 // paramBegin++; 335 // 336 // PRINTF(3)("Parameters to Pass: %s\n", paramBegin); 337 // if (objectPointer != NULL && paramBegin != NULL) 338 // { 339 // elem->executeCommand(objectPointer, paramBegin); 340 // delete iterator; 341 // return true; 342 // } 343 // } 344 // elem = iterator->nextElement(); 345 // } 346 // delete iterator; 347 // return true; 269 348 } 270 349 … … 297 376 void ShellCommandBase::debug() 298 377 { 299 if (ShellCommand Base::commandList == NULL)378 if (ShellCommandClass::commandClassList == NULL) 300 379 { 301 380 PRINT(0)("No Command registered so far\n"); … … 303 382 } 304 383 305 tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator(); 306 ShellCommandBase* elem = iterator->firstElement(); 307 while(elem != NULL) 308 { 309 PRINT(0)("Class:'%s':command:'%s':params:%d: ", elem->className, elem->getName(), elem->paramCount); 310 for (unsigned int i = 0; i< elem->paramCount; i++) 311 printf("%s ", ShellCommandBase::paramToString(elem->parameters[i])); 312 if (elem->description != NULL) 313 printf("- %s", elem->description); 314 printf("\n"); 315 316 elem = iterator->nextElement(); 317 } 318 delete iterator; 384 tIterator<ShellCommandClass>* iteratorCL = ShellCommandClass::commandClassList->getIterator(); 385 ShellCommandClass* elemCL = iteratorCL->firstElement(); 386 while(elemCL != NULL) 387 { 388 tIterator<ShellCommandBase>* iterator = elemCL->commandList->getIterator(); 389 const ShellCommandBase* elem = iterator->firstElement(); 390 { 391 PRINT(0)("Class:'%s' registered: \n", elemCL->className); 392 PRINT(0)(" command:'%s':params:%d: ", elem->getName(), elem->paramCount); 393 for (unsigned int i = 0; i< elem->paramCount; i++) 394 printf("%s ", ShellCommandBase::paramToString(elem->parameters[i])); 395 if (elem->description != NULL) 396 printf("- %s", elem->description); 397 printf("\n"); 398 399 elem = iterator->nextElement(); 400 } 401 delete iterator; 402 elemCL = iteratorCL->nextElement(); 403 } 404 delete iteratorCL; 319 405 } 320 406 -
trunk/src/lib/shell/shell_command.h
r5166 r5170 35 35 // BASE CLASS // 36 36 //////////////// 37 class ShellCommandBase; 38 39 //! A class to hold all Classes that have (once) registered Commands. 40 class ShellCommandClass : public BaseObject 41 { 42 friend class ShellCommandBase; 43 44 public: 45 static const tList<ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; }; 46 static ShellCommandClass* getCommandClass(const char* className); 47 48 private: 49 ShellCommandClass(const char* className); 50 ~ShellCommandClass(); 51 52 static const ShellCommandClass* isRegistered(const char* className); 53 static void initCommandClassList(); 54 55 private: 56 const char* className; 57 ClassID classID; 58 tList<ShellCommandBase>* commandList; 59 static tList<ShellCommandClass>* commandClassList; //!< A list of Classes 60 }; 61 62 37 63 //! a baseClass for all possible ShellCommands 38 64 class ShellCommandBase : public BaseObject 39 65 { 66 friend class ShellCommandClass; 40 67 public: 41 68 static bool execute (const char* executionString); … … 44 71 45 72 /** @returns the CommandList of the Shell */ 46 static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; };47 73 48 74 static void unregisterAllCommands(); … … 74 100 75 101 private: 76 // long classID; //!< The ID of the Class associated to this Command 77 const char* className; //!< The Name of the Class associated to this Command 102 ShellCommandClass* shellClass; //!< A Pointer to the Shell-Class this Command belongs to. 78 103 79 104 const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla"); 80 81 // STATIC MEMBERS82 static tList<ShellCommandBase>* commandList; //!< A list of availiable commands.83 105 }; 84 106 -
trunk/src/lib/shell/shell_completion.cc
r5166 r5170 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include " proto_class.h"18 #include "shell_completion.h" 19 19 20 20 using namespace std; … … 25 25 * @todo this constructor is not jet implemented - do it 26 26 */ 27 ProtoClass::ProtoClass()27 ShellCompletion::ShellCompletion () 28 28 { 29 29 // this->setClassID(CL_PROTO_ID, "ProtoClass"); 30 30 31 31 /* If you make a new class, what is most probably the case when you write this file … … 45 45 * standard deconstructor 46 46 */ 47 ProtoClass::~ProtoClass()47 ShellCompletion::~ShellCompletion () 48 48 { 49 49 // delete what has to be deleted here -
trunk/src/lib/shell/shell_completion.h
r5166 r5170 1 1 /*! 2 * @file proto_class.h3 * @brief Definition of ...2 * @file shell_completion.h 3 * @brief The Shell Completion Tasks 4 4 */ 5 5 6 #ifndef _PROTO_CLASS_H 7 #define _PROTO_CLASS_H 8 9 #include "base_object.h" 6 #ifndef _SHELL_COMPLETION_H 7 #define _SHELL_COMPLETION_H 10 8 11 9 // FORWARD DECLARATION 12 10 13 11 14 15 12 //! A class for ... 16 class ProtoClass : public BaseObject{13 class ShellCompletion { 17 14 18 15 public: 19 ProtoClass();20 virtual ~ ProtoClass();16 ShellCompletion(); 17 virtual ~ShellCompletion(); 21 18 22 19 … … 25 22 }; 26 23 27 #endif /* _ PROTO_CLASS_H */24 #endif /* _SHELL_COMPLETION_H */
Note: See TracChangeset
for help on using the changeset viewer.