7#include "esp_heap_caps.h"
13static const char*
TAG =
"PLG_PRE";
17int as_int(
const std::map<std::string, std::string>& params,
18 const std::string& key,
int dflt)
20 auto it = params.find(key);
21 if (it == params.end())
return dflt;
22 return std::atoi(it->second.c_str());
40 int min_pct = as_int(spec.
params,
"min_pct", 0);
56 auto s = p->getChargeStatus();
64 int min_kb = as_int(spec.
params,
"kb", 0);
65 size_t free_b = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
66 return (free_b >=
static_cast<size_t>(min_kb) * 1024)
72 int min_kb = as_int(spec.
params,
"kb", 0);
73 size_t free_b = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
74 return (free_b >=
static_cast<size_t>(min_kb) * 1024)
88 if (spec.
name ==
"wifi_connected")
return prereq_wifi_connected(spec);
89 if (spec.
name ==
"time_synced")
return prereq_time_synced(spec);
90 if (spec.
name ==
"battery_min")
return prereq_battery_min(spec);
91 if (spec.
name ==
"usb_connected")
return prereq_usb_connected(spec);
92 if (spec.
name ==
"not_charging")
return prereq_not_charging(spec);
93 if (spec.
name ==
"min_free_psram")
return prereq_min_free_psram(spec);
94 if (spec.
name ==
"min_free_dram")
return prereq_min_free_dram(spec);
95 if (spec.
name ==
"unlocked")
return prereq_unlocked(spec);
96 LOG_W(
TAG,
"unknown prerequisite '%s' - treating as soft-pass", spec.
name.c_str());
100void release_one(
const std::string& prereq_name)
102 if (prereq_name ==
"wifi_connected") {
111 std::string& out_failed_name,
112 std::string& out_on_fail)
120 out_failed_name = spec.name;
121 out_on_fail = spec.on_fail.empty() ?
"abort" : spec.on_fail;
122 LOG_W(
TAG,
"prerequisite '%s' failed for %s (on_fail=%s)",
123 spec.name.c_str(), plugin.
id().c_str(), out_on_fail.c_str());
Walks the prerequisites list of a plugin manifest before plugin_on_enter.
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_W(tag, fmt,...)
std::vector< std::string > acquired_prereqs
const std::string & id() const noexcept
const PluginManifest & manifest() const noexcept
static PrereqResult walk(Plugin &plugin, std::string &out_failed_name, std::string &out_on_fail)
Walk the plugin's prerequisite list in order. Marks acquired resources on the Plugin so release() can...
static void release(Plugin &plugin)
Release every resource the plugin acquired during walk(), in reverse order of acquisition.
void release()
Releases a previously acquired WiFi hold.
bool acquire()
Acquires a hold on the WiFi connection for a plugin/host caller.
static WifiHandlers & instance()
Returns singleton Wi-Fi handlers instance.
IPowerManager * getPowerManagerInstance()
Returns the singleton power manager instance.
IRtc * getRtcInstance()
Returns the singleton RTC service instance.
std::vector< PrerequisiteSpec > prerequisites
std::map< std::string, std::string > params