/* BROKER MODULE Copyright (C) 2017-2019 by Xose PĂ©rez */ #pragma once #if BROKER_SUPPORT #include #include #include enum class TBrokerType { SYSTEM, STATUS, SENSOR_READ, SENSOR_REPORT, 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