From dde61aad32d729357ee442aaf0a4f18c3508d8e4 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sat, 20 Jul 2019 22:57:16 -0700 Subject: [PATCH] Remove TimerEventHandler typedef from Notifier class (#1767) Using std::function directly makes it much clearer to the user what kind of function Notifier expects. The Doxygen comments already say what the function is used for, so the typedef just discards useful information. --- wpilibc/src/main/native/cpp/Notifier.cpp | 6 +++--- wpilibc/src/main/native/include/frc/Notifier.h | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/wpilibc/src/main/native/cpp/Notifier.cpp b/wpilibc/src/main/native/cpp/Notifier.cpp index 19ca35ba85..9b5d3a8282 100644 --- a/wpilibc/src/main/native/cpp/Notifier.cpp +++ b/wpilibc/src/main/native/cpp/Notifier.cpp @@ -17,7 +17,7 @@ using namespace frc; -Notifier::Notifier(TimerEventHandler handler) { +Notifier::Notifier(std::function handler) { if (handler == nullptr) wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr"); m_handler = handler; @@ -33,7 +33,7 @@ Notifier::Notifier(TimerEventHandler handler) { uint64_t curTime = HAL_WaitForNotifierAlarm(notifier, &status); if (curTime == 0 || status != 0) break; - TimerEventHandler handler; + std::function handler; { std::scoped_lock lock(m_processMutex); handler = m_handler; @@ -90,7 +90,7 @@ Notifier& Notifier::operator=(Notifier&& rhs) { return *this; } -void Notifier::SetHandler(TimerEventHandler handler) { +void Notifier::SetHandler(std::function handler) { std::scoped_lock lock(m_processMutex); m_handler = handler; } diff --git a/wpilibc/src/main/native/include/frc/Notifier.h b/wpilibc/src/main/native/include/frc/Notifier.h index 47380bce09..d6c14f3afe 100644 --- a/wpilibc/src/main/native/include/frc/Notifier.h +++ b/wpilibc/src/main/native/include/frc/Notifier.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -21,8 +21,6 @@ namespace frc { -using TimerEventHandler = std::function; - class Notifier : public ErrorBase { public: /** @@ -31,7 +29,7 @@ class Notifier : public ErrorBase { * @param handler The handler is called at the notification time which is set * using StartSingle or StartPeriodic. */ - explicit Notifier(TimerEventHandler handler); + explicit Notifier(std::function handler); template Notifier(Callable&& f, Arg&& arg, Args&&... args) @@ -51,7 +49,7 @@ class Notifier : public ErrorBase { * * @param handler Handler */ - void SetHandler(TimerEventHandler handler); + void SetHandler(std::function handler); /** * Register for single event notification. @@ -108,7 +106,7 @@ class Notifier : public ErrorBase { std::atomic m_notifier{0}; // Address of the handler - TimerEventHandler m_handler; + std::function m_handler; // The absolute expiration time double m_expirationTime = 0;