1 /* 2 * Copyright 2007, Ingo Weinhold, bonefish@cs.tu-berlin.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _FSSH_FSSH_H 6 #define _FSSH_FSSH_H 7 8 #include "compatibility.h" 9 10 #include <map> 11 #include <string> 12 13 #include "fssh_defs.h" 14 15 16 typedef fssh_status_t command_function(int argc, const char* const* argv); 17 18 19 namespace FSShell { 20 21 22 enum { 23 COMMAND_RESULT_EXIT = 1, 24 }; 25 26 27 // Command 28 class Command { 29 public: 30 Command(const char* name, 31 const char* description); 32 Command(command_function* function, 33 const char* name, const char* description); 34 virtual ~Command(); 35 36 const char* Name() const; 37 const char* Description() const; 38 39 virtual fssh_status_t Do(int argc, const char* const* argv); 40 41 private: 42 std::string fName; 43 std::string fDescription; 44 command_function* fFunction; 45 }; 46 47 48 // CommandManager 49 class CommandManager { 50 private: 51 CommandManager(); 52 53 public: 54 static CommandManager* Default(); 55 56 void AddCommand(Command* command); 57 void AddCommand(command_function* function, 58 const char* name, const char* description); 59 void AddCommands(command_function* function, 60 const char* name, const char* description, 61 ...); 62 Command* FindCommand(const char* name) const; 63 void ListCommands() const; 64 65 private: 66 typedef std::map<std::string, Command*> CommandMap; 67 68 CommandMap fCommands; 69 70 static CommandManager* sManager; 71 }; 72 73 74 } // namespace FSShell 75 76 77 #endif // _FSSH_FSSH_H 78