Skip to content

Commit

Permalink
Add convenience methods for shared_ptr args
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Oct 30, 2024
1 parent 884253e commit 3817c9f
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Arduino.h>

#include <functional>
#include <memory>

namespace reactesp {

Expand Down Expand Up @@ -35,6 +36,16 @@ struct EventInterface {
virtual void add(EventLoop* event_loop) = 0;
virtual void remove(EventLoop* event_loop) = 0;
virtual void tick(EventLoop* event_loop) = 0;

virtual void add(std::shared_ptr<EventLoop> event_loop) {
add(event_loop.get());
}
virtual void remove(std::shared_ptr<EventLoop> event_loop) {
remove(event_loop.get());
}
virtual void tick(std::shared_ptr<EventLoop> event_loop) {
tick(event_loop.get());
}
};

/**
Expand Down Expand Up @@ -93,8 +104,13 @@ class TimedEvent : public Event {
enabled(true) {}

bool operator<(const TimedEvent& other) const;
void add(EventLoop* event_loop) override;
void remove(EventLoop* event_loop) override;
virtual void add(EventLoop* event_loop) override;
virtual void remove(EventLoop* event_loop) override;

using EventInterface::add;
using EventInterface::remove;
using EventInterface::tick;

uint32_t getTriggerTime() const {
return (last_trigger_time + interval) / 1000;
}
Expand Down Expand Up @@ -165,6 +181,10 @@ class UntimedEvent : public Event {

void add(EventLoop* event_loop) override;
void remove(EventLoop* event_loop) override;

using EventInterface::add;
using EventInterface::remove;
using EventInterface::tick;
};

/**
Expand Down

0 comments on commit 3817c9f

Please sign in to comment.