/*! * @file shell_command.h * Definition of a on-screen-shell */ #ifndef _SHELL_COMMAND_H #define _SHELL_COMMAND_H #include "base_object.h" #include "helper_functions.h" #include "multi_type.h" #include "substring.h" #include "functor_list.h" #include "executor/executor.h" #include #define SHELL_COMMAND_MAX_SIZE //!< The maximum size of a Shell Command // FORWARD DECLARATION template class tList; class ShellCommandClass; class ShellCommandAlias; /** * an easy to use Macro to create a Command * @param command the name of the command (without "" around the string) * @param class the name of the class to apply this command to (without the "" around the string) * @param function the function to call * * MEANING: * ShellCommand* someUniqueVarName = * ShellCommand::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall); * * In the Shell you would call this Command using: * $ ClassName [ObjectName] commandNameInShell [parameters] */ //#define SHELL_COMMAND(command, class, function) \ // ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, &class::function) #define SHELL_COMMAND(command, class, function) \ ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorObjective(&class::function)) /** * an easy to use Macro to create a Command * @param command the name of the command (without "" around the string) * @param class the name of the class to apply this command to (without the "" around the string) * @param function the function to call * * MEANING: * ShellCommand* someUniqueVarName = * ShellCommand::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall); * * In the Shell you would call this Command using: * $ ClassName [ObjectName] commandNameInShell [parameters] */ #define SHELL_COMMAND_STATIC(command, class, function) \ ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorStatic(function)) //! a baseClass for all possible ShellCommands class ShellCommand : public BaseObject { friend class ShellCommandClass; public: static bool execute (const char* executionString); ShellCommand* describe(const char* description); ShellCommand* setAlias(const char* alias); ShellCommand* defaultValues(unsigned int count, ...); static ShellCommand* registerCommand(const char* commandName, const char* className, const Executor& executor); static void unregisterCommand(const char* commandName, const char* className); static void debug(); protected: ShellCommand(const char* commandName, const char* className, const Executor& executor); ~ShellCommand(); static bool isRegistered(const char* commandName, const char* className, const Executor& executor); static const char* paramToString(long parameter); protected: MultiType* defaultValue; //!< Default Values. private: ShellCommandClass* shellClass; //!< A Pointer to the Shell-Class this Command belongs to. ShellCommandAlias* alias; //!< An Alias for the Class. const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla"); Executor* executor; //!< The Executor, that really executes the Function. }; //! A Class, that handles aliases. class ShellCommandAlias { friend class ShellCommand; public: /** @returns the Name of the Alias. */ const char* getName() const { return this->aliasName; }; /** @returns the Command, this Alias is asociated with */ ShellCommand* getCommand() const { return this->command; }; private: /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */ ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; }; private: const char* aliasName; //!< the name of the Alias ShellCommand* command; //!< a pointer to the command, this alias executes. }; #endif /* _SHELL_COMMAND_H */