Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ActHandler Class Reference

#include <ActHandler.h>

Collaboration diagram for ActHandler:

Collaboration graph
[legend]
List of all members.

Public Methods

 ActHandler (Connection *c, WorldModel *wm, ServerSettings *ss)
bool putCommandInQueue (SoccerCommand command)
void emptyQueue ()
bool isQueueEmpty ()
bool sendCommands ()
bool sendCommand (SoccerCommand soc)
bool sendMessage (char *str)
bool sendCommandDirect (SoccerCommand soc)
bool sendMessageDirect (char *str)

Private Attributes

Connectionconnection
ServerSettingsSS
WorldModelWM
SoccerCommand m_queueOneCycleCommand
SoccerCommand m_queueMultipleCommands [MAX_COMMANDS]
int m_iMultipleCommands

Detailed Description

The ActHandler Class is used in the RoboCup Soccer environment to send the commands to the soccerserver. The ActHandler contains a queue in which the commands are put. When a signal arrives (set by the SenseHandler depending on the time of the sense_body message) the commands that are currently in the queue are converted to text strings and send to the server. The sent commands are also passed to the WorldModel, such that the WorldModel can update its internal state based on the performed actions. It is possible to send more than one command to the server at each time step, but some type of (primary) commands can only be sent once (kick,dash, move, turn and catch). Therefore internally two queues are stored. One with only one element,namely the last entered primary command. And the other with all the other commands. Each time a command is put into the queue that is already there, the command is updated with the new information. Furthermore it is also possible to directly send commands (or text strings) to the server. These methods can be used when an initialization or move command has to be sent to the server and you're sure this information is final, i.e. the message will not become better when new information arrives from the server.

Definition at line 75 of file ActHandler.h.


Constructor & Destructor Documentation

ActHandler::ActHandler Connection   c,
WorldModel   wm,
ServerSettings   ss
 

This is the constructor for the ActHandler class. All the variables are initialized.

Parameters:
c  Connection that is connected with the soccerserver
wm  WorldModel, used to set performed commands
ss  ServerSettings in which server settings are defined

Definition at line 67 of file ActHandler.C.

References connection, m_iMultipleCommands, SS, and WM.


Member Function Documentation

void ActHandler::emptyQueue  
 

This method empties the queue in which all the commands are stored.

Definition at line 78 of file ActHandler.C.

References CMD_ILLEGAL, SoccerCommand::commandType, m_iMultipleCommands, m_queueMultipleCommands, m_queueOneCycleCommand, and MAX_COMMANDS.

Referenced by sendMessage().

bool ActHandler::isQueueEmpty  
 

This method returns whether the current queue contains no commands

Returns:
true when queue is empty, false otherwise

Definition at line 88 of file ActHandler.C.

References CMD_ILLEGAL, SoccerCommand::commandType, m_iMultipleCommands, and m_queueOneCycleCommand.

bool ActHandler::putCommandInQueue SoccerCommand    command
 

This method puts a SoccerCommand in the queue. The last added command will be sent to the soccerserver when the method sendCommands is performed. Normally this is done when a signal set by the SenseHandler arrives.

Parameters:
command  SoccerCommand that should be put in the queue.
Returns:
true when command is added, false otherwise (queue is full)

Definition at line 168 of file ActHandler.C.

References CMD_ILLEGAL, SoccerCommand::commandType, SoccerTypes::isPrimaryCommand(), m_iMultipleCommands, m_queueMultipleCommands, m_queueOneCycleCommand, and MAX_COMMANDS.

Referenced by Player::deMeer5(), Player::deMeer5_goalie(), Player::executeStringCommand(), and BasicPlayer::turnWithBallTo().

bool ActHandler::sendCommand SoccerCommand    soc
 

This method sends a single command directly to the server. First a string is made from the SoccerCommand and afterwards this string is send to the server using the method sendMessage.

Parameters:
soc  SoccerCommand that should be send to the server.
Returns:
true when message was sent, false otherwise

Definition at line 204 of file ActHandler.C.

References SoccerCommand::getCommandString(), MAX_MSG, sendMessage(), and SS.

bool ActHandler::sendCommandDirect SoccerCommand    soc
 

This method sends a single command directly to the server. First a string is made from the SoccerCommand and afterwards this string is send to the server using the method sendMessageDirect.

Parameters:
soc  SoccerCommand that should be send to the server.
Returns:
true when message was sent, false otherwise

Definition at line 233 of file ActHandler.C.

References SoccerCommand::getCommandString(), MAX_MSG, sendMessageDirect(), and SS.

Referenced by Player::mainLoop().

bool ActHandler::sendCommands  
 

This method converts all commands in the queue to text strings and sends these text strings to the server (connected by Connection). When the server didn't execute the commands from the previous cycle (this information is stored in the WorldModel) the commands in the queue are not sent, since it is probably the case that these commands will be performed this cycle and we don't want a clash (two commands in one cycle). In this case false is returned.

Returns:
true when sending of messages succeeded, false otherwise

Definition at line 102 of file ActHandler.C.

References CMD_CATCH, CMD_ILLEGAL, SoccerCommand::commandType, connection, SoccerCommand::getCommandString(), WorldModel::getCurrentTime(), WorldModel::isQueuedActionPerformed(), SoccerCommand::iTimes, m_iMultipleCommands, m_queueMultipleCommands, m_queueOneCycleCommand, MAX_COMMANDS, MAX_MSG, WorldModel::processQueuedCommands(), Connection::sendMessage(), SS, and WM.

Referenced by Player::mainLoop(), and sigalarmHandler().

bool ActHandler::sendMessage char *    str
 

This method sends a single string directly to the server. To make sure this message arrives, the time of one complete cycle is waited before and after the message is sent.

Parameters:
str  string that should be sent to the server
Returns:
true when message was sent, false otherwise

Definition at line 216 of file ActHandler.C.

References connection, emptyQueue(), ServerSettings::getSimulatorStep(), Connection::sendMessage(), and SS.

Referenced by Player::executeStringCommand(), Player::Player(), and sendCommand().

bool ActHandler::sendMessageDirect char *    str
 

This method sends a single string directly to the server.

Parameters:
str  string that should be sent to the server
Returns:
true when message was sent, false otherwise

Definition at line 243 of file ActHandler.C.

References connection, and Connection::sendMessage().

Referenced by sendCommandDirect().


Member Data Documentation

Connection* ActHandler::connection [private]
 

Connection with the server

Definition at line 77 of file ActHandler.h.

Referenced by ActHandler(), sendCommands(), sendMessage(), and sendMessageDirect().

int ActHandler::m_iMultipleCommands [private]
 

number of non-primary commands

Definition at line 83 of file ActHandler.h.

Referenced by ActHandler(), emptyQueue(), isQueueEmpty(), putCommandInQueue(), and sendCommands().

SoccerCommand ActHandler::m_queueMultipleCommands[MAX_COMMANDS] [private]
 

nonprimary commands

Definition at line 82 of file ActHandler.h.

Referenced by emptyQueue(), putCommandInQueue(), and sendCommands().

SoccerCommand ActHandler::m_queueOneCycleCommand [private]
 

primary command is saved here

Definition at line 81 of file ActHandler.h.

Referenced by emptyQueue(), isQueueEmpty(), putCommandInQueue(), and sendCommands().

ServerSettings* ActHandler::SS [private]
 

ServerSettings with server parameters

Definition at line 78 of file ActHandler.h.

Referenced by ActHandler(), sendCommand(), sendCommandDirect(), sendCommands(), and sendMessage().

WorldModel* ActHandler::WM [private]
 

needed to set performed actions

Definition at line 79 of file ActHandler.h.

Referenced by ActHandler(), and sendCommands().


The documentation for this class was generated from the following files:
Generated on Thu Mar 7 00:37:52 2002 for UvA Trilearn 2001 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001