|
ORE Studio 0.0.4
|
Manages client subscriptions to event notifications. More...
#include <subscription_manager.hpp>

Public Member Functions | |
| subscription_manager (const subscription_manager &)=delete | |
| subscription_manager & | operator= (const subscription_manager &)=delete |
| subscription_manager (subscription_manager &&)=delete | |
| subscription_manager & | operator= (subscription_manager &&)=delete |
| void | register_session (const session_id &id, notification_callback callback) |
| Register a new session with the subscription manager. | |
| void | unregister_session (const session_id &id) |
| Unregister a session from the subscription manager. | |
| bool | subscribe (const session_id &id, const std::string &event_type) |
| Subscribe a session to an event type. | |
| bool | unsubscribe (const session_id &id, const std::string &event_type) |
| Unsubscribe a session from an event type. | |
| std::size_t | notify (const std::string &event_type, std::chrono::system_clock::time_point timestamp) |
| Notify all subscribers of an event. | |
| std::size_t | subscriber_count (const std::string &event_type) const |
| Get the number of subscribers for an event type. | |
| std::size_t | session_count () const |
| Get the total number of registered sessions. | |
| std::vector< std::string > | get_subscriptions (const session_id &id) const |
| Get the event types a session is subscribed to. | |
Manages client subscriptions to event notifications.
This class tracks which clients are subscribed to which event types and provides the mechanism to broadcast notifications when events occur.
Thread Safety:
Usage:
| void register_session | ( | const session_id & | id, |
| notification_callback | callback | ||
| ) |
Register a new session with the subscription manager.
Must be called when a session successfully completes handshake.
| id | The unique session identifier (typically remote address). |
| callback | The callback to invoke for pushing notifications. |
| void unregister_session | ( | const session_id & | id | ) |
Unregister a session from the subscription manager.
Removes all subscriptions for this session. Should be called when a session disconnects.
| id | The session identifier to unregister. |
| bool subscribe | ( | const session_id & | id, |
| const std::string & | event_type | ||
| ) |
Subscribe a session to an event type.
| id | The session identifier. |
| event_type | The event type to subscribe to. |
| bool unsubscribe | ( | const session_id & | id, |
| const std::string & | event_type | ||
| ) |
Unsubscribe a session from an event type.
| id | The session identifier. |
| event_type | The event type to unsubscribe from. |
| std::size_t notify | ( | const std::string & | event_type, |
| std::chrono::system_clock::time_point | timestamp | ||
| ) |
Notify all subscribers of an event.
Invokes the notification callback for each session subscribed to the given event type. Failed notifications (callback returns false) are logged but do not affect other subscribers.
| event_type | The event type that occurred. |
| timestamp | The timestamp of the event. |
| std::size_t subscriber_count | ( | const std::string & | event_type | ) | const |
Get the number of subscribers for an event type.
| event_type | The event type to query. |
| std::size_t session_count | ( | ) | const |
Get the total number of registered sessions.
| std::vector< std::string > get_subscriptions | ( | const session_id & | id | ) | const |
Get the event types a session is subscribed to.
| id | The session identifier. |