SuperTuxKart
Public Member Functions | Protected Attributes | List of all members
Protocol Class Referenceabstract

Abstract class used to define the global protocol functions. More...

#include <protocol.hpp>

Inheritance diagram for Protocol:
Inheritance graph
[legend]

Public Member Functions

 Protocol (ProtocolType type)
 Constructor Sets the basic protocol parameters, as the callback object and the protocol type. More...
 
virtual ~Protocol ()
 Destructor.
 
virtual void setup ()=0
 Called when the protocol is going to start. More...
 
virtual void update (int ticks)=0
 Called by the protocol listener, synchronously with the main loop. More...
 
virtual void asynchronousUpdate ()=0
 Called by the protocol listener as often as possible. More...
 
NetworkStringgetNetworkString (size_t capacity=16) const
 functions to check incoming data easily More...
 
bool checkDataSize (Event *event, unsigned int minimum_size)
 Checks if the message has at least the specified size, and if not prints a warning message including the message content. More...
 
void sendMessageToPeers (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in game, encrypt the message if needed. More...
 
void sendMessageToPeersInServer (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in server, encrypt the message if needed. More...
 
void sendToServer (NetworkString *message, bool reliable=true)
 Sends a message from a client to the server.
 
virtual void requestStart ()
 Starts a request in the protocol manager to start this protocol.
 
virtual void requestTerminate ()
 Submits a request to the ProtocolManager to terminate this protocol.
 
virtual bool notifyEvent (Event *event)
 Notify a protocol matching the Event type of that event. More...
 
virtual bool notifyEventAsynchronous (Event *event)
 Notify a protocol matching the Event type of that event. More...
 
ProtocolType getProtocolType () const
 Method to get a protocol's type. More...
 
void setHandleConnections (bool b)
 Sets if this protocol should receive connection events. More...
 
void setHandleDisconnections (bool b)
 Sets if this protocol should receive disconnection events. More...
 
virtual bool handleConnects () const
 Return true if this protocol should be informed about connects. More...
 
virtual bool handleDisconnects () const
 Return true if this protocol should be informed about disconnects. More...
 

Protected Attributes

ProtocolType m_type
 The type of the protocol. More...
 
bool m_handle_connections
 True if this protocol should receive connection events. More...
 
bool m_handle_disconnections
 TRue if this protocol should recceiver disconnection events. More...
 

Detailed Description

Abstract class used to define the global protocol functions.

A protocol is an entity that is started at a point, and that is updated by a thread. A protocol can be terminated by an other class, or it can terminate itself if has fulfilled its role. This class must be inherited to make any network job.

Constructor & Destructor Documentation

◆ Protocol()

Protocol::Protocol ( ProtocolType  type)

Constructor Sets the basic protocol parameters, as the callback object and the protocol type.

Parameters
callback_objectThe callback object that will be used by the protocol. Protocols that do not use callback objects must set it to NULL.
typeThe type of the protocol.

Member Function Documentation

◆ asynchronousUpdate()

virtual void Protocol::asynchronousUpdate ( )
pure virtual

Called by the protocol listener as often as possible.

Must be re-defined.

Implemented in ServerLobby, ClientLobby, GameProtocol, ConnectToServer, ConnectToPeer, and GameEventsProtocol.

◆ checkDataSize()

bool Protocol::checkDataSize ( Event event,
unsigned int  minimum_size 
)

Checks if the message has at least the specified size, and if not prints a warning message including the message content.

Returns
True if the message is long enough, false otherwise.

◆ getNetworkString()

NetworkString * Protocol::getNetworkString ( size_t  capacity = 16) const

functions to check incoming data easily

Returns a network string with the given type.

Default preallocated size for the message.

◆ getProtocolType()

ProtocolType Protocol::getProtocolType ( ) const
inline

Method to get a protocol's type.

Returns
The protocol type.

◆ handleConnects()

virtual bool Protocol::handleConnects ( ) const
inlinevirtual

Return true if this protocol should be informed about connects.

◆ handleDisconnects()

virtual bool Protocol::handleDisconnects ( ) const
inlinevirtual

Return true if this protocol should be informed about disconnects.

◆ notifyEvent()

virtual bool Protocol::notifyEvent ( Event event)
inlinevirtual

Notify a protocol matching the Event type of that event.

Parameters
event: Pointer to the event.
Returns
True if the event has been treated, false otherwise.

Reimplemented in ServerLobby, ClientLobby, and GameEventsProtocol.

◆ notifyEventAsynchronous()

virtual bool Protocol::notifyEventAsynchronous ( Event event)
inlinevirtual

Notify a protocol matching the Event type of that event.

This update is done asynchronously :

Parameters
event: Pointer to the event.
Returns
True if the event has been treated, false otherwise

Reimplemented in ServerLobby, ClientLobby, GameProtocol, and GameEventsProtocol.

◆ sendMessageToPeers()

void Protocol::sendMessageToPeers ( NetworkString message,
bool  reliable = true 
)

Sends a message to all validated peers in game, encrypt the message if needed.

The message is composed of a 1-byte message (usually the message type) followed by the actual message.

Parameters
messageThe actual message content.

◆ sendMessageToPeersInServer()

void Protocol::sendMessageToPeersInServer ( NetworkString message,
bool  reliable = true 
)

Sends a message to all validated peers in server, encrypt the message if needed.

The message is composed of a 1-byte message (usually the message type) followed by the actual message.

Parameters
messageThe actual message content.

◆ setHandleConnections()

void Protocol::setHandleConnections ( bool  b)
inline

Sets if this protocol should receive connection events.

◆ setHandleDisconnections()

void Protocol::setHandleDisconnections ( bool  b)
inline

Sets if this protocol should receive disconnection events.

◆ setup()

virtual void Protocol::setup ( )
pure virtual

Called when the protocol is going to start.

Must be re-defined by subclasses.

Implemented in ServerLobby, LobbyProtocol, ClientLobby, GameProtocol, ConnectToServer, ConnectToPeer, and GameEventsProtocol.

◆ update()

virtual void Protocol::update ( int  ticks)
pure virtual

Called by the protocol listener, synchronously with the main loop.

Must be re-defined.

Implemented in ServerLobby, LobbyProtocol, ClientLobby, GameProtocol, ConnectToServer, ConnectToPeer, and GameEventsProtocol.

Member Data Documentation

◆ m_handle_connections

bool Protocol::m_handle_connections
protected

True if this protocol should receive connection events.

◆ m_handle_disconnections

bool Protocol::m_handle_disconnections
protected

TRue if this protocol should recceiver disconnection events.

◆ m_type

ProtocolType Protocol::m_type
protected

The type of the protocol.


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