Planeshift
Public Types | Public Member Functions | Protected Attributes

MsgHandler Class Reference

This class is the client's and server's main interface for either sending network messages out or getting notified about inbound ones which have been received. More...

#include <msghandler.h>

List of all members.

Public Types

typedef NetBase::broadcasttype broadcasttype
 import the broadcasttype

Public Member Functions

void AddToLocalQueue (MsgEntry *me)
virtual void Broadcast (MsgEntry *msg, broadcasttype scope=NetBase::BC_EVERYONEBUTSELF, int guildID=-1)
 Send messages to many clients with one func call.
bool Flush ()
 Flush the connected output queue.
csTicks GetPing ()
bool Initialize (NetBase *nb, int queuelen=500)
 Initializes the Handler.
 MsgHandler ()
virtual void Multicast (MsgEntry *msg, csArray< PublishDestination > &multi, uint32_t except, float range)
 Sends the given message me to all the clients in the list.
void Publish (MsgEntry *msg)
 Distribute message to all subscribers.
virtual void SendMessage (MsgEntry *msg)
 Allows subscribers to respond with new messages.
virtual void Subscribe (iNetSubscriber *subscriber, msgtype type, uint32_t flags=0x01)
 Subscribes an iNetSubscriber to a specific message type.
virtual bool Unsubscribe (iNetSubscriber *subscriber, msgtype type)
 Unsubscribes a subscriber from a specific message type.
virtual bool UnsubscribeAll (iNetSubscriber *subscriber)
 Searches all message types and deletes any Subscription that has the specified subscriber.
virtual ~MsgHandler ()

Protected Attributes

CS::Threading::ReadWriteMutex mutex
 Protects subscribers.
NetBasenetbase
MsgQueuequeue
csHash< Subscription, msgtypesubscribers
 Stores the hash of all subscribers and the message type they are subscribed to.

Detailed Description

This class is the client's and server's main interface for either sending network messages out or getting notified about inbound ones which have been received.

Definition at line 106 of file msghandler.h.


Member Typedef Documentation

import the broadcasttype

Definition at line 150 of file msghandler.h.


Constructor & Destructor Documentation

MsgHandler::MsgHandler ( )
virtual MsgHandler::~MsgHandler ( ) [virtual]

Member Function Documentation

void MsgHandler::AddToLocalQueue ( MsgEntry me) [inline]

Definition at line 179 of file msghandler.h.

virtual void MsgHandler::Broadcast ( MsgEntry msg,
broadcasttype  scope = NetBase::BC_EVERYONEBUTSELF,
int  guildID = -1 
) [inline, virtual]

Send messages to many clients with one func call.

Definition at line 157 of file msghandler.h.

bool MsgHandler::Flush ( ) [inline]

Flush the connected output queue.

Definition at line 184 of file msghandler.h.

csTicks MsgHandler::GetPing ( ) [inline]

Definition at line 181 of file msghandler.h.

bool MsgHandler::Initialize ( NetBase nb,
int  queuelen = 500 
)

Initializes the Handler.

virtual void MsgHandler::Multicast ( MsgEntry msg,
csArray< PublishDestination > &  multi,
uint32_t  except,
float  range 
) [inline, virtual]

Sends the given message me to all the clients in the list.

Sends the given message me to all the clients in the list (clientlist) which is of size count. This will send the message to all the clients except the client which has a client number given in the variable except.

Note:
(Brendon) Why is multi not const & ?
Parameters:
msgIs the message to be sent to other clients.
multiIs a vector of all the clients to send this message to.
exceptIs a client number for a client NOT to send this message to. This would usually be the client trying to send the message.
rangeIs the maximum distance the client must be away to be out of "message reception range".

Definition at line 176 of file msghandler.h.

void MsgHandler::Publish ( MsgEntry msg)

Distribute message to all subscribers.

virtual void MsgHandler::SendMessage ( MsgEntry msg) [inline, virtual]

Allows subscribers to respond with new messages.

Reimplemented in ClientMsgHandler.

Definition at line 153 of file msghandler.h.

virtual void MsgHandler::Subscribe ( iNetSubscriber subscriber,
msgtype  type,
uint32_t  flags = 0x01 
) [virtual]

Subscribes an iNetSubscriber to a specific message type.

Subclasses of iNetSubscriber subscribe to incoming network messages using this function. Adds the resulting Subscription to subscribers.

Parameters:
subscriberThe subscriber that wants to be informed of messages
typeThe type of message to monitor
flagsAdditional flags to determine if the message should be forwarded
virtual bool MsgHandler::Unsubscribe ( iNetSubscriber subscriber,
msgtype  type 
) [virtual]

Unsubscribes a subscriber from a specific message type.

If subscribers contains a Subscription that has the specified subscriber and the message type key it is removed and true is returned

Parameters:
subscriberThe subscriber to look for in the hash
typeThe type of message to search
Returns:
True if the subscription is found and deleted, false otherwise
virtual bool MsgHandler::UnsubscribeAll ( iNetSubscriber subscriber) [virtual]

Searches all message types and deletes any Subscription that has the specified subscriber.

Parameters:
subscriberThe subscriber to search for and remove
Returns:
True if at least one Subscription was deleted, false otherwise

Member Data Documentation

CS::Threading::ReadWriteMutex MsgHandler::mutex [protected]

Protects subscribers.

Reimplemented in EventManager.

Definition at line 194 of file msghandler.h.

Definition at line 187 of file msghandler.h.

Definition at line 188 of file msghandler.h.

Stores the hash of all subscribers and the message type they are subscribed to.

Definition at line 193 of file msghandler.h.


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