[4838] | 1 | /*! |
---|
[5129] | 2 | * @file shell_command.h |
---|
[5068] | 3 | * Definition of a on-screen-shell |
---|
[3245] | 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" |
---|
[5143] | 12 | #include "functor_list.h" |
---|
[5141] | 13 | |
---|
[5068] | 14 | #include <stdarg.h> |
---|
| 15 | |
---|
[5130] | 16 | #define MAX_SHELL_COMMAND_SIZE |
---|
| 17 | |
---|
[5127] | 18 | |
---|
[5130] | 19 | |
---|
[4838] | 20 | // FORWARD DECLARATION |
---|
[5068] | 21 | template<class T> class tList; |
---|
[3543] | 22 | |
---|
[5135] | 23 | |
---|
| 24 | /////////////////////// |
---|
| 25 | // MACRO DEFINITIONS // |
---|
| 26 | /////////////////////// |
---|
| 27 | |
---|
[5142] | 28 | // COMMAND REGISTRATION |
---|
| 29 | // NO ARGUMENTS |
---|
| 30 | #define ShellCommandRegister0 \ |
---|
| 31 | static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \ |
---|
| 32 | { \ |
---|
| 33 | if (isRegistered(commandName, classID, 0)== true) \ |
---|
| 34 | return; \ |
---|
| 35 | new ShellCommand<T>(commandName, classID, functionPointer); \ |
---|
| 36 | } |
---|
[5135] | 37 | |
---|
[5142] | 38 | |
---|
| 39 | #define ShellCommandConstructor0 \ |
---|
| 40 | void (T::*functionPointer_NULL)(); \ |
---|
| 41 | ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \ |
---|
| 42 | : ShellCommandBase (commandName, classID, 0) \ |
---|
[5135] | 43 | { \ |
---|
[5142] | 44 | this->functionPointer_NULL = functionPointer; \ |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | #define ShellCommandRegister2(t1, t2) \ |
---|
| 51 | static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \ |
---|
| 52 | t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \ |
---|
| 53 | { \ |
---|
| 54 | if (isRegistered(commandName, classID, 2, t1##_PARAM, t2##_PARAM) == true) \ |
---|
[5135] | 55 | return; \ |
---|
| 56 | else \ |
---|
| 57 | ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \ |
---|
[5142] | 58 | } |
---|
| 59 | |
---|
| 60 | // CONSTRUCTORS AND POINTERS |
---|
| 61 | #define ShellCommandConstructor2(t1, t2) \ |
---|
| 62 | void (T::*functionPointer_##t1_##t2)(t1##_TYPE, t2##_TYPE); \ |
---|
| 63 | ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \ |
---|
| 64 | t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \ |
---|
[5135] | 65 | { \ |
---|
[5142] | 66 | this->functionPointer_##t1_##t2 = function; \ |
---|
[5135] | 67 | } |
---|
| 68 | |
---|
[5142] | 69 | //#define ShellCommand |
---|
[5135] | 70 | |
---|
[5141] | 71 | |
---|
[5135] | 72 | //////////////// |
---|
| 73 | // BASE CLASS // |
---|
| 74 | //////////////// |
---|
| 75 | //! a baseClass for all possible ShellCommands |
---|
[5130] | 76 | class ShellCommandBase : public BaseObject |
---|
[5129] | 77 | { |
---|
[5068] | 78 | public: |
---|
[5129] | 79 | static bool execute (const char* executionString); |
---|
[2036] | 80 | |
---|
[5141] | 81 | static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; }; |
---|
[5130] | 82 | |
---|
[5141] | 83 | |
---|
[5129] | 84 | protected: |
---|
[5135] | 85 | ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...); |
---|
[5130] | 86 | ~ShellCommandBase(); |
---|
[1853] | 87 | |
---|
[5135] | 88 | static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...); |
---|
[1853] | 89 | |
---|
[5141] | 90 | private: |
---|
[5142] | 91 | virtual void executeCommand (BaseObject* object, const char* parameters) = NULL; |
---|
[5141] | 92 | |
---|
[5130] | 93 | protected: |
---|
| 94 | void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) |
---|
| 95 | unsigned int paramCount; //!< the count of parameters |
---|
[5143] | 96 | long* parameters; //!< Parameters |
---|
[5140] | 97 | bool isSingleton; //!< if the Class is Singleton @todo autocheck |
---|
[5130] | 98 | |
---|
[5129] | 99 | private: |
---|
[5141] | 100 | long classID; //!< The ID of the Class associated to this Command |
---|
| 101 | const char* className; //!< The Name of the Class associated to this Command |
---|
[3245] | 102 | |
---|
[5142] | 103 | char* defaultStrings[FUNCTOR_MAX_ARGUMENTS]; |
---|
| 104 | int defaultInts[FUNCTOR_MAX_ARGUMENTS]; |
---|
| 105 | float defaultFloats[FUNCTOR_MAX_ARGUMENTS]; |
---|
| 106 | bool defaultBools[FUNCTOR_MAX_ARGUMENTS]; |
---|
| 107 | |
---|
| 108 | |
---|
[5130] | 109 | // STATIC MEMBERS |
---|
[5129] | 110 | static tList<ShellCommandBase>* commandList; //!< A list of availiable commands. |
---|
| 111 | }; |
---|
[5068] | 112 | |
---|
[5136] | 113 | template<class T> class ShellCommand; |
---|
[5142] | 114 | /* |
---|
[5136] | 115 | template<class T> class ShellCommandSingleton : public ShellCommandBase |
---|
| 116 | { |
---|
| 117 | friend class ShellCommand<T>; |
---|
| 118 | private: |
---|
| 119 | ShellCommandSingleton(const char* commandName, ClassID classID, void (T::*functionPointer)()) |
---|
| 120 | : ShellCommandBase (commandName, classID, 0) |
---|
| 121 | { |
---|
| 122 | this->functionPointer_NULL = functionPointer; |
---|
| 123 | } |
---|
| 124 | void (T::*functionPointer_NULL)(); |
---|
[5142] | 125 | |
---|
[5136] | 126 | virtual void executeCommand (const char* parameters) |
---|
| 127 | { |
---|
| 128 | if (this->paramCount == 0) |
---|
| 129 | (T::getInstance()->*functionPointer_NULL)(); |
---|
| 130 | } |
---|
[5142] | 131 | };*/ |
---|
[5135] | 132 | |
---|
[5136] | 133 | |
---|
[5129] | 134 | //! keeps information about a ShellCommand |
---|
| 135 | template<class T> class ShellCommand : public ShellCommandBase |
---|
| 136 | { |
---|
| 137 | public: |
---|
| 138 | static void unregisterCommand(const char* commandNaame, ClassID classID); |
---|
[5068] | 139 | |
---|
[5142] | 140 | #define FUNCTOR_LIST(x) ShellCommandRegister ## x |
---|
| 141 | //#include "functor_list.h" |
---|
| 142 | FUNCTOR_LIST(0); |
---|
| 143 | #undef FUNCTOR_LIST |
---|
[5136] | 144 | |
---|
[5142] | 145 | |
---|
[5068] | 146 | private: |
---|
[5142] | 147 | #define FUNCTOR_LIST(x) ShellCommandConstructor ## x |
---|
| 148 | //#include "functor_list.h" |
---|
| 149 | FUNCTOR_LIST(0); |
---|
| 150 | #undef FUNCTOR_LIST |
---|
| 151 | |
---|
| 152 | virtual void executeCommand (BaseObject* object, const char* parameters) |
---|
[5135] | 153 | { |
---|
[5142] | 154 | printf("not implemented yet\n"); |
---|
| 155 | if (this->paramCount == 0) |
---|
| 156 | (dynamic_cast<T*>(object)->*functionPointer_NULL)(); |
---|
[5135] | 157 | } |
---|
[5068] | 158 | |
---|
| 159 | |
---|
[5135] | 160 | |
---|
| 161 | #define FUNCTOR_LIST(x) ShellCommand ## x |
---|
| 162 | //#include "functor_list.h" |
---|
[5141] | 163 | //FUNCTOR_LIST(2)(l_INT, l_INT); |
---|
[5135] | 164 | #undef FUNCTOR_LIST |
---|
| 165 | |
---|
[5129] | 166 | }; |
---|
[5113] | 167 | |
---|
| 168 | |
---|
[5120] | 169 | |
---|
[5129] | 170 | #endif /* _SHELL_COMMAND_H */ |
---|