| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 4 | * 2013-2022 by the Falcon Player Developers. | ||
| 5 | * | ||
| 6 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 7 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 8 | * file for descriptions of what files are covered by each license. | ||
| 9 | * | ||
| 10 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 11 | * included LICENSE.LGPL file. | ||
| 12 | */ | ||
| 13 | |||
| 14 | // PLUGIN ABI: native plugins compile against this header and are loaded with | ||
| 15 | // dlopen(), so parts of it are baked into binaries FPP did not build. | ||
| 16 | // - EventHandler's vtable: plugins call Publish() through MosquittoClient. | ||
| 17 | // - Events::AddCallback()/RemoveCallback() signatures (called by symbol). | ||
| 18 | // Any such change must bump FPP_PLUGIN_API_VERSION in Plugin.h. Without the | ||
| 19 | // bump, a plugin built against the previous header still loads and silently | ||
| 20 | // uses the old layout - FPP 10.2 shipped exactly that and crash-looped fppd. | ||
| 21 | // See .claude/PLUGIN-ABI.md for which plugins use what. | ||
| 22 | #include <ctime> | ||
| 23 | #include <functional> | ||
| 24 | #include <string> | ||
| 25 | #include <time.h> | ||
| 26 | |||
| 27 | #define MQTT_READY_TOPIC_NAME "ready" | ||
| 28 | |||
| 29 | class EventHandler { | ||
| 30 | public: | ||
| 31 | EventHandler(); | ||
| 32 | virtual ~EventHandler(); | ||
| 33 | |||
| 34 | virtual bool Publish(const std::string& topic, const std::string& data) = 0; | ||
| 35 | virtual bool Publish(const std::string& subTopic, const int valueconst) = 0; | ||
| 36 | |||
| 37 | virtual void RegisterCallback(const std::string& topic) = 0; | ||
| 38 | virtual void RemoveCallback(const std::string& topic) = 0; | ||
| 39 | |||
| 40 | virtual void PrepareForShutdown() = 0; | ||
| 41 | }; | ||
| 42 | |||
| 43 | class Events { | ||
| 44 | public: | ||
| 45 | static void Ready(); | ||
| 46 | |||
| 47 | static bool HasEventHandlers(); | ||
| 48 | static void AddEventHandler(EventHandler* handler); | ||
| 49 | static void RemoveEventHandler(EventHandler* handler); | ||
| 50 | |||
| 51 | static bool Publish(const std::string& topic, const std::string& data); | ||
| 52 | static bool Publish(const std::string& subTopic, const int valueconst); | ||
| 53 | |||
| 54 | static void AddCallback(const std::string& topic, std::function<void(const std::string& topic, const std::string& payload)>& callback); | ||
| 55 | static void RemoveCallback(const std::string& topic); | ||
| 56 | |||
| 57 | static void PrepareForShutdown(); | ||
| 58 | |||
| 59 | static void InvokeCallback(const std::string& topic, const std::string& topic_in, const std::string& payload); | ||
| 60 | |||
| 61 | private: | ||
| 62 | static void RunPublishThread(); | ||
| 63 | }; | ||
| 64 | |||
| 65 | class EventNotifier { | ||
| 66 | public: | ||
| 67 | int frequency; | ||
| 68 | time_t next_time = std::time(0); | ||
| 69 | virtual void notify() = 0; | ||
| 70 | 3 | EventNotifier(int freq) { this->frequency = freq; } | |
| 71 | ✗ | ~EventNotifier() {} | |
| 72 | }; | ||
| 73 |