00001 00033 #ifndef LLCOMMANDHANDLER_H 00034 #define LLCOMMANDHANDLER_H 00035 00036 /* To implement a command "foo" that takes one parameter, 00037 a UUID, do this: 00038 00039 class LLFooHandler : public LLCommandHandler 00040 { 00041 public: 00042 // Inform the system you handle commands starting 00043 // with "foo" 00044 LLFooHandler() : LLCommandHandler("foo") { } 00045 00046 // Your code here 00047 bool handle(const std::vector<std::string>& tokens) 00048 { 00049 if (tokens.size() < 1) return false; 00050 LLUUID id( tokens[0] ); 00051 return doFoo(id); 00052 } 00053 }; 00054 00055 // Creating the object registers with the dispatcher. 00056 LLFooHandler gFooHandler; 00057 */ 00058 00059 class LLCommandHandler 00060 { 00061 public: 00062 LLCommandHandler(const char* command); 00063 // Automatically registers object to get called when 00064 // command is executed. 00065 00066 virtual ~LLCommandHandler(); 00067 00068 virtual bool handle(const std::vector<std::string>& params) = 0; 00069 // Execute the command with a provided (possibly empty) 00070 // list of parameters. 00071 // Return true if you did something, false if the parameters 00072 // are invalid or on error. 00073 }; 00074 00075 00076 class LLCommandDispatcher 00077 { 00078 public: 00079 static bool dispatch(const std::string& cmd, const std::vector<std::string>& params); 00080 // Execute a command registered via the above mechanism, 00081 // passing string parameters. 00082 // Returns true if command was found and executed correctly. 00083 }; 00084 00085 #endif