Commander Class Reference

Processor of server commands. More...

#include <commander.h>

Inherits Task.

Inherited by CommanderClient, and CommanderServer.

Inheritance diagram for Commander:

Inheritance graph
[legend]
Collaboration diagram for Commander:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Commander ()
virtual ~Commander ()
void addCommand (const std::string &command, int playerID=-1)
 Add command to command queues.
void processAllCommands ()
 Process all commands in queue.
virtual void update (int atime)
 Equal to processAllCommands().

Protected Types

typedef Commander::sCommand sCommand
 Mutex for commands queueHolds info abou one message in queue.

Protected Member Functions

virtual void processCommand (const std::string &command, int playerID)=0
 Process one command.

Protected Attributes

Mutex mQueueMutex
std::list< sCommandmCommQueue
 Queue of commands that are waiting for processing.

Classes

struct  sCommand
 Mutex for commands queueHolds info abou one message in queue. More...

Detailed Description

Processor of server commands.

Accepts users commands from console and from network. Inherits from Task so you may put it in task manager. The commander needs regular processAllCommands(); call or update call will do the same job.

Definition at line 22 of file commander.h.


Member Typedef Documentation

typedef struct Commander::sCommand Commander::sCommand [protected]
 

Mutex for commands queueHolds info abou one message in queue.


Constructor & Destructor Documentation

Commander::Commander  )  [inline]
 

Definition at line 25 of file commander.h.

virtual Commander::~Commander  )  [inline, virtual]
 

Definition at line 26 of file commander.h.


Member Function Documentation

void Commander::addCommand const std::string &  command,
int  playerID = -1
 

Add command to command queues.

The command will be processed later in main thread. This function is thread safe. Add one element to mCommQueue. Command will be processed in processAllCommands() call.

Parameters:
command string containing command that contains the command and it arguments (if any)
playerID ID of player who created this command. You don't have to set it on client side - it will be set automaticly in receiver of commands on server. Value -1 is invalid value and indicates unknown source like internal command or command from server console. The ID is used when command provide some output so we need to send it back to player who created it.

Definition at line 8 of file commander.cpp.

References Mutex::lock(), mCommQueue, mQueueMutex, and Mutex::unlock().

Referenced by Console::processCommand(), and ConsoleText::run().

Here is the call graph for this function:

void Commander::processAllCommands  ) 
 

Process all commands in queue.

This should be regullary called from main thread. Simplye emty mCommQueue and call processCommand on every member if the list.

Definition at line 19 of file commander.cpp.

References Commander::sCommand::command, Mutex::lock(), mCommQueue, mQueueMutex, Commander::sCommand::playerID, processCommand(), and Mutex::unlock().

Referenced by GameClient::run(), and update().

Here is the call graph for this function:

virtual void Commander::processCommand const std::string &  command,
int  playerID
[protected, pure virtual]
 

Process one command.

This function will be called in main task. Should process the command.

Parameters:
command string with command
playerID ID of player who created the command

Implemented in CommanderClient, and CommanderServer.

Referenced by processAllCommands().

void Commander::update int  atime  )  [virtual]
 

Equal to processAllCommands().

This fucntion is here if you need to put commander in task manager.

Reimplemented from Task.

Definition at line 40 of file commander.cpp.

References processAllCommands().

Here is the call graph for this function:


Member Data Documentation

std::list<sCommand> Commander::mCommQueue [protected]
 

Queue of commands that are waiting for processing.

Use mQueueMutex when accessing the.

Definition at line 96 of file commander.h.

Referenced by addCommand(), and processAllCommands().

Mutex Commander::mQueueMutex [protected]
 

Definition at line 74 of file commander.h.

Referenced by addCommand(), and processAllCommands().


The documentation for this class was generated from the following files:
Generated on Wed Apr 12 14:12:44 2006 for bjs by  doxygen 1.4.5