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 &game, const std::string &email, const std::string &comment)
 Creates an account on the server.
bool login (const std::string &user, const std::string &password, const std::string &game)
 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 ()
 Tells the server that the player has finished their turn.
std::set< GameInfo * > getAvailableGames () const
GameInfogetActiveGame () const

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 (  ) 

Member Function Documentation

bool TPProto::GameLayer::connect ( TPSocket nsock  ) 
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.

References TPProto::Logger::error(), and TPProto::Logger::warning().

bool TPProto::GameLayer::createAccount ( const std::string &  user,
const std::string &  password,
const std::string &  game,
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.
game The name of the game to create the account on.
email The user's email address.
comment A comment to send.
Returns:
True if successful, false otherwise.

References TPProto::FrameFactory::createAccountCreate(), TPProto::GameStatusListener::disconnected(), TPProto::Logger::error(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::ProtocolLayer::getFrameFactory(), TPProto::TPSocket::isConnected(), TPProto::FrameCodec::sendFrame(), TPProto::AccountCreate::setComment(), TPProto::AccountCreate::setEmail(), TPProto::AccountCreate::setPass(), TPProto::AccountCreate::setUser(), and TPProto::Features::supportsAccountCreation().

Message * TPProto::GameLayer::createMessage (  ) 

Creates a Message object.

Returns:
A new message object.

References TPProto::FrameFactory::createMessage(), and TPProto::ProtocolLayer::getFrameFactory().

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.
void TPProto::GameLayer::disconnect (  ) 

Disconnects from server.

Closes the underlying TPSocket.

References TPProto::TPSocket::disconnect(), TPProto::GameStatusListener::disconnected(), and TPProto::Logger::info().

void TPProto::GameLayer::finishedTurn (  ) 
GameInfo * TPProto::GameLayer::getActiveGame (  )  const

Get the GameInfo for the currently logged in game.

Returns:
The GameInfo for the current game, or NULL if not logged in.
std::set< GameInfo * > TPProto::GameLayer::getAvailableGames (  )  const

Get this set of available GameInfo for this server.

Could be empty if not yet fetched from the server or not connected.

Returns:
The set of GameInfo for the games on this server
BoardCache * TPProto::GameLayer::getBoardCache (  )  const

Gets the BoardCache.

Returns:
The BoardCache.
CategoryCache * TPProto::GameLayer::getCategoryCache (  )  const

Gets the CategoryCache.

Returns:
The CategoryCache.
ComponentCache * TPProto::GameLayer::getComponentCache (  )  const

Gets the ComponentCache.

Returns:
The ComponentCache.
DesignCache * TPProto::GameLayer::getDesignCache (  )  const

Gets the DesignCache.

Returns:
The DesignCache.
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.
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.
ObjectCache * TPProto::GameLayer::getObjectCache (  )  const

Gets the ObjectCache.

Returns:
The ObjectCache.
ObjectDescCache * TPProto::GameLayer::getObjectDescCache (  )  const

Gets the ObjectDescCache.

Returns:
The ObjectDescCache.
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.
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.
PlayerCache * TPProto::GameLayer::getPlayerCache (  )  const

Gets the PlayerCache.

Returns:
The PlayerCache.
PropertyCache * TPProto::GameLayer::getPropertyCache (  )  const

Gets the PropertyCache.

Returns:
The PropertyCache.
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.
ResourceCache * TPProto::GameLayer::getResourceCache (  )  const

Gets the ResourceCache.

Returns:
The ResourceCache.
GameStatus TPProto::GameLayer::getStatus (  ) 

Gets the state of the game.

Returns:
The GameStatus enum value for the current state.

References TPProto::GameStatusListener::disconnected(), and TPProto::TPSocket::isConnected().

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().

References TPProto::FrameFactory::createGetTimeRemaining(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::ProtocolLayer::getFrameFactory(), and TPProto::FrameCodec::sendFrame().

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.

Referenced by replaceOrder().

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

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.
game The name of the game to log into.
Returns:
True if successfully started, false otherwise.

References TPProto::FrameFactory::createLogin(), TPProto::GameStatusListener::disconnected(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::ProtocolLayer::getFrameFactory(), TPProto::TPSocket::isConnected(), TPProto::FrameCodec::sendFrame(), TPProto::Login::setPass(), and TPProto::Login::setUser().

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.
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::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.
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.

Referenced by replaceOrder().

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.

References TPProto::Order::getObjectId(), TPProto::Order::getSlot(), insertOrder(), and removeOrder().

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.

References TPProto::CacheMethod::clone(), and TPProto::Cache::setCacheMethod().

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::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.

References TPProto::ProtocolLayer::getFrameCodec(), and TPProto::Connection::setEventLoop().

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

Sets the GameStatusListener to use.

Parameters:
gsl The new GameStatusListener to use.
void TPProto::GameLayer::setLogger ( Logger nlog  ) 

Sets the Logger to use.

Parameters:
nlog The new Logger to use.

References TPProto::ProtocolLayer::getFrameCodec(), and TPProto::FrameCodec::setLogger().


The documentation for this class was generated from the following files:

Generated on Wed Mar 17 07:45:05 2010 for libtpproto-cpp by  doxygen 1.6.1