2022-06-09 08:16:51 +03:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
2022-06-10 15:38:54 +03:00
|
|
|
#include <vector>
|
2022-06-09 08:16:51 +03:00
|
|
|
|
|
|
|
|
#include <wpi/FunctionExtras.h>
|
|
|
|
|
|
|
|
|
|
namespace frc {
|
2023-07-23 17:22:04 -04:00
|
|
|
/** A declarative way to bind a set of actions to a loop and execute them when
|
|
|
|
|
* the loop is polled. */
|
2022-06-09 08:16:51 +03:00
|
|
|
class EventLoop {
|
|
|
|
|
public:
|
|
|
|
|
EventLoop();
|
|
|
|
|
|
2022-11-07 12:30:03 -05:00
|
|
|
EventLoop(const EventLoop&) = delete;
|
|
|
|
|
EventLoop& operator=(const EventLoop&) = delete;
|
|
|
|
|
|
2022-06-09 08:16:51 +03:00
|
|
|
/**
|
2023-07-23 17:22:04 -04:00
|
|
|
* Bind a new action to run when the loop is polled.
|
2022-06-09 08:16:51 +03:00
|
|
|
*
|
|
|
|
|
* @param action the action to run.
|
|
|
|
|
*/
|
2022-11-28 23:48:48 +02:00
|
|
|
void Bind(wpi::unique_function<void()> action);
|
2022-06-09 08:16:51 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Poll all bindings.
|
|
|
|
|
*/
|
|
|
|
|
void Poll();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear all bindings.
|
|
|
|
|
*/
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
|
|
private:
|
2022-11-28 23:48:48 +02:00
|
|
|
std::vector<wpi::unique_function<void()>> m_bindings;
|
2022-06-09 08:16:51 +03:00
|
|
|
};
|
|
|
|
|
} // namespace frc
|