TPProto::GameLayer Class Reference

GameLayer is the main interface to the higher layer of libtpproto-cpp. More...

#include <gamelayer.h>

List of all members.

Public Member Functions

 GameLayer ()
 Constructs object and sets up defaults.
 ~GameLayer ()
 Destructor.
void setClientString (const std::string &name)
 Sets the client string.
void setLogger (Logger *nlog)
 Sets the Logger to use.
void setGameStatusListener (GameStatusListener *gsl)
 Sets the GameStatusListener to use.
void setCacheMethod (CacheMethod *prototype)
 Sets the CacheMethod for the caches to use. Changes the default CacheMethod used, defaults to CacheNoneMethod.
void setEventLoop (EventLoop *el)
 Sets the EventLoop abstraction to use. Sets which implementation of EventLoop to use.
GameStatus getStatus ()
 Gets the state of the game.
ProtocolLayergetProtocolLayer () const
 Gets the ProtocolLayer being used. This could be used to do low level calls to the protocol itself, or more importantly, set the FrameFactory, FrameBuilder and/or FrameCodec classes in the ProtocolLayer.
bool connect (const std::string &address)
 Connects to the given address url This method connects to the server given as the address. The types of url supported are tp, tps, https and http. Tps and https depend on TLS being enabled.
bool connect (TPSocket *nsock)
 Connects using a given TPSocket. Connects to a server using a given TPSocket.
bool createAccount (const std::string &user, const std::string &password, const std::string &email, const std::string &comment)
 Creates an account on the server.
bool login (const std::string &user, const std::string &password)
 Logs in to the server.
void disconnect ()
 Disconnects from server.
void updateCaches ()
 Tells all the caches to update. Called automatically after logged in, and after EOT has finished. Call if you want the caches to be updated.
ObjectDescCachegetObjectDescCache () const
 Gets the ObjectDescCache.
ObjectCachegetObjectCache () const
 Gets the ObjectCache.
OrderDescCachegetOrderDescCache () const
 Gets the OrderDescCache.
std::list< Order * > getOrders (uint32_t obid, uint32_t num)
 Gets Orders from the server.
OrdergetOrder (uint32_t obid, uint32_t slot)
 Gets an Orders from the server.
OrdercreateOrderFrame (int type)
 Creates an Order Frame of a given type.
bool insertOrder (Order *frame)
 Inserts an Order into the objects order queue.
bool replaceOrder (Order *frame)
 Replaces a current Order with a new one.
OrderprobeOrder (Order *frame)
 Probes an Order.
bool removeOrder (uint32_t obid, uint32_t slot)
 Removes an Order from the server.
BoardCachegetBoardCache () const
 Gets the BoardCache.
std::list< Message * > getMessages (uint32_t boardid, uint32_t num)
 Gets Messages from the server.
MessagecreateMessage ()
 Creates a Message object.
MessagegetMessage (uint32_t boardid, uint32_t slot)
 Gets a Message from the server.
bool postMessage (Message *frame)
 Posts a Message to the server.
bool removeMessage (uint32_t boardid, uint32_t slot)
 Removes messages from the server.
ResourceCachegetResourceCache () const
 Gets the ResourceCache.
PlayerCachegetPlayerCache () const
 Gets the PlayerCache.
CategoryCachegetCategoryCache () const
 Gets the CategoryCache.
DesignCachegetDesignCache () const
 Gets the DesignCache.
ComponentCachegetComponentCache () const
 Gets the ComponentCache.
PropertyCachegetPropertyCache () const
 Gets the PropertyCache.
void getTimeRemaining ()
 Gets the time remaining before the end of turn.
void finishedTurn ()

Friends

class GameLayerAsyncFrameListener


Detailed Description

GameLayer is the main interface to the higher layer of libtpproto-cpp.

GameLayer abstracts away most of the underlying details of how Objects and Orders are requested and received.


Constructor & Destructor Documentation

TPProto::GameLayer::GameLayer (  ) 

Constructs object and sets up defaults.

Defaults are


Member Function Documentation

void TPProto::GameLayer::setClientString ( const std::string &  name  ) 

Sets the client string.

The client string can be set to anything. The perferred format is "name/version". The library name and version is added the the client string later.

Parameters:
name The client name string.

void TPProto::GameLayer::setLogger ( Logger nlog  ) 

Sets the Logger to use.

Parameters:
nlog The new Logger to use.

void TPProto::GameLayer::setGameStatusListener ( GameStatusListener gsl  ) 

Sets the GameStatusListener to use.

Parameters:
gsl The new GameStatusListener to use.

void TPProto::GameLayer::setCacheMethod ( CacheMethod prototype  ) 

Sets the CacheMethod for the caches to use. Changes the default CacheMethod used, defaults to CacheNoneMethod.

Parameters:
prototype A CacheMethod that will be cloned for each Cache to use.

void TPProto::GameLayer::setEventLoop ( EventLoop el  ) 

Sets the EventLoop abstraction to use. Sets which implementation of EventLoop to use.

Must be set before connecting to a server.

Parameters:
el The implementation of the EventLoop to use.

GameStatus TPProto::GameLayer::getStatus (  ) 

Gets the state of the game.

Returns:
The GameStatus enum value for the current state.

ProtocolLayer * TPProto::GameLayer::getProtocolLayer (  )  const

Gets the ProtocolLayer being used. This could be used to do low level calls to the protocol itself, or more importantly, set the FrameFactory, FrameBuilder and/or FrameCodec classes in the ProtocolLayer.

Returns:
The pointer to the ProtocolLayer.

bool TPProto::GameLayer::connect ( const std::string &  address  ) 

Connects to the given address url This method connects to the server given as the address. The types of url supported are tp, tps, https and http. Tps and https depend on TLS being enabled.

Parameters:
address The URL to connect to.
Returns:
True if connection in progress, false otherwise.

bool TPProto::GameLayer::connect ( TPSocket nsock  ) 

Connects using a given TPSocket. Connects to a server using a given TPSocket.

Parameters:
nsock The TPSocket to connect using.
Returns:
True if connection in progress, false otherwise.

bool TPProto::GameLayer::createAccount ( const std::string &  user,
const std::string &  password,
const std::string &  email,
const std::string &  comment 
)

Creates an account on the server.

Sends a AccountCreate Frame to the server and waits for a reply.

Parameters:
user The username to use.
password The password for the account.
email The user's email address.
comment A comment to send.
Returns:
True if successful, false otherwise.

bool TPProto::GameLayer::login ( const std::string &  username,
const std::string &  password 
)

Logs in to the server.

Sends a Login Frame to the server and waits for a reply.

Parameters:
username The username to connect as.
password The password of the account of the username.
Returns:
True if successfully started, false otherwise.

void TPProto::GameLayer::disconnect (  ) 

Disconnects from server.

Closes the underlying TPSocket.

ObjectDescCache * TPProto::GameLayer::getObjectDescCache (  )  const

Gets the ObjectDescCache.

Returns:
The ObjectDescCache.

ObjectCache * TPProto::GameLayer::getObjectCache (  )  const

Gets the ObjectCache.

Returns:
The ObjectCache.

OrderDescCache * TPProto::GameLayer::getOrderDescCache (  )  const

Gets the OrderDescCache.

Returns:
The OrderDescCache.

std::list< Order * > TPProto::GameLayer::getOrders ( uint32_t  obid,
uint32_t  num 
)

Gets Orders from the server.

This method sends the GetOrder Frame to the server and returns the Order Frames.

Parameters:
obid The object to get the orders from.
num The number of orders to get.
Returns:
List of Orders.

Order * TPProto::GameLayer::getOrder ( uint32_t  obid,
uint32_t  slot 
)

Gets an Orders from the server.

This method sends the GetOrder Frame to the server and returns the Order Frame.

Parameters:
obid The object to get the orders from.
slot The slot number of the order to get.
Returns:
The order retreved.

Order * TPProto::GameLayer::createOrderFrame ( int  type  ) 

Creates an Order Frame of a given type.

This method creates a new Order Frame, sets the protocol version and sets up the order for the given type, including parameters.

Parameters:
type The type number for the order type.
Returns:
The new Order.

bool TPProto::GameLayer::insertOrder ( Order frame  ) 

Inserts an Order into the objects order queue.

Parameters:
frame The Order to insert.
Returns:
True if successful, false otherwise.

bool TPProto::GameLayer::replaceOrder ( Order frame  ) 

Replaces a current Order with a new one.

First inserts the new Order, then removes the old one. Can fail with or without the new order in the order queue.

Parameters:
frame The Order that will replace the current one.
Returns:
True if successful, false otherwise.

Order * TPProto::GameLayer::probeOrder ( Order frame  ) 

Probes an Order.

Sends the order to the server to be probed, returning the order that would have been added to the object.

Parameters:
frame The Order to probe.
Returns:
The reply Order with read-only fields filled.

bool TPProto::GameLayer::removeOrder ( uint32_t  obid,
uint32_t  slot 
)

Removes an Order from the server.

Sends the RemoveOrder frame to the server and receives reply.

Parameters:
obid The Object to remove the order from.
slot The slot that should have it's order removed.
Returns:
True if sucessful, false otherwise.

BoardCache * TPProto::GameLayer::getBoardCache (  )  const

Gets the BoardCache.

Returns:
The BoardCache.

std::list< Message * > TPProto::GameLayer::getMessages ( uint32_t  boardid,
uint32_t  num 
)

Gets Messages from the server.

Sends the GetMessage Frame and receives the Message frames.

Parameters:
boardid The board ID of the board to get the messages from.
num The number of messages to get.
Returns:
List of Messages.

Message * TPProto::GameLayer::createMessage (  ) 

Creates a Message object.

Returns:
A new message object.

Message * TPProto::GameLayer::getMessage ( uint32_t  boardid,
uint32_t  slot 
)

Gets a Message from the server.

Sends the GetMessage Frame and receives the Message frame.

Parameters:
boardid The board ID of the board to get the message from.
slot The slot number of the message to get.
Returns:
The Message.

bool TPProto::GameLayer::postMessage ( Message frame  ) 

Posts a Message to the server.

Sends the Message Frame to the server.

Parameters:
frame The Message to post.
Returns:
True if successful, false otherwise.

bool TPProto::GameLayer::removeMessage ( uint32_t  boardid,
uint32_t  slot 
)

Removes messages from the server.

Sends the RemoveMessage frame and receives the replies.

Parameters:
boardid The board id of the board to remove the message from.
slot The slot to remove the message from.
Returns:
True if message is removed, false otherwise.

ResourceCache * TPProto::GameLayer::getResourceCache (  )  const

Gets the ResourceCache.

Returns:
The ResourceCache.

PlayerCache * TPProto::GameLayer::getPlayerCache (  )  const

Gets the PlayerCache.

Returns:
The PlayerCache.

CategoryCache * TPProto::GameLayer::getCategoryCache (  )  const

Gets the CategoryCache.

Returns:
The CategoryCache.

DesignCache * TPProto::GameLayer::getDesignCache (  )  const

Gets the DesignCache.

Returns:
The DesignCache.

ComponentCache * TPProto::GameLayer::getComponentCache (  )  const

Gets the ComponentCache.

Returns:
The ComponentCache.

PropertyCache * TPProto::GameLayer::getPropertyCache (  )  const

Gets the PropertyCache.

Returns:
The PropertyCache.

void TPProto::GameLayer::getTimeRemaining (  ) 

Gets the time remaining before the end of turn.

Fetches the time remaining till the end of turn from the server. The actual value is returned through the GameStatusListener::timeToEoT().


The documentation for this class was generated from the following files:
Generated on Tue Jan 6 09:00:51 2009 for libtpproto-cpp by  doxygen 1.5.1