NSCpp 2.0
NSCpp is a modern C++20 server/client framework designed to simplify network programming in C++. With robust support for both IPv4 and IPv6, as well as TCP and UDP communication protocols.
 
Loading...
Searching...
No Matches
GroupManager Class Reference

#include <GroupManager.h>

Public Member Functions

void subscribe (const std::string &groupName, std::function< void(const std::string &)> callback, const std::string &CUID)
 Let you register a Channel's callback to a group.
 
void unsubscribe (const std::string &groupName, const std::string &CUID)
 Remove a Channel's callback from the given group.
 
void send (const std::string &groupName, const std::string &message)
 Emit the message in the given groupName.
 

Static Public Member Functions

static GroupManagergetInstance ()
 Return the instance of the GroupManager or create one if it does not exist.
 

Protected Attributes

std::unordered_map< std::string, std::vector< std::pair< std::function< void(const std::string &)>, std::string > > > groups
 Unordered map of the groups, link the group's name to the callback and CUID.
 

Member Function Documentation

◆ getInstance()

static GroupManager & GroupManager::getInstance ( )
static

Return the instance of the GroupManager or create one if it does not exist.

This class is a Singleton.

◆ send()

void GroupManager::send ( const std::string & groupName,
const std::string & message )

Emit the message in the given groupName.

Every callbacks of the given group will be called with the message as parameter.

Parameters
groupNameGroup's name.
messageMessage to be emit the group.

◆ subscribe()

void GroupManager::subscribe ( const std::string & groupName,
std::function< void(const std::string &)> callback,
const std::string & CUID )

Let you register a Channel's callback to a group.

Parameters
groupNameGroup's name.
callbackCallback which will be called when someone emit in the groupName's group.
CUIDChannel's key used to identify it.

◆ unsubscribe()

void GroupManager::unsubscribe ( const std::string & groupName,
const std::string & CUID )

Remove a Channel's callback from the given group.

Parameters
groupNameGroup's name to search for the callback.
CUIDChannel's key in the group associate to the callback.

Member Data Documentation

◆ groups

std::unordered_map<std::string, std::vector<std::pair<std::function<void(const std::string&)>, std::string> > > GroupManager::groups
protected

Unordered map of the groups, link the group's name to the callback and CUID.

Multiple callbacks can be declared for the same group. When a Channel is unsubscribe, every receiver inside the group is removed.


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