libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
MulticastManager Class Reference

Manages multicast group membership for multi-stream scenarios. More...

#include <multicastmanager.h>

Inheritance diagram for MulticastManager:
Collaboration diagram for MulticastManager:

Public Member Functions

 MulticastManager (ObjectBase *parent=nullptr)
 Constructs a MulticastManager.
 
 ~MulticastManager () override
 Destructor. Leaves all managed groups.
 
Error joinGroup (const SocketAddress &group, UdpSocket *socket)
 Joins a multicast group on a socket.
 
Error joinGroup (const SocketAddress &group, UdpSocket *socket, const String &iface)
 Joins a multicast group on a specific interface.
 
Error leaveGroup (const SocketAddress &group, UdpSocket *socket)
 Leaves a multicast group on a socket.
 
void leaveAllGroups ()
 Leaves all managed multicast groups.
 
List< SocketAddressactiveGroups () const
 Returns a list of all active multicast group addresses.
 
bool isMemberOf (const SocketAddress &group) const
 Returns true if any socket is a member of the group.
 
Error joinSourceGroup (const SocketAddress &group, const SocketAddress &source, UdpSocket *socket)
 Joins a Source-Specific Multicast group.
 
Error leaveSourceGroup (const SocketAddress &group, const SocketAddress &source, UdpSocket *socket)
 Leaves a Source-Specific Multicast group.
 
void setDefaultInterface (const String &iface)
 Sets the default network interface for joins.
 
const StringdefaultInterface () const
 Returns the default interface name.
 
 PROMEKI_SIGNAL (groupJoined, SocketAddress)
 Emitted when a multicast group is joined.
 
 PROMEKI_SIGNAL (groupLeft, SocketAddress)
 Emitted when a multicast group is left.
 
- Public Member Functions inherited from ObjectBase
 ObjectBase (ObjectBase *p=nullptr)
 Default ObjectBase constructor.
 
virtual ~ObjectBase ()
 Destructor. Emits aboutToDestroy, detaches from parent, and destroys children.
 
ObjectBaseparent () const
 Returns the parent object, if one. nullptr if none.
 
void setParent (ObjectBase *p)
 Sets the parent of this object. If the object already has a parent, it will be removed as a child from the old parent and added as a child to the new one.
 
const ObjectBaseListchildList () const
 Returns a list of children of this object.
 
template<typename... Args>
int registerSlot (Slot< Args... > *slot)
 Registers a slot with this object and assigns it an ID.
 
EventLoopeventLoop () const
 Returns the EventLoop this object is affiliated with.
 
void moveToThread (EventLoop *loop)
 Changes the EventLoop affinity of this object.
 
int startTimer (unsigned int intervalMs, bool singleShot=false)
 Starts a timer on this object's EventLoop.
 
void stopTimer (int timerId)
 Stops a timer previously started with startTimer().
 
template<typename... Args>
PROMEKI_NAMESPACE_BEGIN void connect (Signal< Args... > *signal, Slot< Args... > *slot)
 

Additional Inherited Members

- Public Types inherited from ObjectBase
using SlotVariantFunc = std::function< void(const VariantList &)>
 Function type for invoking a slot with a list of Variants.
 
- Static Public Member Functions inherited from ObjectBase
static const MetaInfometaInfo ()
 Returns the MetaInfo for the ObjectBase class.
 
template<typename... Args>
static void connect (Signal< Args... > *signal, Slot< Args... > *slot)
 connects a signal and slot together. This function assumes both the signal and slot exist in a ObjectBase or derived object
 
- Public Attributes inherited from ObjectBase
Signal< ObjectBase * > aboutToDestroySignal = Signal< ObjectBase * >(this, aboutToDestroySignalName)
 
- Static Public Attributes inherited from ObjectBase
static constexpr const charaboutToDestroySignalName = PROMEKI_STRINGIFY( aboutToDestroy ) "(" PROMEKI_STRINGIFY_ARGS( ObjectBase * ) ")"
 
static SignalMeta aboutToDestroySignalMeta = SignalMeta(metaInfo(), aboutToDestroySignalName)
 
- Protected Member Functions inherited from ObjectBase
ObjectBasesignalSender ()
 Returns the ObjectBase that emitted the signal currently being handled.
 
virtual void event (Event *e)
 Called by EventLoop to deliver events to this object.
 
virtual void timerEvent (TimerEvent *e)
 Called when a timer fires for this object.
 

Detailed Description

Manages multicast group membership for multi-stream scenarios.

MulticastManager tracks which sockets have joined which multicast groups, providing centralized management and cleanup. It supports both Any-Source Multicast (ASM) and Source-Specific Multicast (SSM).

Note
All managed sockets must remain valid for the lifetime of their memberships. MulticastManager does not take ownership of socket pointers.
Example
sock.setReuseAddress(true);
SocketAddress group(Ipv4Address(239, 0, 0, 1), 5004);
mgr.joinGroup(group, &sock);
// Later...
mgr.leaveAllGroups();
@ ReadWrite
Open for reading and writing.
Definition iodevice.h:37
IPv4 network address.
Definition ipv4address.h:51
Dynamic array container wrapping std::vector.
Definition list.h:40
Manages multicast group membership for multi-stream scenarios.
Definition multicastmanager.h:47
Network address with port number.
Definition socketaddress.h:50
static SocketAddress any(uint16_t port)
Returns INADDR_ANY with the given port.
Definition socketaddress.h:71
Datagram-oriented UDP socket with multicast support.
Definition udpsocket.h:47

Constructor & Destructor Documentation

◆ MulticastManager()

MulticastManager::MulticastManager ( ObjectBase parent = nullptr)

Constructs a MulticastManager.

Parameters
parentThe parent object, or nullptr.

Member Function Documentation

◆ isMemberOf()

bool MulticastManager::isMemberOf ( const SocketAddress group) const

Returns true if any socket is a member of the group.

Parameters
groupThe multicast group to check.
Returns
True if the group is active.

◆ joinGroup() [1/2]

Error MulticastManager::joinGroup ( const SocketAddress group,
UdpSocket socket 
)

Joins a multicast group on a socket.

Parameters
groupThe multicast group address.
socketThe UDP socket to join with.
Returns
Error::Ok on success, or an error on failure.

◆ joinGroup() [2/2]

Error MulticastManager::joinGroup ( const SocketAddress group,
UdpSocket socket,
const String iface 
)

Joins a multicast group on a specific interface.

Parameters
groupThe multicast group address.
socketThe UDP socket to join with.
ifaceThe network interface name (e.g. "eth0").
Returns
Error::Ok on success, or an error on failure.

◆ joinSourceGroup()

Error MulticastManager::joinSourceGroup ( const SocketAddress group,
const SocketAddress source,
UdpSocket socket 
)

Joins a Source-Specific Multicast group.

Subscribes to multicast traffic from a specific source only (IP_ADD_SOURCE_MEMBERSHIP).

Parameters
groupThe multicast group address.
sourceThe source address to accept traffic from.
socketThe UDP socket.
Returns
Error::Ok on success, or an error on failure.

◆ leaveGroup()

Error MulticastManager::leaveGroup ( const SocketAddress group,
UdpSocket socket 
)

Leaves a multicast group on a socket.

Parameters
groupThe multicast group address.
socketThe UDP socket to leave from.
Returns
Error::Ok on success, or an error on failure.

◆ leaveSourceGroup()

Error MulticastManager::leaveSourceGroup ( const SocketAddress group,
const SocketAddress source,
UdpSocket socket 
)

Leaves a Source-Specific Multicast group.

Parameters
groupThe multicast group address.
sourceThe source address.
socketThe UDP socket.
Returns
Error::Ok on success, or an error on failure.

◆ PROMEKI_SIGNAL() [1/2]

MulticastManager::PROMEKI_SIGNAL ( groupJoined  ,
SocketAddress   
)

Emitted when a multicast group is joined.

Signal:

◆ PROMEKI_SIGNAL() [2/2]

MulticastManager::PROMEKI_SIGNAL ( groupLeft  ,
SocketAddress   
)

Emitted when a multicast group is left.

Signal:

◆ setDefaultInterface()

void MulticastManager::setDefaultInterface ( const String iface)
inline

Sets the default network interface for joins.

Used when joinGroup() is called without an explicit interface. Only affects future joins, not existing memberships.

Parameters
ifaceThe interface name (e.g. "eth0").

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