The event bus acts as a mediator between event sources and event sinks. An event source, or producer, emits the events to a bus, and classes that have subscribed to events (consumers) will get notified. The pattern could be an instance of the mediator pattern. In an event bus implementation, we have the following:
- Producers: Classes that produce events
- Consumers: Classes that consume events
- Controllers: Classes that act as producers and consumers
In the implementation that follows, we have omitted the implementation of controllers. The following code implements an event bus:
//----------- EventBus.cpp #include <rxcpp/rx.hpp> #include <memory> #include <map> #include <algorithm> using namespace std; //---------- Event ...