Change C++ Notifier to allow std::function callback.

Also provide templated varags constructor for backwards compatibility and
ease of use.

Update PIDController to use new constructor, eliminating static function
CallCalculate().

Change-Id: Iaeae95aa5953f294f5debc5fc569ef6d4684f223
This commit is contained in:
Peter Johnson
2015-12-29 10:58:11 -08:00
parent b0de0b7386
commit 91a451f87a
7 changed files with 33 additions and 53 deletions

View File

@@ -5,16 +5,25 @@
/*----------------------------------------------------------------------------*/
#pragma once
#include <atomic>
#include <functional>
#include <thread>
#include "ErrorBase.h"
#include "HAL/cpp/priority_mutex.h"
#include <thread>
#include <atomic>
typedef void (*TimerEventHandler)(void *param);
typedef std::function<void()> TimerEventHandler;
class Notifier : public ErrorBase {
public:
Notifier(TimerEventHandler handler, void *param = nullptr);
explicit Notifier(TimerEventHandler handler);
template <typename Callable, typename Arg, typename... Args>
Notifier(Callable&& f, Arg&& arg, Args&&... args)
: Notifier(std::bind(std::forward<Callable>(f),
std::forward<Arg>(arg),
std::forward<Args>(args)...)) {}
virtual ~Notifier();
Notifier(const Notifier&) = delete;
@@ -42,8 +51,6 @@ class Notifier : public ErrorBase {
// address of the handler
TimerEventHandler m_handler;
// a parameter to pass to the handler
void *m_param;
// the relative time (either periodic or single)
double m_period = 0;
// absolute expiration time for the current event