/* BROKER MODULE Copyright (C) 2017-2019 by Xose PĂ©rez */ #pragma once #if BROKER_SUPPORT #include #include #include enum class TBrokerType { System, Status, SensorRead, SensorReport, Datetime, Config }; template using TBrokerCallback = std::function; template using TBrokerCallbacks = std::vector>; template struct TBroker { static TBrokerCallbacks callbacks; static void Register(TBrokerCallback callback) { callbacks.push_back(callback); } static void Publish(TArgs... args) { for (auto& callback : callbacks) { callback(args...); } } }; template TBrokerCallbacks TBroker::callbacks; // --- Some known types. Bind them here to avoid .ino screwing with order --- using StatusBroker = TBroker; using SensorReadBroker = TBroker; using SensorReportBroker = TBroker; using ConfigBroker = TBroker; #endif // BROKER_SUPPORT == 1