The Event bus pattern
The Event bus acts as a intermediary 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 design pattern. In an Event bus implementation, we have the following archetypes
- Producers: Classes which produce events
- Consumers: Classes which consume events
- Controllers: Classes which act as producers and consumers
In the implementation that follows, we have omitted the implementation of Controllers. The following code implements a toy version of an Event bus:
//----------- EventBus.cpp #include <rxcpp/rx.hpp> #include <memory> #include <map> #include <algorithm> using namespace std; //---------- Event Information struct EVENT_INFO{ int id; int err_code; string description; EVENT_INFO() { id = err_code = 0 ; description ="default";} EVENT_INFO(int pid,int perr_code...