25 friend void ::esphome::retry_handler(
const std::shared_ptr<RetryArgs> &args);
29 void set_timeout(
Component *component,
const std::string &name, uint32_t timeout, std::function<
void()> func);
41 void set_timeout(
Component *component,
const char *name, uint32_t timeout, std::function<
void()> func);
46 void set_interval(
Component *component,
const std::string &name, uint32_t interval, std::function<
void()> func);
58 void set_interval(
Component *component,
const char *name, uint32_t interval, std::function<
void()> func);
62 void set_retry(
Component *component,
const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts,
63 std::function<
RetryResult(uint8_t)> func,
float backoff_increase_factor = 1.0f);
64 void set_retry(
Component *component,
const char *name, uint32_t initial_wait_time, uint8_t max_attempts,
65 std::function<
RetryResult(uint8_t)> func,
float backoff_increase_factor = 1.0f);
78 void call(uint32_t now);
116 name_.static_name =
nullptr;
122 delete[]
name_.dynamic_name;
138 void set_name(
const char *name,
bool make_copy =
false) {
141 delete[]
name_.dynamic_name;
147 name_.static_name =
nullptr;
148 }
else if (make_copy) {
150 size_t len = strlen(name);
151 name_.dynamic_name =
new char[
len + 1];
152 memcpy(
name_.dynamic_name, name,
len + 1);
156 name_.static_name = name;
160 static bool cmp(
const std::unique_ptr<SchedulerItem> &a,
const std::unique_ptr<SchedulerItem> &b);
167 uint32_t
delay, std::function<
void()> func,
bool is_retry =
false);
171 uint8_t max_attempts, std::function<
RetryResult(uint8_t)> func,
float backoff_increase_factor);
185 inline const char *get_name_cstr_(
bool is_static_string,
const void *name_ptr) {
186 return is_static_string ?
static_cast<const char *
>(name_ptr) : static_cast<const std::string *>(name_ptr)->c_str();
190 bool cancel_item_(Component *component,
bool is_static_string,
const void *name_ptr,
SchedulerItem::Type type);
193 inline bool HOT matches_item_(
const std::unique_ptr<SchedulerItem> &item, Component *component,
const char *name_cstr,
195 if (item->component != component || item->type !=
type || (skip_removed && item->remove) ||
196 (match_retry && !item->is_retry)) {
199 const char *item_name = item->get_name();
200 if (item_name ==
nullptr) {
207 if (item_name == name_cstr) {
211 return strcmp(name_cstr, item_name) == 0;
215 void execute_item_(SchedulerItem *item, uint32_t now);
218 bool should_skip_item_(
const SchedulerItem *item)
const {
219 return item->remove || (item->component !=
nullptr && item->component->is_failed());
223 template<
typename Container>
224 bool has_cancelled_timeout_in_container_(
const Container &container, Component *component,
const char *name_cstr,
225 bool match_retry)
const {
226 for (
const auto &item : container) {
236 std::vector<std::unique_ptr<SchedulerItem>> items_;
237 std::vector<std::unique_ptr<SchedulerItem>> to_add_;
238#ifndef ESPHOME_THREAD_SINGLE
240 std::deque<std::unique_ptr<SchedulerItem>> defer_queue_;
244#ifdef ESPHOME_THREAD_MULTI_ATOMICS
255 std::atomic<uint32_t> last_millis_{0};
267#ifdef ESPHOME_THREAD_MULTI_ATOMICS
268 std::atomic<uint16_t> millis_major_{0};
270 uint16_t millis_major_{0};
void set_retry_common_(Component *component, bool is_static_string, const void *name_ptr, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> func, float backoff_increase_factor)
void set_timer_common_(Component *component, SchedulerItem::Type type, bool is_static_string, const void *name_ptr, uint32_t delay, std::function< void()> func, bool is_retry=false)
void set_retry(Component *component, const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> func, float backoff_increase_factor=1.0f)