Main Page   Class Hierarchy   Compound List   File List   Compound Members  

NetManager Class Reference

Network manager class for Perihelion. More...

#include <netmanager.h>

Inheritance diagram for NetManager:

Inheritance graph
[legend]
List of all members.

Public Methods

 NetManager ()
 Creates a NetManager. More...

void keepSending (bool go_on=true)
 Starts/stops data sending. More...

virtual ~NetManager ()
 Destroys all the data structures. More...

void waitForData ()
 Waits until there is data ready. More...

bool dataReady ()
 Tells if there is data ready in the socket. More...


Static Public Attributes

const Uint16 SERVER_PORT = 57570
 Port the server will be listening at.

const int PACKET_SIZE = 1600
 Size of the UDP packets sent through the network.


Protected Methods

virtual void onReception (unsigned client)
 Method called after reception of a packet from a certain client. More...

void transmit (const UDPsocket &sock, const MessagePacket &msg) const
 Performs the actual transmission of the data through the socket.

virtual void manageReception ()
 Controls the data reception. More...

virtual bool forwardMessage (const MessagePacket &msg, IPaddress *ip)=0
 Determines whether the message should or not be forwarded to the user. More...


Protected Attributes

queue< MessagePacketinputBuffer
 Contains the unread packets received from the receiverSocket.

IPaddress serverIP
 IP address for the server. More...

UDPsocket receiverSocket
 Socket used for data reception. More...

Uint16 actualPort
 Keeps the actual port through the data will be sent.

SDL_Thread * receiver
 Controls the reception of data. More...

bool exitControllers
 Tells the controller when to exit. More...

bool keepSendingFlag
 Allows/forbids data sending. More...

SDL_mutex * sendingMutex
 Controls the access to keepSendingFlag.

SDL_mutex * exitMutex
 Controls the access to the exitController flag. More...

SDL_cond * dataReadyCond
 The 'waitForData' method locks here to wait for data to be ready.

SDL_mutex * dataReadyMutex
 Controls the access to dataReadyMutex.

SDLNet_SocketSet receiverSet
 Used to control the arrival of new data.

SDL_mutex * socketOpen
 Prevents the reception thread from accessing a not ready NetManager. More...


Friends

int receiverCallback (void *data)
 Calls the receiver thread method. More...


Detailed Description

Network manager class for Perihelion.

Network manager class for Perihelion, with capabilities to send and receive MessagePacket objects, and return them to the class' users.

Please be aware of methods that can throw exceptions when indicated.

Note: Unless we find an use for them, channels in UCP sockets will be ignored, and 0 will be used by default.


Constructor & Destructor Documentation

NetManager::NetManager  
 

Creates a NetManager.

Creates a NetManager object, although most of the work is done in the subclasses.

NetManager::~NetManager   [virtual]
 

Destroys all the data structures.

Flushes the remaining data, closes the socket and destroys all the data structures.


Member Function Documentation

bool NetManager::dataReady  
 

Tells if there is data ready in the socket.

Tells if there is data ready to gather from the client socket. This method can raise exceptions if something goes wrong, so please catch the 'string'.

Returns:
a boolean value indicating whether there is data ready or not.

virtual bool NetManager::forwardMessage const MessagePacket   msg,
IPaddress *    ip
[protected, pure virtual]
 

Determines whether the message should or not be forwarded to the user.

Returns:
a boolean telling whether the message must pass or not.

Implemented in NetManagerClient, and NetManagerServer.

void NetManager::keepSending bool    go_on = true
 

Starts/stops data sending.

Starts/stops data sending, by constraining the behavior of the 'flush' method.

void NetManager::manageReception   [protected, virtual]
 

Controls the data reception.

Controls the network reception, offering the upper layer a simplified view. This code is run asinchronously, in the 'receiver' thread.

virtual void NetManager::onReception unsigned    client [inline, protected, virtual]
 

Method called after reception of a packet from a certain client.

This is intended to serve the inherited classes to manage events like this.

Parameters:
client  indicates the index of the client that sent the message.

Reimplemented in NetManagerServer.

void NetManager::waitForData  
 

Waits until there is data ready.

Waits until there is data ready in the input buffers. If there is already some data, it just exits. It can be used to control the network activity from a separate thread without having to poll it constantly.


Friends And Related Function Documentation

int receiverCallback void *    data [friend]
 

Calls the receiver thread method.

Calls the receiver thread method. It is needed to initialize the SDL_Thread that

gets data from the connection (it cannot be a method, as long as I know).


Member Data Documentation

bool NetManager::exitControllers [protected]
 

Tells the controller when to exit.

Gently tells the controllers when to exit, instead of just killing the threads. When it is set to true and the controller threads are running (otherwise it would be nice to wake them up), it does its last loop and exit.

SDL_mutex* NetManager::exitMutex [protected]
 

Controls the access to the exitController flag.

Controls the access to the exitController flag, and should be used anytime we enter/leave its critical section.

bool NetManager::keepSendingFlag [protected]
 

Allows/forbids data sending.

Allows/forbids data sending, by controlling the 'flush' method.

SDL_Thread* NetManager::receiver [protected]
 

Controls the reception of data.

This thread controls the reception of data. MUST be running in order to actually get some transactions done, instead of endless buffering. This thread can only be stopped when destroying the NetManager.

UDPsocket NetManager::receiverSocket [protected]
 

Socket used for data reception.

Socket used for data reception and, in the case of clients, also for sending.

IPaddress NetManager::serverIP [protected]
 

IP address for the server.

Keeps the IP address for the server, both in the server and the client. in the client it is more important because we need to know where to send the data. In the server it is still needed to open the connection and listen.

SDL_mutex* NetManager::socketOpen [protected]
 

Prevents the reception thread from accessing a not ready NetManager.

Prevents the reception thread from accessing a not ready NetManager. Must be unlocked in the subclasses right after the receiver socket (maybe a few more) is created.


The documentation for this class was generated from the following files:
Generated on Thu Jun 6 17:22:22 2002 for Perihelion by doxygen1.2.15