#include <ChannelProvider.h>
Collaboration diagram for GNE::ChannelProvider:
Public Member Functions | |
ChannelProvider () | |
Creates a new ChannelProvider, with no active channels. | |
void | addConnection (int channel, Connection *conn) |
Adds a Connection to a channel. | |
void | removeConnection (int channel, Connection *conn) |
Removes a Connection from a channel. | |
void | removeFromAll (Connection *conn) |
Removes the given Connection from all of the channels. | |
void | disbandChannel (int channel) |
Removes all of the Connections from a channel. | |
int | numConnections (int channel) const |
Returns the number of Connections currently part of the given channel. | |
void | sendToChannel (int channel, int from, const Packet &packet, Connection *exclude, bool reliable) const |
Sends a packet to everyone on a channel. | |
void | sendToChannel (ChannelPacket &packet, Connection *exclude, bool reliable) const |
Works just like sendToChannel( int, int, Packet&, Connection* ), except it takes an already created ChannelPacket. | |
Static Public Attributes | |
static const int | MIN_CHANNEL = 0 |
The minimum valid channel number. | |
static const int | MAX_CHANNEL = 255 |
The maximum valid channel number. | |
Classes | |
struct | Channel |
A single Connection can be in zero or more channels.
This class is part of the high-level GNE API, and is mostly meant to be used by the Server class, but users of the mid-level API who do not wish to use the Server/Client API may also find this class useful as well.
The valid range of channels is from 0 to 255, both sides inclusive. These values are reflected in the MIN_CHANNEL and MAX_CHANNEL static members.
This class is entirely thread-safe. The methods can all be called from multiple threads concurrently, and will retain their expected behaviors in all cases. The obvious exception is that no threads can be accessing the object if another thread is destroying or has destroyed the object.
void GNE::ChannelProvider::addConnection | ( | int | channel, | |
Connection * | conn | |||
) |
Adds a Connection to a channel.
If the channel does not exist, one is transparently created (in other words, you do not need to explicitly open new channels).
If one of the two parameters are invalid, no action is taken. In the debugging version of the library, an assert will fail in that case.
channel | a channel from 0 to 255 (MIN_CHANNEL to MAX_CHANNEL) | |
conn | a Connection to add, cannot be NULL. |
void GNE::ChannelProvider::disbandChannel | ( | int | channel | ) |
Removes all of the Connections from a channel.
If the channel parameter is invalid, no action is taken, but in the debugging version of the library, an assert will fail.
channel | a channel from 0 to 255 (MIN_CHANNEL to MAX_CHANNEL) |
void GNE::ChannelProvider::removeConnection | ( | int | channel, | |
Connection * | conn | |||
) |
Removes a Connection from a channel.
If the channel does not exist, or if the Connection is not a member of the channel, this method will have no effect.
If one of the two parameters are invalid, no action is taken. In the debugging version of the library, an assert will fail in that case.
channel | a channel from 0 to 255 (MIN_CHANNEL to MAX_CHANNEL) | |
conn | a Connection to remove, cannot be NULL. |
void GNE::ChannelProvider::removeFromAll | ( | Connection * | conn | ) |
Removes the given Connection from all of the channels.
Useful for when the Connection shuts down.
void GNE::ChannelProvider::sendToChannel | ( | int | channel, | |
int | from, | |||
const Packet & | packet, | |||
Connection * | exclude, | |||
bool | reliable | |||
) | const |
Sends a packet to everyone on a channel.
Creates a ChannelPacket with the specified channel and sends it to all Connections, except the one specified. Excluding a Connection is useful for when you want to send to everyone but the Connection who sent the packet.
It is acceptable if the channel does not exist -- in this case no packets will be sent. It is also acceptable if the exclude parameter does not exist in the channel -- in this case, the packet will be sent to all Connections.
If the channel parameter is invalid, no action is taken, but in the debugging version of the library, an assert will fail.
channel | the channel to send to. | |
from | source information. | |
packet | the packet to send. | |
exclude | does not send packets to this player. Can be NULL so that no Connection is excluded. | |
reliable | true if the packet should be sent reliably. |