Nameless Engine
|
#include <NodeNotificationBroadcaster.hpp>
Public Member Functions | |
NodeNotificationBroadcaster (const NodeNotificationBroadcaster &)=delete | |
NodeNotificationBroadcaster & | operator= (const NodeNotificationBroadcaster &)=delete |
void | broadcast (FunctionArgs &&... args) |
size_t | subscribe (const NodeFunction< FunctionReturnType(FunctionArgs...)> &callback) |
void | unsubscribe (size_t iBindingId) |
size_t | getSubscriberCount () |
![]() | |
NodeNotificationBroadcasterBase (const NodeNotificationBroadcasterBase &)=delete | |
NodeNotificationBroadcasterBase & | operator= (const NodeNotificationBroadcasterBase &)=delete |
Protected Member Functions | |
virtual void | onOwnerNodeSpawning (Node *pOwnerNode) override |
virtual void | onOwnerNodeDespawning (Node *pOwnerNode) override |
virtual void | onOwnerNodeSpawning (Node *pOwnerNode)=0 |
virtual void | onOwnerNodeDespawning (Node *pOwnerNode)=0 |
Private Member Functions | |
void | removeAllCallbacks () |
Private Attributes | |
std::pair< std::recursive_mutex, std::unordered_map< size_t, NodeFunction< FunctionReturnType(FunctionArgs...)> > > | mtxCallbacks |
std::pair< std::recursive_mutex, std::unordered_map< size_t, NodeFunction< FunctionReturnType(FunctionArgs...)> > > | mtxCallbacksToAdd |
std::pair< std::recursive_mutex, std::vector< size_t > > | mtxCallbacksToRemove |
std::pair< std::recursive_mutex, Node * > | mtxSpawnedOwnerNode |
std::atomic< size_t > | iAvailableBindingId {0} |
std::atomic_flag | bIsBroadcasting {} |
Friends | |
class | Node |
Implements publisher-subscriber pattern. Allows nodes to subscribe by specifying their callback functions via NodeFunction
and triggers them once the broadcast method is called.
|
inline |
Executes all registered (subscribed) callbacks.
args | Arguments to pass to subscribed callbacks. |
|
inline |
Returns the current estimated number of subscribers.
The returned number is called "estimated" because right now we don't know if some nodes that subscribed to this broadcaster have despawned or not, callbacks of despawned nodes are only removed in broadcast calls. The only thing that we can say for sure is that the actual number of spawned subscribers is either equal to the returned value or smaller than it.
|
inlineoverrideprotectedvirtual |
Called by the node, that owns this broadcaster, when it's despawning.
pOwnerNode | Node that owns this broadcaster. |
Implements ne::NodeNotificationBroadcasterBase.
|
inlineoverrideprotectedvirtual |
Called by the node, that owns this broadcaster, when it's spawning.
pOwnerNode | Spawned node that owns this broadcaster. |
Implements ne::NodeNotificationBroadcasterBase.
|
inlineprivate |
Removes all registered callbacks (including callbacks that are pending to be added/removed).
|
inline |
Adds the specified callback to be registered in the broadcaster so that the callback will be triggered on the next broadcast call.
callback | Callback to register. |
|
inline |
Removes a previously added callback (see subscribe) by its binding ID.
iBindingId | ID of the binding to remove. |
|
private |
Determines whether we are currently broadcasting or not.
|
private |
Stores the next free (available for use) binding ID.
|
private |
Stores map that should be used with the mutex. Map contains pairs of "binding ID" - "callback".
|
private |
Stores map that should be used with the mutex. Map contains pairs of "binding ID" - "callback" to add to mtxCallbacks.
|
private |
Stores array that should be used with the mutex. Array contains binding IDs to remove from mtxCallbacks.
|
private |
Information about the owner node.