00001 #ifndef __COMMANDPROCESSOR_H 00002 #define __COMMANDPROCESSOR_H 00003 00004 #include <pthread.h> 00005 #include <string> 00006 #include <vector> 00007 00008 #include "Command.h" 00009 #include "CommandParser.h" 00010 00011 class CommandProcessor : public BasicObject { 00012 public: 00013 CommandProcessor(); 00014 virtual ~CommandProcessor() {} 00015 void processCommands(); 00016 void setParser(CommandParser* parser); 00017 void startThread(); 00018 virtual void stopThread(); 00019 std::vector<Command*> getCommandList(); 00020 virtual void toStream(std::ostream& out); 00021 Command* matchCommand(std::string command); 00022 void addCommand(Command* command); 00023 00024 protected: 00025 virtual void init(); 00026 virtual void readCommand(std::string* input) = 0; 00027 virtual void displayResponse(std::string* output) = 0; 00028 virtual void generateError(std::string* input, std::ostream& output); 00029 00030 private: 00031 static void* daemonThread(void*); 00032 CommandParser* m_parser; 00033 pthread_t m_daemonThreadId; 00034 int m_commandsProcessed; 00035 std::vector<Command*> m_commandList; 00036 }; 00037 00038 #endif 00039