mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
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:
@@ -5,14 +5,23 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
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;
|
||||
@@ -34,8 +43,6 @@ class Notifier : public ErrorBase {
|
||||
void *m_notifier;
|
||||
// address of the handler
|
||||
TimerEventHandler m_handler;
|
||||
// a parameter to pass to the handler
|
||||
void *m_param;
|
||||
// the absolute expiration time
|
||||
double m_expirationTime = 0;
|
||||
// the relative time (either periodic or single)
|
||||
|
||||
Reference in New Issue
Block a user