| 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 API: native plugins compile against this header and are loaded with | ||
| 15 | // dlopen(). | ||
| 16 | // - Plugins call WarningHolder's static AddWarning/RemoveWarning by symbol. | ||
| 17 | // Data layout here is NOT plugin ABI, so members can change freely. Changing | ||
| 18 | // or removing a signature a plugin calls is: keep the old one as an overload | ||
| 19 | // (as Timers::addPeriodicTimer does) or bump FPP_PLUGIN_API_VERSION in | ||
| 20 | // Plugin.h. See .claude/PLUGIN-ABI.md for which plugins use what. | ||
| 21 | |||
| 22 | #include <chrono> | ||
| 23 | #include <list> | ||
| 24 | #include <map> | ||
| 25 | #include <string> | ||
| 26 | |||
| 27 | // Forward declaration only -- FPPWarning no longer derives from Json::Value, so | ||
| 28 | // this header does not need the (heavy) jsoncpp include. Code that serializes a | ||
| 29 | // warning calls toJsonValue(), whose definition (in Warnings.cpp) includes the | ||
| 30 | // real jsoncpp header. | ||
| 31 | namespace Json { | ||
| 32 | class Value; | ||
| 33 | } | ||
| 34 | |||
| 35 | constexpr int UNKNOWN_WARNING_ID = 0; | ||
| 36 | |||
| 37 | class FPPWarning { | ||
| 38 | public: | ||
| 39 | FPPWarning(int id, const std::string& message, const std::string& plugin); | ||
| 40 | |||
| 41 | 7740 | int id() const { return m_id; } | |
| 42 | 30370 | const std::string& message() const { return m_message; } | |
| 43 | 1021 | const std::string& plugin() const { return m_plugin; } | |
| 44 | |||
| 45 | // Extra key/value pairs attached to the warning (formerly the json "data" | ||
| 46 | // object). Kept as an ordered map so the serialized output is stable. | ||
| 47 | std::map<std::string, std::string> data; | ||
| 48 | |||
| 49 | std::chrono::steady_clock::time_point timeout; | ||
| 50 | |||
| 51 | // JSON representation written to warnings_full.json / published to events. | ||
| 52 | Json::Value toJsonValue() const; | ||
| 53 | |||
| 54 | private: | ||
| 55 | int m_id; | ||
| 56 | std::string m_message; | ||
| 57 | std::string m_plugin; | ||
| 58 | }; | ||
| 59 | |||
| 60 | class WarningListener { | ||
| 61 | public: | ||
| 62 | virtual void handleWarnings(const std::list<FPPWarning>& warnings) = 0; | ||
| 63 | }; | ||
| 64 | |||
| 65 | class WarningHolder { | ||
| 66 | public: | ||
| 67 | static void AddWarning(const std::string& w); | ||
| 68 | static void AddWarningTimeout(const std::string& w, int seconds); | ||
| 69 | static void RemoveWarning(const std::string& w); | ||
| 70 | |||
| 71 | static void AddWarning(int id, const std::string& w, const std::map<std::string, std::string>& data = {}); | ||
| 72 | |||
| 73 | // Convenience overload for a warning that offers a one-click "Fix" button in | ||
| 74 | // the web UI. fixUrl is a same-origin URL the button navigates to; fixText is | ||
| 75 | // the button label (e.g. "Reinstall All Plugins"). Both are carried in the | ||
| 76 | // warning's data map (keys "fixUrl"/"fixText") and rendered by updateWarnings() | ||
| 77 | // in www/js/fpp.js. | ||
| 78 | static void AddWarning(int id, const std::string& w, const std::string& fixUrl, const std::string& fixText); | ||
| 79 | static void AddWarningTimeout(int seconds, int id, const std::string& w, const std::map<std::string, std::string>& data = {}, const std::string& plugin = ""); | ||
| 80 | static void RemoveWarning(int id, const std::string& w, const std::string& plugin = ""); | ||
| 81 | static void RemoveAllWarnings(); | ||
| 82 | |||
| 83 | // An entry of a config file that couldn't be read -- a value of the wrong | ||
| 84 | // JSON type, which jsoncpp throws on -- and was skipped. Logs it and puts | ||
| 85 | // up a warning (id 73) for an hour; a load that still finds it raises it | ||
| 86 | // again. Loaders call this from their catch, so one bad entry is left out | ||
| 87 | // instead of terminating fppd. | ||
| 88 | static void InvalidConfigEntry(const std::string& file, const std::string& detail); | ||
| 89 | |||
| 90 | // Recompute the "A Log Level is set to Debug/Excessive" warnings from the | ||
| 91 | // current logger levels. Call after any change to log levels, whatever | ||
| 92 | // path it came in on (settings page, REST API, command socket). | ||
| 93 | static void UpdateLogLevelWarnings(); | ||
| 94 | |||
| 95 | static void AddWarningListener(WarningListener* l); | ||
| 96 | static void RemoveWarningListener(WarningListener* l); | ||
| 97 | |||
| 98 | static std::list<FPPWarning> GetWarnings(); | ||
| 99 | static void StartNotifyThread(); | ||
| 100 | static void StopNotifyThread(); | ||
| 101 | |||
| 102 | static void WriteWarningsFile(); | ||
| 103 | // For the crash handler only: replace the warnings files with this one | ||
| 104 | // message without taking warningsLock, which the crashed thread may hold. | ||
| 105 | static void WriteCrashedWarningsFile(int id, const std::string& message); | ||
| 106 | static void ClearWarningsFile(); | ||
| 107 | |||
| 108 | private: | ||
| 109 | static void WarningsThreadMain(); // main for notify thread | ||
| 110 | }; | ||
| 111 |