[4838] | 1 | /*! |
---|
[5129] | 2 | * @file shell_command.h |
---|
[5068] | 3 | * Definition of a on-screen-shell |
---|
[5391] | 4 | */ |
---|
[1853] | 5 | |
---|
[5129] | 6 | #ifndef _SHELL_COMMAND_H |
---|
| 7 | #define _SHELL_COMMAND_H |
---|
[1853] | 8 | |
---|
[5129] | 9 | #include "base_object.h" |
---|
[1853] | 10 | |
---|
[5141] | 11 | #include "helper_functions.h" |
---|
[5552] | 12 | #include "multi_type.h" |
---|
[5155] | 13 | #include "substring.h" |
---|
[5143] | 14 | #include "functor_list.h" |
---|
[5636] | 15 | #include "executor/executor.h" |
---|
[5068] | 16 | #include <stdarg.h> |
---|
| 17 | |
---|
[5166] | 18 | #define SHELL_COMMAND_MAX_SIZE //!< The maximum size of a Shell Command |
---|
[5130] | 19 | |
---|
[5127] | 20 | |
---|
[5130] | 21 | |
---|
[4838] | 22 | // FORWARD DECLARATION |
---|
[5068] | 23 | template<class T> class tList; |
---|
[5639] | 24 | class ShellCommandClass; |
---|
| 25 | class ShellCommandAlias; |
---|
[3543] | 26 | |
---|
[5166] | 27 | /** |
---|
| 28 | * an easy to use Macro to create a Command |
---|
| 29 | * @param command the name of the command (without "" around the string) |
---|
| 30 | * @param class the name of the class to apply this command to (without the "" around the string) |
---|
| 31 | * @param function the function to call |
---|
[5179] | 32 | * |
---|
| 33 | * MEANING: |
---|
[5636] | 34 | * ShellCommand* someUniqueVarName = |
---|
[5179] | 35 | * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall); |
---|
| 36 | * |
---|
| 37 | * In the Shell you would call this Command using: |
---|
| 38 | * $ ClassName [ObjectName] commandNameInShell [parameters] |
---|
[5166] | 39 | */ |
---|
[5636] | 40 | //#define SHELL_COMMAND(command, class, function) \ |
---|
| 41 | // ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function) |
---|
[5162] | 42 | #define SHELL_COMMAND(command, class, function) \ |
---|
[5636] | 43 | ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorObjective<class>(&class::function)) |
---|
| 44 | |
---|
[5329] | 45 | /** |
---|
| 46 | * an easy to use Macro to create a Command |
---|
| 47 | * @param command the name of the command (without "" around the string) |
---|
| 48 | * @param class the name of the class to apply this command to (without the "" around the string) |
---|
| 49 | * @param function the function to call |
---|
| 50 | * |
---|
| 51 | * MEANING: |
---|
[5636] | 52 | * ShellCommand* someUniqueVarName = |
---|
[5329] | 53 | * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall); |
---|
| 54 | * |
---|
| 55 | * In the Shell you would call this Command using: |
---|
| 56 | * $ ClassName [ObjectName] commandNameInShell [parameters] |
---|
| 57 | */ |
---|
| 58 | #define SHELL_COMMAND_STATIC(command, class, function) \ |
---|
[5636] | 59 | ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorStatic<class>(function)) |
---|
[5135] | 60 | |
---|
[5162] | 61 | |
---|
[5328] | 62 | |
---|
[5161] | 63 | //! a baseClass for all possible ShellCommands |
---|
[5636] | 64 | class ShellCommand : public BaseObject |
---|
[5161] | 65 | { |
---|
[5170] | 66 | friend class ShellCommandClass; |
---|
[5161] | 67 | public: |
---|
| 68 | static bool execute (const char* executionString); |
---|
| 69 | |
---|
[5636] | 70 | ShellCommand* describe(const char* description); |
---|
| 71 | ShellCommand* setAlias(const char* alias); |
---|
| 72 | ShellCommand* defaultValues(unsigned int count, ...); |
---|
[5164] | 73 | |
---|
[5636] | 74 | static ShellCommand* registerCommand(const char* commandName, const char* className, Executor* executor); |
---|
| 75 | |
---|
[5166] | 76 | static void unregisterCommand(const char* commandName, const char* className); |
---|
[5161] | 77 | |
---|
| 78 | static void debug(); |
---|
| 79 | |
---|
| 80 | protected: |
---|
[5637] | 81 | ShellCommand(const char* commandName, const char* className, Executor* executor); |
---|
[5636] | 82 | ~ShellCommand(); |
---|
[5161] | 83 | |
---|
[5637] | 84 | static bool isRegistered(const char* commandName, const char* className, Executor* executor); |
---|
[5161] | 85 | static const char* paramToString(long parameter); |
---|
| 86 | |
---|
| 87 | protected: |
---|
[5163] | 88 | void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) |
---|
[5166] | 89 | unsigned int paramCount; //!< the count of parameters. |
---|
| 90 | unsigned int* parameters; //!< Parameters the function of this Command takes. |
---|
[5552] | 91 | MultiType* defaultValue; //!< Default Values. |
---|
[5161] | 92 | |
---|
| 93 | private: |
---|
[5170] | 94 | ShellCommandClass* shellClass; //!< A Pointer to the Shell-Class this Command belongs to. |
---|
[5196] | 95 | ShellCommandAlias* alias; //!< An Alias for the Class. |
---|
[5161] | 96 | |
---|
[5166] | 97 | const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla"); |
---|
[5636] | 98 | Executor* executor; |
---|
[5161] | 99 | |
---|
[5129] | 100 | }; |
---|
[5113] | 101 | |
---|
[5197] | 102 | //! A Class, that handles aliases. |
---|
[5190] | 103 | class ShellCommandAlias |
---|
| 104 | { |
---|
[5636] | 105 | friend class ShellCommand; |
---|
[5190] | 106 | public: |
---|
[5197] | 107 | /** @returns the Name of the Alias. */ |
---|
[5195] | 108 | const char* getName() const { return this->aliasName; }; |
---|
[5197] | 109 | /** @returns the Command, this Alias is asociated with */ |
---|
[5636] | 110 | ShellCommand* getCommand() const { return this->command; }; |
---|
[5196] | 111 | |
---|
[5190] | 112 | private: |
---|
[5197] | 113 | /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */ |
---|
[5636] | 114 | ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; }; |
---|
[5196] | 115 | |
---|
| 116 | private: |
---|
[5197] | 117 | const char* aliasName; //!< the name of the Alias |
---|
[5636] | 118 | ShellCommand* command; //!< a pointer to the command, this alias executes. |
---|
[5190] | 119 | }; |
---|
| 120 | |
---|
[5129] | 121 | #endif /* _SHELL_COMMAND_H */ |
---|