Nicer TimerEventForwarder<>

This commit is contained in:
Pavel Kirienko
2014-03-10 11:01:43 +04:00
parent 2aa9d8cdb5
commit 38e43e58ad
+9 -4
View File
@@ -8,6 +8,7 @@
#include <uavcan/scheduler.hpp>
#include <uavcan/util/compile_time.hpp>
#include <uavcan/internal/linked_list.hpp>
#include <uavcan/internal/fatal_error.hpp>
namespace uavcan
{
@@ -63,21 +64,25 @@ class TimerEventForwarder : public Timer
Functor functor_;
public:
TimerEventForwarder(Scheduler& node)
: Timer(node)
, functor_()
{ }
TimerEventForwarder(Scheduler& node, Functor functor)
: Timer(node)
, functor_(functor)
{
assert(try_implicit_cast<bool>(functor, true));
}
{ }
const Functor& getFunctor() const { return functor_; }
void setFunctor(const Functor& functor) { functor_ = functor; }
void onTimerEvent(const TimerEvent& event)
{
if (try_implicit_cast<bool>(functor_, true))
functor_(event);
else
assert(0);
handleFatalError("Invalid timer functor");
}
};