Main Page   Namespace List   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 ()
SoccerCommand getPrimaryCommand ()
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 [CMD_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, tackle, turn and catch). Therefore internally different queues are stored. One with only one element, namely the last entered primary command. One with all the change_view commands (since these have to be sent at special times for the synchronization). And finally a separate queue containing 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 87 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 79 of file ActHandler.cpp.

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 90 of file ActHandler.cpp.

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

Referenced by sendMessage().

SoccerCommand ActHandler::getPrimaryCommand  
 

This method returns the primary command that is currently stored in the queue.

Definition at line 201 of file ActHandler.cpp.

References m_queueOneCycleCommand.

Referenced by Player::sayBallStatus().

bool ActHandler::isQueueEmpty  
 

This method returns whether the current queue contains no commands

Returns:
true when queue is empty, false otherwise

Definition at line 100 of file ActHandler.cpp.

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 211 of file ActHandler.cpp.

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

Referenced by Player::deMeer5(), Player::deMeer5_goalie(), Player::executeStringCommand(), Player::mainLoop(), and Player::performPenalty().

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 247 of file ActHandler.cpp.

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 284 of file ActHandler.cpp.

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

Referenced by BasicCoach::substitutePlayer().

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 114 of file ActHandler.cpp.

References CMD_CATCH, CMD_ILLEGAL, CMD_MAX_COMMANDS, SoccerCommand::commandType, connection, SoccerCommand::getCommandString(), WorldModel::getCommunicationString(), WorldModel::getCurrentCycle(), WorldModel::getCurrentTime(), WorldModel::getPlayerNumber(), WorldModel::isFullStateOn(), WorldModel::isQueuedActionPerformed(), SoccerCommand::iTimes, m_iMultipleCommands, m_queueMultipleCommands, m_queueOneCycleCommand, MAX_MSG, MAX_SAY_MSG, WorldModel::processQueuedCommands(), Connection::sendMessage(), WorldModel::setCommunicationString(), 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 259 of file ActHandler.cpp.

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

Referenced by BasicCoach::BasicCoach(), Player::executeStringCommand(), BasicCoach::executeStringCommand(), Player::mainLoop(), 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 296 of file ActHandler.cpp.

References connection, and Connection::sendMessage().

Referenced by Player::mainLoop(), BasicCoach::mainLoopNormal(), and sendCommandDirect().


Member Data Documentation

Connection* ActHandler::connection [private]
 

Connection with the server

Definition at line 89 of file ActHandler.h.

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

int ActHandler::m_iMultipleCommands [private]
 

number of non-primary commands

Definition at line 96 of file ActHandler.h.

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

SoccerCommand ActHandler::m_queueMultipleCommands[CMD_MAX_COMMANDS] [private]
 

non primary commands

Definition at line 95 of file ActHandler.h.

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

SoccerCommand ActHandler::m_queueOneCycleCommand [private]
 

primary command is saved here

Definition at line 93 of file ActHandler.h.

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

ServerSettings* ActHandler::SS [private]
 

ServerSettings with server parameters

Definition at line 90 of file ActHandler.h.

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

WorldModel* ActHandler::WM [private]
 

needed to set performed actions

Definition at line 91 of file ActHandler.h.

Referenced by ActHandler(), and sendCommands().


The documentation for this class was generated from the following files:
Generated on Fri Nov 7 11:45:58 2003 for UvA Trilearn 2003 Base Code by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001