Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

CommandProcessor Class Reference

Uses the Template Method design pattern from "Design Patterns". More...

#include <CommandProcessor.h>

Inheritance diagram for CommandProcessor::

BasicObject FileHandleCommandProcessor HttpTestCommandProcessor ProxyCommandProcessor List of all members.

Public Methods

 CommandProcessor ()
virtual ~CommandProcessor ()
void processCommands ()
 The template method. More...

void setParser (CommandParser *parser)
void startThread ()
 Call this function to start the processor thread. More...

virtual void stopThread ()
std::vector< Command *> getCommandList ()
virtual void toStream (std::ostream &out)
CommandmatchCommand (std::string command)
 Match a command string to its command object. More...

void addCommand (Command *command)
 Add a command to internal command list. More...


Protected Methods

virtual void init ()
 Subclasses can override this to do their own initialization if they need to. More...

virtual void readCommand (std::string *input)=0
virtual void displayResponse (std::string *output)=0
virtual void generateError (std::string *input, std::ostream &output)

Static Private Methods

void * daemonThread (void *)

Private Attributes

CommandParserm_parser
pthread_t m_daemonThreadId
int m_commandsProcessed
std::vector< Command *> m_commandList

Detailed Description

Uses the Template Method design pattern from "Design Patterns".

The "processCommands" function is the Template Method. Subclasses must override readCommand() and displayResponse(), and optionally init().

To add a new command to the command processor, define a subclass of Command, and make sure to override the pure virtual functions. Then, add the command in the setParser function inside of CommandProcessor. Then you are done.

Definition at line 11 of file CommandProcessor.h.


Constructor & Destructor Documentation

CommandProcessor::CommandProcessor
 

Definition at line 15 of file CommandProcessor.cpp.

virtual CommandProcessor::~CommandProcessor [inline, virtual]
 

Definition at line 14 of file CommandProcessor.h.


Member Function Documentation

void CommandProcessor::addCommand Command * command
 

Add a command to internal command list.

Definition at line 63 of file CommandProcessor.cpp.

Referenced by GlobalObjects::init(), and GlobalObjects::initializeCommands().

void * CommandProcessor::daemonThread void * processorPtr [static, private]
 

Definition at line 43 of file CommandProcessor.cpp.

virtual void CommandProcessor::displayResponse std::string * output [protected, pure virtual]
 

Reimplemented in FileHandleCommandProcessor, HttpTestCommandProcessor, and ProxyCommandProcessor.

Referenced by processCommands().

void CommandProcessor::generateError std::string * input,
std::ostream & output
[protected, virtual]
 

Reimplemented in ProxyCommandProcessor.

Definition at line 138 of file CommandProcessor.cpp.

Referenced by processCommands().

vector< Command *> CommandProcessor::getCommandList
 

Definition at line 132 of file CommandProcessor.cpp.

void CommandProcessor::init [protected, virtual]
 

Subclasses can override this to do their own initialization if they need to.

Reimplemented in FileHandleCommandProcessor.

Definition at line 96 of file CommandProcessor.cpp.

Referenced by processCommands().

Command * CommandProcessor::matchCommand std::string command
 

Match a command string to its command object.

Todo:
This is hacked to clear the command as well to erase any old arguments it might have had. fix this hack.

Definition at line 76 of file CommandProcessor.cpp.

void CommandProcessor::processCommands
 

The template method.

Reads in commands, parses them, executes them, and then displays the output.

Definition at line 105 of file CommandProcessor.cpp.

Referenced by daemonThread().

virtual void CommandProcessor::readCommand std::string * input [protected, pure virtual]
 

Reimplemented in FileHandleCommandProcessor, HttpTestCommandProcessor, and ProxyCommandProcessor.

Referenced by processCommands().

void CommandProcessor::setParser CommandParser * parser
 

Definition at line 54 of file CommandProcessor.cpp.

Referenced by CommandProcessor(), and GlobalObjects::init().

void CommandProcessor::startThread
 

Call this function to start the processor thread.

Definition at line 25 of file CommandProcessor.cpp.

Referenced by GlobalObjects::init().

void CommandProcessor::stopThread [virtual]
 

Reimplemented in HttpTestCommandProcessor, and ProxyCommandProcessor.

Definition at line 34 of file CommandProcessor.cpp.

Referenced by ProxyCommandProcessor::stopThread(), and HttpTestCommandProcessor::stopThread().

void CommandProcessor::toStream std::ostream & out [virtual]
 

Reimplemented from BasicObject.

Reimplemented in HttpTestCommandProcessor, and ProxyCommandProcessor.

Definition at line 144 of file CommandProcessor.cpp.

Referenced by ProxyCommandProcessor::toStream(), and HttpTestCommandProcessor::toStream().


Member Data Documentation

std::vector<Command*> CommandProcessor::m_commandList [private]
 

Definition at line 35 of file CommandProcessor.h.

int CommandProcessor::m_commandsProcessed [private]
 

Definition at line 34 of file CommandProcessor.h.

pthread_t CommandProcessor::m_daemonThreadId [private]
 

Definition at line 33 of file CommandProcessor.h.

CommandParser* CommandProcessor::m_parser [private]
 

Definition at line 32 of file CommandProcessor.h.


The documentation for this class was generated from the following files:
Generated at Thu Jul 11 13:31:56 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001