FrameCodec is the main working class the lower layer of libtpproto-cpp. More...
#include <framecodec.h>
Public Member Functions | |
| FrameCodec () | |
| Constructs object and sets up defaults. | |
| ~FrameCodec () | |
| Destructor. | |
| void | setAsyncFrameListener (AsyncFrameListener *afl) |
| Sets the AsyncFrameListener. | |
| void | setLogger (Logger *nlog) |
| Sets the Logger. | |
| void | setProtocolLayer (ProtocolLayer *pl) |
| Sets the ProtocolLayer. | |
| int | getStatus () |
| Gets the status of the connection. | |
| FrameConnection | sendFrame (boost::shared_ptr< Frame > f, const FrameSignal::slot_type &callback) |
| Sends a Frame and sets the slot for the recieved reply(s) to be sent to. | |
| void | readyToRead () |
| Called when the socket has data ready to be read. | |
| void | readyToSend () |
| Called when the socket is ready for data to be sent to it. | |
| void | receivedFrame (Frame *frame) |
| Called by FrameBuilder when a Frame is decoded from a Buffer. Sends the Frame to the right slot, or to the AsyncFrameListener if the frame is an asynchronous (sequence number is 0). | |
FrameCodec is the main working class the lower layer of libtpproto-cpp.
The FrameCodec class is responsible for handling the running of the protocol. It interacts with the Thousand Parsec servers and avoids a lot of unneccessary handling by the client and higher layers. The FrameCodec class is not the best way for a client to access a tp server, use the upper layers for that, but it can be used if necessary. A ProtocolLayer must be set (by setting this object as the FrameCodec for the ProtocolLayer).
| TPProto::FrameCodec::FrameCodec | ( | ) |
Constructs object and sets up defaults.
Defaults are
| int TPProto::FrameCodec::getStatus | ( | ) |
Gets the status of the connection.
References TPProto::TPSocket::isConnected(), and TPProto::Connection::socket.
| void TPProto::FrameCodec::readyToRead | ( | ) | [virtual] |
Called when the socket has data ready to be read.
Protocol reading entry point is here. Non-blocking sockets should be used.
Implements TPProto::Connection.
References TPProto::Logger::debug(), TPProto::TPSocket::isConnected(), and TPProto::Connection::socket.
| void TPProto::FrameCodec::readyToSend | ( | ) | [virtual] |
Called when the socket is ready for data to be sent to it.
This can be used to send queued data when non-blocking writes say they would have blocked.
Implements TPProto::Connection.
| void TPProto::FrameCodec::receivedFrame | ( | Frame * | frame | ) |
Called by FrameBuilder when a Frame is decoded from a Buffer. Sends the Frame to the right slot, or to the AsyncFrameListener if the frame is an asynchronous (sequence number is 0).
| frame | The Frame that has been received. |
References TPProto::Frame::getSequenceNumber(), TPProto::Frame::getType(), TPProto::AsyncFrameListener::recvLogMessage(), TPProto::AsyncFrameListener::recvTimeRemaining(), and TPProto::Logger::warning().
Referenced by TPProto::FrameBuilder::buildFrame(), TPProto::FrameBuilder::processCommandDescription(), TPProto::FrameBuilder::processObjectDescription(), and TPProto::FrameBuilder::processOrderDescription().
| FrameConnection TPProto::FrameCodec::sendFrame | ( | boost::shared_ptr< Frame > | f, | |
| const FrameSignal::slot_type & | callback | |||
| ) |
Sends a Frame and sets the slot for the recieved reply(s) to be sent to.
Packs the Frame into a Buffer and sends it via the TPSocket. Sets the sequence number and increments the sequence number counter.
| f | The Frame to send. | |
| callback | The slot that replies will be sent to. |
| DisconnectedException | If the socket is not connected. |
References TPProto::Buffer::createHeader(), TPProto::Buffer::getData(), TPProto::Buffer::getLength(), TPProto::TPSocket::isConnected(), TPProto::TPSocket::send(), and TPProto::Connection::socket.
Referenced by TPProto::CategoryCache::addCategory(), TPProto::DesignCache::addDesign(), TPProto::GameLayer::connect(), TPProto::AdminLayer::connect(), TPProto::GameLayer::createAccount(), TPProto::GameLayer::finishedTurn(), TPProto::CacheNoneMethod::getById(), TPProto::CacheNoneMethod::getIdList(), TPProto::GameLayer::getTimeRemaining(), TPProto::GameLayer::login(), TPProto::AdminLayer::login(), TPProto::DesignCache::modifyDesign(), TPProto::CategoryCache::removeCategory(), TPProto::DesignCache::removeDesign(), TPProto::AdminLayer::sendCommand(), TPProto::PlayerCache::update(), and TPProto::BoardCache::update().
| void TPProto::FrameCodec::setAsyncFrameListener | ( | AsyncFrameListener * | afl | ) |
Sets the AsyncFrameListener.
Only one AsyncFrameListener is allowed currently. When a new listener is set, the old one if present is deleted.
| afl | The AsyncFrameListener to use. |
Referenced by TPProto::AdminLayer::AdminLayer(), and TPProto::GameLayer::GameLayer().
| void TPProto::FrameCodec::setLogger | ( | Logger * | nlog | ) |
Sets the Logger.
This method sets a new Logger. The old Logger is deleted. If the pointer to the new Logger is NULL, the default SilentLogger is used.
| nlog | The new Logger to use, or NULL |
References TPProto::Logger::debug().
Referenced by TPProto::GameLayer::setLogger(), and TPProto::AdminLayer::setLogger().
| void TPProto::FrameCodec::setProtocolLayer | ( | ProtocolLayer * | pl | ) |
Sets the ProtocolLayer.
This method sets the ProtocolLayer.
| pl | The ProtocolLayer to use. |
References TPProto::Logger::debug().
Referenced by TPProto::ProtocolLayer::ProtocolLayer(), and TPProto::ProtocolLayer::setFrameCodec().
1.6.1