MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ publish()

void Lila::EventBus::publish ( const StreamEvent event)

Publish an event to all subscribers of its type.

Parameters
eventThe event to publish

Definition at line 18 of file EventBus.cpp.

19{
20 std::vector<std::shared_ptr<Subscription>> active_subscribers;
21
22 {
23 std::lock_guard lock(m_mutex);
24 auto it = m_subscribers.find(event.type);
25 if (it == m_subscribers.end())
26 return;
27
28 auto& subscribers = it->second;
29 subscribers.erase(
30 std::remove_if(subscribers.begin(), subscribers.end(),
31 [&active_subscribers](const std::weak_ptr<Subscription>& weak) {
32 if (auto shared = weak.lock()) {
33 active_subscribers.push_back(shared);
34 return false;
35 }
36 return true;
37 }),
38 subscribers.end());
39 }
40
41 for (auto& subscriber : active_subscribers) {
42 subscriber->on_event(event);
43 }
44}
std::mutex m_mutex
Mutex for thread safety.
Definition EventBus.hpp:183
std::unordered_map< EventType, std::vector< std::weak_ptr< Subscription > > > m_subscribers
Subscribers by event type.
Definition EventBus.hpp:182

References m_mutex, m_subscribers, and Lila::StreamEvent::type.

Referenced by Lila::Server::cleanup_client(), Lila::Server::handle_client(), Lila::Server::start(), and Lila::Server::stop().

+ Here is the caller graph for this function: