[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 | |
---|
[5068] | 11 | #include <stdarg.h> |
---|
| 12 | |
---|
[5130] | 13 | #define MAX_SHELL_COMMAND_SIZE |
---|
| 14 | |
---|
[5129] | 15 | typedef enum ShellParameterType |
---|
| 16 | { |
---|
| 17 | ShellParameterNull, |
---|
| 18 | ShellParameterChar, |
---|
| 19 | ShellParameterString, |
---|
| 20 | ShellParameterInt, |
---|
| 21 | ShellParameterUInt, |
---|
| 22 | ShellParameterFloat, |
---|
| 23 | /* ... */ |
---|
| 24 | }; |
---|
[5127] | 25 | |
---|
[5130] | 26 | |
---|
[4838] | 27 | // FORWARD DECLARATION |
---|
[5068] | 28 | template<class T> class tList; |
---|
[5118] | 29 | template<class T> class tIterator; |
---|
[3543] | 30 | |
---|
[5130] | 31 | class ShellCommandBase : public BaseObject |
---|
[5129] | 32 | { |
---|
[5068] | 33 | public: |
---|
[5129] | 34 | static bool execute (const char* executionString); |
---|
[2036] | 35 | |
---|
[5130] | 36 | // virtual void execute (...); |
---|
| 37 | |
---|
[5129] | 38 | protected: |
---|
[5130] | 39 | ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters); |
---|
| 40 | ~ShellCommandBase(); |
---|
[1853] | 41 | |
---|
[5130] | 42 | static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters); |
---|
[1853] | 43 | |
---|
[3245] | 44 | |
---|
[5130] | 45 | protected: |
---|
| 46 | void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) |
---|
| 47 | unsigned int paramCount; //!< the count of parameters |
---|
| 48 | ShellParameterType* parameters; //!< Parameters |
---|
| 49 | |
---|
[5129] | 50 | private: |
---|
| 51 | char* commandName; //!< The name of the Command when executed |
---|
| 52 | long classID; //!< The ID of the Class asociated to this Command |
---|
[3245] | 53 | |
---|
[5130] | 54 | // STATIC MEMBERS |
---|
[5129] | 55 | static tList<ShellCommandBase>* commandList; //!< A list of availiable commands. |
---|
| 56 | }; |
---|
[5068] | 57 | |
---|
[5129] | 58 | //! keeps information about a ShellCommand |
---|
| 59 | template<class T> class ShellCommand : public ShellCommandBase |
---|
| 60 | { |
---|
| 61 | public: |
---|
[5130] | 62 | static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...); |
---|
[5069] | 63 | |
---|
[5129] | 64 | static void unregisterCommand(const char* commandNaame, ClassID classID); |
---|
[5068] | 65 | |
---|
| 66 | private: |
---|
[5130] | 67 | ShellCommand(const char* command, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters); |
---|
[5068] | 68 | |
---|
| 69 | |
---|
[5129] | 70 | public: |
---|
[5130] | 71 | T* objectPointer; //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL ) |
---|
[5129] | 72 | }; |
---|
[5113] | 73 | |
---|
[5129] | 74 | template<class T> |
---|
[5130] | 75 | ShellCommand<T>::ShellCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters) |
---|
| 76 | : ShellCommandBase (commandName, classID, functionPointer, paramCount, parameters) |
---|
[5129] | 77 | { |
---|
[5113] | 78 | |
---|
[5129] | 79 | } |
---|
[5120] | 80 | |
---|
[5129] | 81 | template<class T> |
---|
[5130] | 82 | void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...) |
---|
[5129] | 83 | { |
---|
[5130] | 84 | va_list parameters; |
---|
| 85 | va_start(parameters, paramCount); |
---|
| 86 | |
---|
| 87 | if (isRegistered(commandName, classID, paramCount, parameters) == true) |
---|
[5129] | 88 | return; |
---|
| 89 | else |
---|
| 90 | { |
---|
[5068] | 91 | |
---|
[5130] | 92 | // ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, functionPointer, paramCount, parameters); |
---|
[5129] | 93 | } |
---|
| 94 | } |
---|
[5068] | 95 | |
---|
[5129] | 96 | #endif /* _SHELL_COMMAND_H */ |
---|