Message Bus

Publish and subscribe on messages on the Message Bus.

Example

#include <r8/core/message-bus.h>
using namespace R8;
class Hello
    : public Core::IMessage
{
public:
    const char* getMessage() const {
        return "Hello!";
    }

private:
    int getType() const override {
       return 1001; // note: less than 1000 are reserved for internal types.
    }

    const char* getTopic() const override {
        return "app/hello";
    }
};
Core::Context& ctx = Core::System::getContext();
ctx.messageBus.subscribe(this, "app/hello"); // this implements Core::IMessageListener.
ctx.messageBus.publish(Core::SharedPtr<Core::IMessage>(new Hello()));
void App::onMessage(Core::SharedPtr<Core::IMessage> message) {
    if (message->getType() == 1001) {
        LogInfo("%s", reinterpret_cast<Hello*>(message.get())->getMessage());
    }
}