Changeset 5639 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Nov 18, 2005, 7:21:32 PM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 6 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/Makefile.am
r5463 r5639 8 8 shell_input.cc \ 9 9 shell_command.cc \ 10 shell_command_class.cc \ 10 11 shell_completion.cc 11 12 … … 15 16 shell_input.h \ 16 17 shell_command.h \ 18 shell_command_class.h \ 17 19 shell_completion.h -
trunk/src/lib/shell/Makefile.in
r5479 r5639 56 56 am_libORXshell_a_OBJECTS = shell.$(OBJEXT) shell_buffer.$(OBJEXT) \ 57 57 shell_input.$(OBJEXT) shell_command.$(OBJEXT) \ 58 shell_com pletion.$(OBJEXT)58 shell_command_class.$(OBJEXT) shell_completion.$(OBJEXT) 59 59 libORXshell_a_OBJECTS = $(am_libORXshell_a_OBJECTS) 60 60 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) … … 188 188 shell_input.cc \ 189 189 shell_command.cc \ 190 shell_command_class.cc \ 190 191 shell_completion.cc 191 192 … … 194 195 shell_input.h \ 195 196 shell_command.h \ 197 shell_command_class.h \ 196 198 shell_completion.h 197 199 … … 246 248 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_buffer.Po@am__quote@ 247 249 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_command.Po@am__quote@ 250 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_command_class.Po@am__quote@ 248 251 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_completion.Po@am__quote@ 249 252 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_input.Po@am__quote@ -
trunk/src/lib/shell/shell_command.cc
r5637 r5639 17 17 18 18 #include "shell_command.h" 19 #include "shell_command_class.h" 19 20 20 21 #include "list.h" … … 29 30 using namespace std; 30 31 31 /**32 * creates a new ShellCommandClass33 * @param className the Name of the command-class to create34 */35 ShellCommandClass::ShellCommandClass(const char* className)36 {37 this->setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass");38 this->setName(className);39 40 this->className = className;41 this->classID = CL_NULL;42 this->commandList = new tList<ShellCommand>;43 44 ShellCommandClass::commandClassList->add(this);45 }46 47 /**48 * destructs the shellCommandClass again49 */50 ShellCommandClass::~ShellCommandClass()51 {52 tIterator<ShellCommand>* iterator = this->commandList->getIterator();53 ShellCommand* elem = iterator->firstElement();54 while(elem != NULL)55 {56 delete elem;57 elem = iterator->nextElement();58 }59 delete iterator;60 delete this->commandList;61 }62 63 /**64 * collects the Commands registered to some class.65 * @param className the name of the Class to collect the Commands from.66 * @param stringList a List to paste the Commands into.67 * @returns true on success, false otherwise68 */69 bool ShellCommandClass::getCommandListOfClass(const char* className, tList<const char>* stringList)70 {71 if (stringList == NULL || className == NULL)72 return false;73 74 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();75 ShellCommandClass* elem = iterator->firstElement();76 while(elem != NULL)77 {78 if (!strcmp (elem->getName(), className))79 {80 tIterator<ShellCommand>* itFkt = elem->commandList->getIterator();81 ShellCommand* command = itFkt->firstElement();82 while (command != NULL)83 {84 stringList->add(command->getName());85 command = itFkt->nextElement();86 }87 delete itFkt;88 }89 90 elem = iterator->nextElement();91 }92 delete iterator;93 return true;94 }95 96 /**97 * collects the Aliases registered to the ShellCommands98 * @param stringList a List to paste the Aliases into.99 * @returns true on success, false otherwise100 */101 bool ShellCommandClass::getCommandListOfAlias(tList<const char>* stringList)102 {103 if (stringList == NULL || ShellCommandClass::aliasList == NULL)104 return false;105 106 tIterator<ShellCommandAlias>* iterator = ShellCommandClass::aliasList->getIterator();107 ShellCommandAlias* elem = iterator->firstElement();108 while(elem != NULL)109 {110 stringList->add(elem->getName());111 elem = iterator->nextElement();112 }113 delete iterator;114 return true;115 }116 117 /**118 * unregisters all Commands that exist119 */120 void ShellCommandClass::unregisterAllCommands()121 {122 if (ShellCommandClass::commandClassList != NULL)123 {124 // unregister all commands125 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();126 ShellCommandClass* elem = iterator->firstElement();127 while(elem != NULL)128 {129 delete elem;130 131 elem = iterator->nextElement();132 }133 delete iterator;134 135 delete ShellCommandClass::commandClassList;136 ShellCommandClass::commandClassList = NULL;137 }138 139 // unregister all aliases (there should be nothing to do here :))140 if (ShellCommandClass::aliasList != NULL)141 {142 tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();143 ShellCommandAlias* elemAL = itAL->firstElement();144 while(elemAL != NULL)145 {146 delete elemAL;147 elemAL = itAL->nextElement();148 }149 delete itAL;150 delete ShellCommandClass::aliasList;151 ShellCommandClass::aliasList = NULL;152 }153 }154 155 /**156 * checks if a Class is already registered to the Commands' class-stack157 * @param className the Name of the Class to check for158 * @returns the CommandClass if found, NULL otherwise159 */160 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)161 {162 if (ShellCommandClass::commandClassList == NULL)163 initCommandClassList();164 165 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();166 ShellCommandClass* elem = iterator->firstElement();167 while(elem != NULL)168 {169 if (!strcmp(className, elem->className))170 {171 if (elem->classID == CL_NULL)172 elem->classID = ClassList::StringToID(className);173 174 delete iterator;175 return elem;176 }177 elem = iterator->nextElement();178 }179 delete iterator;180 return NULL;181 }182 183 /**184 * searches for a CommandClass185 * @param className the name of the CommandClass186 * @returns the CommandClass if found, or a new CommandClass if not187 */188 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)189 {190 if (ShellCommandClass::commandClassList == NULL)191 initCommandClassList();192 193 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();194 ShellCommandClass* elem = iterator->firstElement();195 while(elem != NULL)196 {197 if (!strcmp(className, elem->className))198 {199 delete iterator;200 return elem;201 }202 elem = iterator->nextElement();203 }204 delete iterator;205 return new ShellCommandClass(className);206 }207 208 /**209 * initializes the CommandList (if it is NULL)210 */211 void ShellCommandClass::initCommandClassList()212 {213 if (ShellCommandClass::commandClassList == NULL)214 {215 ShellCommandClass::commandClassList = new tList<ShellCommandClass>;216 ShellCommand::registerCommand("debug", "ShellCommand", new ExecutorStatic<ShellCommand>(ShellCommand::debug));217 }218 }219 220 void ShellCommandClass::help(const char* className)221 {222 if (className == NULL)223 return;224 if (likely(ShellCommandClass::commandClassList != NULL))225 {226 tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();227 ShellCommandClass* elemCL = itCL->firstElement();228 while(elemCL != NULL)229 {230 if (elemCL->className && !strcasecmp(className, elemCL->className))231 {232 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());233 tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator();234 const ShellCommand* elem = iterator->firstElement();235 while(elem != NULL)236 {237 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount);238 for (unsigned int i = 0; i< elem->paramCount; i++)239 PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));240 if (elem->description != NULL)241 PRINT(0)("- %s", elem->description);242 PRINT(0)("\n");243 elem = iterator->nextElement();244 }245 delete iterator;246 247 delete itCL;248 return;249 }250 elemCL = itCL->nextElement();251 }252 delete itCL;253 PRINTF(3)("Class %s not found in Command's classes\n", className);254 }255 else256 {257 PRINTF(1)("List of commandClasses does not exist");258 }259 }260 261 tList<ShellCommandClass>* ShellCommandClass::commandClassList = NULL;262 tList<ShellCommandAlias>* ShellCommandClass::aliasList = NULL;263 264 265 266 267 268 269 270 271 272 273 ////////////////////////274 // SHELL COMMAND BASE //275 ////////////////////////276 32 /** 277 33 * constructs and registers a new Command -
trunk/src/lib/shell/shell_command.h
r5637 r5639 22 22 // FORWARD DECLARATION 23 23 template<class T> class tList; 24 class ShellCommandClass; 25 class ShellCommandAlias; 24 26 25 27 /** … … 63 65 ShellCommand_Static = 2, 64 66 } ShellCommand_Type; 65 66 ////////////////67 // BASE CLASS //68 ////////////////69 class ShellCommand;70 class ShellCommandAlias;71 72 //! A class to hold all Classes that have (once) registered Commands.73 class ShellCommandClass : public BaseObject74 {75 friend class ShellCommand;76 77 public:78 /** @returns the CommandClassList */79 static const tList<ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; };80 static bool getCommandListOfClass(const char* className, tList<const char>* stringList);81 static bool getCommandListOfAlias(tList<const char>* aliasList);82 83 static ShellCommandClass* getCommandClass(const char* className);84 static void unregisterAllCommands();85 86 static void help (const char* className);87 88 private:89 ShellCommandClass(const char* className);90 ~ShellCommandClass();91 92 static const ShellCommandClass* isRegistered(const char* className);93 static void initCommandClassList();94 95 private:96 const char* className; //!< The Name of the Class. This should match the ClassName of the Commands Class.97 long classID; //!< The classID of this Class98 tList<ShellCommand>* commandList; //!< A list of Commands from this Class99 static tList<ShellCommandClass>* commandClassList; //!< A list of Classes100 static tList<ShellCommandAlias>* aliasList; //!< An Alias to A Command. (only for classes with one Instance)101 };102 103 67 104 68 //! a baseClass for all possible ShellCommands -
trunk/src/lib/shell/shell_command_class.cc
r5637 r5639 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include "shell_command_class.h" 19 18 20 #include "shell_command.h" 19 21 … … 22 24 #include "class_list.h" 23 25 24 #include "key_names.h"25 #include <stdarg.h>26 26 #include <stdio.h> 27 27 #include <string.h> 28 28 29 29 using namespace std; 30 31 tList<ShellCommandClass>* ShellCommandClass::commandClassList = NULL; 32 tList<ShellCommandAlias>* ShellCommandClass::aliasList = NULL; 30 33 31 34 /** … … 259 262 } 260 263 261 tList<ShellCommandClass>* ShellCommandClass::commandClassList = NULL;262 tList<ShellCommandAlias>* ShellCommandClass::aliasList = NULL;263 264 265 266 267 268 269 270 271 272 273 ////////////////////////274 // SHELL COMMAND BASE //275 ////////////////////////276 /**277 * constructs and registers a new Command278 * @param commandName the name of the Command279 * @param className the name of the class to apply this command to280 * @param paramCount the count of parameters this command takes281 */282 ShellCommand::ShellCommand(const char* commandName, const char* className, Executor* executor)283 {284 this->setClassID(CL_SHELL_COMMAND, "ShellCommand");285 this->setName(commandName);286 this->description = NULL;287 this->alias = NULL;288 289 // this->classID = classID;290 this->shellClass = ShellCommandClass::getCommandClass(className); //ClassList::IDToString(classID);291 if (this->shellClass != NULL)292 this->shellClass->commandList->add(this);293 // handling parameters, and storing them:294 if (paramCount > FUNCTOR_MAX_ARGUMENTS)295 paramCount = FUNCTOR_MAX_ARGUMENTS;296 this->paramCount = paramCount;297 this->parameters = new unsigned int[paramCount];298 this->defaultValue = new MultiType[paramCount];299 300 this->executor = executor;301 }302 303 /**304 * deconstructs a ShellCommand305 */306 ShellCommand::~ShellCommand()307 {308 delete[] this->parameters;309 delete[] this->defaultValue;310 if (this->alias != NULL && ShellCommandClass::aliasList != NULL)311 {312 ShellCommandClass::aliasList->remove(this->alias);313 delete this->alias;314 }315 }316 317 /**318 * registers a new ShellCommand319 */320 ShellCommand* ShellCommand::registerCommand(const char* commandName, const char* className, Executor* executor)321 {322 if (ShellCommand::isRegistered(commandName, className, executor))323 return NULL;324 else325 return new ShellCommand(commandName, className, executor);326 327 }328 329 330 331 332 /**333 * unregister an existing commandName334 * @param className the name of the Class the command belongs to.335 * @param commandName the name of the command itself336 */337 void ShellCommand::unregisterCommand(const char* commandName, const char* className)338 {339 if (ShellCommandClass::commandClassList == NULL)340 ShellCommandClass::initCommandClassList();341 342 const ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className);343 344 if (checkClass != NULL)345 {346 tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator();347 ShellCommand* elem = iterator->firstElement();348 while(elem != NULL)349 {350 if (!strcmp(commandName, elem->getName()))351 {352 checkClass->commandList->remove(elem);353 delete elem;354 break;355 }356 elem = iterator->nextElement();357 }358 delete iterator;359 360 if (checkClass->commandList->getSize() == 0)361 {362 ShellCommandClass::commandClassList->remove(checkClass);363 delete checkClass;364 }365 }366 }367 368 /**369 * checks if a command has already been registered.370 * @param commandName the name of the Command371 * @param className the name of the Class the command should apply to.372 * @param paramCount how many arguments the Command takes373 * @returns true, if the command is registered/false otherwise374 *375 * This is used internally, to see, if we have multiple command subscriptions.376 * This is checked in the registerCommand-function.377 */378 bool ShellCommand::isRegistered(const char* commandName, const char* className, Executor* executor)379 {380 if (ShellCommandClass::commandClassList == NULL)381 {382 ShellCommandClass::initCommandClassList();383 return false;384 }385 386 const ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className);387 if (checkClass != NULL)388 {389 tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator();390 ShellCommand* elem = iterator->firstElement();391 while(elem != NULL)392 {393 if (!strcmp(commandName, elem->getName()))394 {395 PRINTF(2)("Command already registered\n");396 delete iterator;397 return true;398 }399 elem = iterator->nextElement();400 }401 delete iterator;402 return false;403 }404 else405 return false;406 }407 408 409 /**410 * executes commands411 * @param executionString the string containing the following input412 * ClassName [ObjectName] functionName [parameter1[,parameter2[,...]]]413 * @return true on success, false otherwise.414 */415 bool ShellCommand::execute(const char* executionString)416 {417 if (ShellCommandClass::commandClassList == NULL)418 return false;419 420 long classID = CL_NULL; //< the classID retrieved from the Class.421 ShellCommandClass* commandClass = NULL; //< the command class this command applies to.422 tList<BaseObject>* objectList = NULL; //< the list of Objects stored in classID423 BaseObject* objectPointer = NULL; //< a pointer to th Object to Execute the command on424 bool emptyComplete = false; //< if the completion input is empty string. e.g ""425 unsigned int fktPos = 1; //< the position of the function (needed for finding it)426 // long completeType = SHELLC_NONE; //< the Type we'd like to complete.427 SubString inputSplits(executionString, true);428 429 if (inputSplits.getCount() == 0)430 return false;431 if (inputSplits.getCount() >= 1)432 {433 // CHECK FOR ALIAS434 if (ShellCommandClass::aliasList != NULL)435 {436 tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();437 ShellCommandAlias* elemAL = itAL->firstElement();438 while(elemAL != NULL)439 {440 if (elemAL->getName() != NULL && !strcmp(elemAL->getName(), inputSplits.getString(0)) && elemAL->getCommand() != NULL &&441 elemAL->getCommand()->shellClass != NULL )442 {443 objectList = ClassList::getList(elemAL->getCommand()->shellClass->getName());444 if (objectList != NULL)445 {446 if (inputSplits.getCount() > 1)447 elemAL->getCommand()->executor->execute(objectList->firstElement(), executionString+inputSplits.getOffset(1));448 else449 elemAL->getCommand()->executor->execute(objectList->firstElement(), "");450 delete itAL;451 return true;452 }453 }454 elemAL = itAL->nextElement();455 }456 delete itAL;457 }458 // looking for a Matching Class459 if (likely(ShellCommandClass::commandClassList != NULL))460 {461 tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();462 ShellCommandClass* elemCL = itCL->firstElement();463 while(elemCL != NULL)464 {465 if (elemCL->getName() && !strcasecmp(inputSplits.getString(0), elemCL->getName()))466 {467 //elemCL->getName();468 classID = ClassList::StringToID(elemCL->getName());469 commandClass = elemCL;470 objectList = ClassList::getList(classID);471 break;472 }473 elemCL = itCL->nextElement();474 }475 delete itCL;476 }477 478 if (commandClass != NULL && inputSplits.getCount() >= 2)479 {480 if (objectList != NULL)481 {482 // Checking for a Match in the Objects of classID (else take the first)483 tIterator<BaseObject>* itBO = objectList->getIterator();484 BaseObject* enumBO = itBO->firstElement();485 while(enumBO)486 {487 if (enumBO->getName() != NULL && !strcasecmp(enumBO->getName(), inputSplits.getString(1)))488 {489 objectPointer = enumBO;490 fktPos = 2;491 break;492 }493 enumBO = itBO->nextElement();494 }495 delete itBO;496 497 //498 if (objectPointer == NULL)499 objectPointer = objectList->firstElement();500 }501 // match a function.502 if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))503 {504 tIterator<ShellCommand>* itCMD = commandClass->commandList->getIterator();505 ShellCommand* enumCMD = itCMD->firstElement();506 while (enumCMD != NULL)507 {508 if (!strcmp(enumCMD->getName(), inputSplits.getString(fktPos)))509 {510 if (objectPointer == NULL && enumCMD->functorType == ShellCommand_Objective)511 {512 delete itCMD;513 return false;514 }515 if (inputSplits.getCount() > fktPos+1)516 enumCMD->executor->execute(objectPointer, executionString+inputSplits.getOffset(fktPos +1));517 else518 enumCMD->executor->execute(objectPointer, "");519 delete itCMD;520 return true;521 }522 523 enumCMD = itCMD->nextElement();524 }525 delete itCMD;526 }527 }528 }529 }530 531 /**532 * lets a command be described533 * @param description the description of the Given command534 */535 ShellCommand* ShellCommand::describe(const char* description)536 {537 if (this == NULL)538 return NULL;539 else540 {541 this->description = description;542 return this;543 }544 }545 546 /**547 * adds an Alias to this Command548 * @param alias the name of the Alias to set549 * @returns itself550 */551 ShellCommand* ShellCommand::setAlias(const char* alias)552 {553 if (this == NULL)554 return NULL;555 556 if (this->alias != NULL)557 {558 PRINTF(2)("not more than one Alias allowed for functions (%s::%s)\n", this->getName(), this->shellClass->getName());559 }560 else561 {562 if (ShellCommandClass::aliasList == NULL)563 ShellCommandClass::aliasList = new tList<ShellCommandAlias>;564 565 ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this);566 ShellCommandClass::aliasList->add(aliasCMD);567 this->alias = aliasCMD;568 }569 return this;570 }571 572 /**573 * sets default Values of the Commands574 * @param count how many default Values to set.575 * @param ... the default Values in order. They will be cast to the right type576 * @returns itself577 *578 * Be aware, that when you use this Function, you !!MUST!! match the input as579 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]580 */581 ShellCommand* ShellCommand::defaultValues(unsigned int count, ...)582 {583 if (this == NULL)584 return NULL;585 if (count == 0)586 return this;587 if (count > this->paramCount)588 count = this->paramCount;589 590 va_list defaultList;591 va_start(defaultList, count);592 593 for (unsigned int i = 0; i < count; i++)594 {595 596 597 switch (this->parameters[i])598 {599 case MT_BOOL:600 this->defaultValue[i].setInt(va_arg(defaultList, int));601 break;602 case MT_CHAR:603 this->defaultValue[i].setChar((char)va_arg(defaultList, int));604 break;605 case MT_STRING:606 this->defaultValue[i].setString(va_arg(defaultList, char*));607 break;608 case MT_INT:609 this->defaultValue[i].setInt(va_arg(defaultList, int));610 break;611 /* case MT_UINT:612 this->defaultValue[i].setInt((int)va_arg(defaultList, unsigned int));613 break;*/614 case MT_FLOAT:615 this->defaultValue[i].setFloat(va_arg(defaultList, double));616 break;617 /* case MT_LONG:618 this->defaultValue[i].setInt((int) va_arg(defaultList, long));619 break;*/620 default:621 break;622 }623 }624 return this;625 }626 627 /**628 * prints out nice information about the Shells Commands629 */630 void ShellCommand::debug()631 {632 if (ShellCommandClass::commandClassList == NULL)633 {634 PRINT(0)("No Command registered.\n");635 return;636 }637 638 tIterator<ShellCommandClass>* iteratorCL = ShellCommandClass::commandClassList->getIterator();639 ShellCommandClass* elemCL = iteratorCL->firstElement();640 while(elemCL != NULL)641 {642 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());643 tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator();644 const ShellCommand* elem = iterator->firstElement();645 while(elem != NULL)646 {647 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount);648 for (unsigned int i = 0; i< elem->paramCount; i++)649 printf("%s ", ShellCommand::paramToString(elem->parameters[i]));650 if (elem->description != NULL)651 printf("- %s", elem->description);652 printf("\n");653 654 elem = iterator->nextElement();655 }656 delete iterator;657 elemCL = iteratorCL->nextElement();658 }659 delete iteratorCL;660 }661 662 /**663 * converts a Parameter to a String664 * @param parameter the Parameter we have.665 * @returns the Name of the Parameter at Hand666 */667 const char* ShellCommand::paramToString(long parameter)668 {669 return MultiType::MultiTypeToString((MT_Type)parameter);670 // FIXME671 /* switch (parameter)672 {673 case ParameterBool:674 return "BOOL";675 break;676 case ParameterChar:677 return "CHAR";678 break;679 case ParameterString:680 return "STRING";681 break;682 case ParameterInt:683 return "INT";684 break;685 case ParameterUInt:686 return "UINT";687 break;688 case ParameterFloat:689 return "FLOAT";690 break;691 case ParameterLong:692 return "LONG";693 break;694 default:695 return "NULL";696 break;697 }*/698 } -
trunk/src/lib/shell/shell_command_class.h
r5637 r5639 1 1 /*! 2 * @file shell_command .h2 * @file shell_command_class.h 3 3 * Definition of a on-screen-shell 4 4 */ 5 5 6 #ifndef _SHELL_COMMAND_ H7 #define _SHELL_COMMAND_ H6 #ifndef _SHELL_COMMAND_CLASS_H 7 #define _SHELL_COMMAND_CLASS_H 8 8 9 9 #include "base_object.h" 10 11 #include "helper_functions.h"12 #include "multi_type.h"13 #include "substring.h"14 #include "functor_list.h"15 #include "executor/executor.h"16 #include <stdarg.h>17 18 #define SHELL_COMMAND_MAX_SIZE //!< The maximum size of a Shell Command19 20 10 21 11 22 12 // FORWARD DECLARATION 23 13 template<class T> class tList; 24 25 /**26 * an easy to use Macro to create a Command27 * @param command the name of the command (without "" around the string)28 * @param class the name of the class to apply this command to (without the "" around the string)29 * @param function the function to call30 *31 * MEANING:32 * ShellCommand* someUniqueVarName =33 * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);34 *35 * In the Shell you would call this Command using:36 * $ ClassName [ObjectName] commandNameInShell [parameters]37 */38 //#define SHELL_COMMAND(command, class, function) \39 // ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)40 #define SHELL_COMMAND(command, class, function) \41 ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorObjective<class>(&class::function))42 43 /**44 * an easy to use Macro to create a Command45 * @param command the name of the command (without "" around the string)46 * @param class the name of the class to apply this command to (without the "" around the string)47 * @param function the function to call48 *49 * MEANING:50 * ShellCommand* someUniqueVarName =51 * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);52 *53 * In the Shell you would call this Command using:54 * $ ClassName [ObjectName] commandNameInShell [parameters]55 */56 #define SHELL_COMMAND_STATIC(command, class, function) \57 ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorStatic<class>(function))58 59 60 //! an enumerator for the definition of the Type.61 typedef enum {62 ShellCommand_Objective = 1,63 ShellCommand_Static = 2,64 } ShellCommand_Type;65 14 66 15 //////////////// … … 96 45 const char* className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 97 46 long classID; //!< The classID of this Class 98 tList<ShellCommand>* commandList; //!< A list of Commands from this Class47 tList<ShellCommand>* commandList; //!< A list of Commands from this Class 99 48 static tList<ShellCommandClass>* commandClassList; //!< A list of Classes 100 49 static tList<ShellCommandAlias>* aliasList; //!< An Alias to A Command. (only for classes with one Instance) 101 50 }; 102 51 103 104 //! a baseClass for all possible ShellCommands105 class ShellCommand : public BaseObject106 {107 friend class ShellCommandClass;108 public:109 static bool execute (const char* executionString);110 111 ShellCommand* describe(const char* description);112 ShellCommand* setAlias(const char* alias);113 ShellCommand* defaultValues(unsigned int count, ...);114 115 static ShellCommand* registerCommand(const char* commandName, const char* className, Executor* executor);116 117 static void unregisterCommand(const char* commandName, const char* className);118 119 static void debug();120 121 protected:122 ShellCommand(const char* commandName, const char* className, Executor* executor);123 ~ShellCommand();124 125 /** @returns the Type of this Function (either static or objective) */126 inline ShellCommand_Type getType() { return this->functorType; };127 128 static bool isRegistered(const char* commandName, const char* className, Executor* executor);129 static const char* paramToString(long parameter);130 131 protected:132 ShellCommand_Type functorType; //!< The type of Function we've got (either static or objective).133 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )134 unsigned int paramCount; //!< the count of parameters.135 unsigned int* parameters; //!< Parameters the function of this Command takes.136 MultiType* defaultValue; //!< Default Values.137 138 private:139 ShellCommandClass* shellClass; //!< A Pointer to the Shell-Class this Command belongs to.140 ShellCommandAlias* alias; //!< An Alias for the Class.141 142 const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");143 Executor* executor;144 145 };146 147 //! A Class, that handles aliases.148 class ShellCommandAlias149 {150 friend class ShellCommand;151 public:152 /** @returns the Name of the Alias. */153 const char* getName() const { return this->aliasName; };154 /** @returns the Command, this Alias is asociated with */155 ShellCommand* getCommand() const { return this->command; };156 157 private:158 /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */159 ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };160 161 private:162 const char* aliasName; //!< the name of the Alias163 ShellCommand* command; //!< a pointer to the command, this alias executes.164 };165 166 52 #endif /* _SHELL_COMMAND_H */ -
trunk/src/lib/shell/shell_completion.cc
r5406 r5639 17 17 18 18 #include "shell_completion.h" 19 #include "shell_command_class.h" 19 20 20 21 #include "shell_input.h" -
trunk/src/lib/shell/shell_input.cc
r5636 r5639 21 21 22 22 #include "shell_command.h" 23 #include "shell_command_class.h" 23 24 #include "shell_completion.h" 24 25 #include "event_handler.h"
Note: See TracChangeset
for help on using the changeset viewer.