[wpiutil] Split C++ header files

This commit is contained in:
Peter Johnson
2026-01-04 10:22:33 -08:00
parent a7f71c9434
commit f08258f784
97 changed files with 727 additions and 718 deletions

View File

@@ -5,7 +5,7 @@
#pragma once
#include "wpi/math/geometry/Pose3d.hpp"
#include "wpi/util/RawFrame.h"
#include "wpi/util/RawFrame.hpp"
#include "wpi/util/SymbolExports.hpp"
#include "wpi/util/json_fwd.hpp"

View File

@@ -10,7 +10,8 @@
#include "Handle.hpp"
#include "Instance.hpp"
#include "Notifier.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/string.hpp"
#include "wpi/util/timestamp.hpp"
using namespace wpi::cs;

View File

@@ -5,7 +5,7 @@
#pragma once
#include "wpi/cs/cscore_c.h"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
namespace wpi::cs {
@@ -27,8 +27,8 @@ class Handle {
};
enum { kIndexMax = 0xffff };
Handle(CS_Handle handle) : m_handle(handle) {} // NOLINT
operator CS_Handle() const { return m_handle; }
Handle(CS_Handle handle) : m_handle(handle) {} // NOLINT
operator CS_Handle() const { return m_handle; } // NOLINT
Handle(int index, Type type) {
if (index < 0) {

View File

@@ -18,9 +18,9 @@
#include "Telemetry.hpp"
#include "c_util.hpp"
#include "wpi/net/TCPConnector.h"
#include "wpi/util/MemAlloc.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/string.hpp"
#include "wpi/util/timestamp.hpp"
using namespace wpi::cs;

View File

@@ -23,7 +23,7 @@
#include "wpi/util/SmallString.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/fmt/raw_ostream.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/string.hpp"
using namespace wpi::cs;

View File

@@ -9,6 +9,7 @@
#include "Instance.hpp"
#include "wpi/cs/cscore_raw.h"
#include "wpi/util/string.hpp"
using namespace wpi::cs;

View File

@@ -9,7 +9,8 @@
#include "Instance.hpp"
#include "Notifier.hpp"
#include "wpi/cs/cscore_raw.h"
#include "wpi/util/timestamp.h"
#include "wpi/util/string.hpp"
#include "wpi/util/timestamp.hpp"
using namespace wpi::cs;

View File

@@ -12,6 +12,7 @@
#include "c_util.hpp"
#include "wpi/util/SmallString.hpp"
#include "wpi/util/json.hpp"
#include "wpi/util/string.hpp"
using namespace wpi::cs;

View File

@@ -16,7 +16,7 @@
#include "Telemetry.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/json.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::cs;

View File

@@ -9,6 +9,7 @@
#include "c_util.hpp"
#include "wpi/cs/cscore_cpp.hpp"
#include "wpi/util/MemAlloc.hpp"
#include "wpi/util/string.hpp"
using namespace wpi::cs;

View File

@@ -14,6 +14,7 @@
#include "wpi/cs/cscore_cpp.hpp"
#include "wpi/util/MemAlloc.hpp"
#include "wpi/util/SmallString.hpp"
#include "wpi/util/string.hpp"
static CS_Event ConvertToC(const wpi::cs::RawEvent& rawEvent) {
CS_Event event;

View File

@@ -4,13 +4,11 @@
#pragma once
#include <functional>
#include <opencv2/core/mat.hpp>
#include "wpi/cs/cscore_oo.hpp"
#include "wpi/cs/cscore_raw.h"
#include "wpi/util/RawFrame.h"
#include "wpi/util/RawFrame.hpp"
namespace wpi::cs {
/**

View File

@@ -11,6 +11,7 @@
// NOLINTBEGIN
#ifdef __cplusplus
#include "wpi/cs/cscore_oo.hpp"
#include "wpi/util/RawFrame.hpp"
#endif
#ifdef __cplusplus

View File

@@ -3,7 +3,7 @@
// the WPILib BSD license file in the root directory of this project.
#include "wpi/cs/cscore_runloop.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
static wpi::util::Event& GetInstance() {
static wpi::util::Event event;

View File

@@ -34,12 +34,10 @@
#include "Telemetry.hpp"
#include "UsbUtil.hpp"
#include "wpi/cs/cscore_cpp.hpp"
#include "wpi/util/MemAlloc.hpp"
#include "wpi/util/SmallString.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/fs.hpp"
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::cs;

View File

@@ -5,7 +5,7 @@
#import "UsbCameraDelegate.hpp"
#include "UsbCameraImpl.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
@implementation UsbCameraDelegate

View File

@@ -9,7 +9,7 @@
#include <vector>
#include <string>
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "Handle.hpp"

View File

@@ -3,7 +3,7 @@
// the WPILib BSD license file in the root directory of this project.
#include "wpi/cs/cscore_runloop.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
static wpi::util::Event& GetInstance() {
static wpi::util::Event event;

View File

@@ -38,7 +38,7 @@
#include "wpi/util/MemAlloc.hpp"
#include "wpi/util/SmallString.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
#pragma comment(lib, "Mfplat.lib")
#pragma comment(lib, "Mf.lib")

View File

@@ -17,7 +17,8 @@
#include "wpi/util/Logger.hpp"
#include "wpi/util/SmallString.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/string.hpp"
#include "wpi/util/timestamp.hpp"
using namespace wpi::log;

View File

@@ -26,6 +26,7 @@
#include "wpi/util/Logger.hpp"
#include "wpi/util/fs.hpp"
#include "wpi/util/string.hpp"
using namespace wpi::log;

View File

@@ -9,6 +9,7 @@
#include <vector>
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/string.hpp"
using namespace wpi::log;

View File

@@ -19,7 +19,6 @@
#include <vector>
#include <version>
#include "wpi/datalog/DataLog_c.h"
#include "wpi/util/DenseMap.hpp"
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/StringMap.hpp"
@@ -27,7 +26,7 @@
#include "wpi/util/protobuf/Protobuf.hpp"
#include "wpi/util/string.h"
#include "wpi/util/struct/Struct.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
namespace wpi::util {
class Logger;

View File

@@ -42,7 +42,7 @@ update_init = [
]
scan_headers_ignore = [
# wpi/datalog
"wpi/datalog/DataLog_c.h",
"wpi/datalog/DataLog.h",
"wpi/datalog/DataLogReaderThread.hpp",
"wpi/datalog/FileLogger.hpp",
]
@@ -59,5 +59,5 @@ DataLogBackgroundWriter = "wpi/datalog/DataLogBackgroundWriter.hpp"
DataLogReader = "wpi/datalog/DataLogReader.hpp"
# DataLogReaderThread = "wpi/datalog/DataLogReaderThread.hpp"
DataLogWriter = "wpi/datalog/DataLogWriter.hpp"
# DataLog_c = "wpi/datalog/DataLog_c.h"
# FileLogger = "wpi/datalog/FileLogger.hpp"
# DataLog_c = "wpi/datalog/DataLog.h"
# FileLogger = "wpi/datalog/FileLogger.hpp"

View File

@@ -22,7 +22,7 @@
#include "wpi/util/fs.hpp"
#include "wpi/util/json.hpp"
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::glass;

View File

@@ -35,9 +35,7 @@
#include "wpi/glass/support/EnumSetting.hpp"
#include "wpi/glass/support/ExtraGuiWidgets.hpp"
#include "wpi/util/Signal.h"
#include "wpi/util/SmallString.hpp"
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::glass;

View File

@@ -18,7 +18,7 @@
#include "wpi/nt/ntcore_cpp.hpp"
#include "wpi/util/StringMap.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
using namespace wpi;

View File

@@ -11,7 +11,7 @@
#include "org_wpilib_hardware_hal_AlertJNI.h"
#include "wpi/hal/Alert.h"
#include "wpi/util/jni_util.hpp"
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
using namespace wpi::hal;
using namespace wpi::util::java;

View File

@@ -7,6 +7,7 @@
#include <string_view>
#include "wpi/hal/Notifier.h"
#include "wpi/util/string.hpp"
/**
* Sets the name of a notifier.

View File

@@ -7,6 +7,7 @@
#include <string_view>
#include "wpi/hal/UsageReporting.h"
#include "wpi/util/string.hpp"
/**
* Reports usage of a resource of interest. Repeated calls for the same

View File

@@ -7,7 +7,7 @@
#include <stdint.h>
#include "wpi/hal/Types.h"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
/* General Handle Data Layout
* Bits 0-15: Handle Index

View File

@@ -16,7 +16,7 @@
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/hal/simulation/AlertData.h"
#include "wpi/util/mutex.hpp"
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
namespace {
struct Alert {

View File

@@ -14,7 +14,7 @@
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/util/DenseMap.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::hal;

View File

@@ -14,7 +14,7 @@
#include "NotifierInternal.hpp"
#include "wpi/hal/simulation/NotifierData.h"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
static std::atomic<bool> programStarted{false};
static std::atomic<int64_t> programState{0};

View File

@@ -26,8 +26,9 @@
#include "wpi/util/SafeThread.hpp"
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/priority_queue.hpp"
#include "wpi/util/string.hpp"
namespace {
struct Notifier {

View File

@@ -14,6 +14,7 @@
#include "DriverStationDataInternal.hpp"
#include "wpi/hal/DashboardOpMode.hpp"
#include "wpi/hal/DriverStationTypes.h"
#include "wpi/util/string.hpp"
using namespace wpi::hal;

View File

@@ -5,6 +5,7 @@
#include <string>
#include "RoboRioDataInternal.hpp"
#include "wpi/util/string.hpp"
using namespace wpi::hal;

View File

@@ -16,7 +16,7 @@
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/hal/simulation/AlertData.h"
#include "wpi/util/mutex.hpp"
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
namespace {
struct Alert {

View File

@@ -28,7 +28,7 @@
#include "wpi/util/circular_buffer.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::hal;

View File

@@ -14,7 +14,7 @@
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/util/DenseMap.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::hal;

View File

@@ -39,8 +39,8 @@
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/condition_variable.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/string.h"
#include "wpi/util/timestamp.h"
#include "wpi/util/string.hpp"
#include "wpi/util/timestamp.hpp"
static_assert(sizeof(int32_t) >= sizeof(int),
"WPILIB_NetworkComm status variable is larger than 32 bits");

View File

@@ -12,25 +12,15 @@
#include <atomic>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <memory>
#include <thread>
#include <utility>
#include "CANInternal.hpp"
#include "HALInitializer.hpp"
#include "HALInternal.hpp"
#include "SystemServerInternal.hpp"
#include "wpi/hal/DriverStation.h"
#include "wpi/hal/Errors.h"
#include "wpi/hal/Notifier.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/MemoryBuffer.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/fs.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::hal;

View File

@@ -19,8 +19,9 @@
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/util/SafeThread.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/priority_queue.hpp"
#include "wpi/util/string.hpp"
namespace {
struct Notifier {

View File

@@ -12,7 +12,7 @@
#include "wpi/nt/NetworkTableInstance.hpp"
#include "wpi/nt/StringTopic.hpp"
#include "wpi/util/StringMap.hpp"
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
namespace {
struct SystemServerUsageReporting {

View File

@@ -19,12 +19,10 @@
#include "wpi/nt/DoubleArrayTopic.hpp"
#include "wpi/nt/NetworkTableInstance.hpp"
#include "wpi/nt/ntcore.h"
#include "wpi/nt/ntcore_c.h"
#include "wpi/nt/ntcore_cpp.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
void bench();
void bench2();

View File

@@ -8,6 +8,7 @@
#include "Value_internal.hpp"
#include "wpi/nt/ntcore_cpp.hpp"
#include "wpi/util/string.hpp"
using namespace wpi::nt;

View File

@@ -8,6 +8,7 @@
#include "Value_internal.hpp"
#include "wpi/nt/ntcore_cpp.hpp"
#include "wpi/util/string.hpp"
using namespace wpi::nt;

View File

@@ -5,7 +5,7 @@
#pragma once
#include "wpi/nt/ntcore_c.h"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
namespace wpi::nt {
@@ -33,7 +33,7 @@ class Handle {
enum { kIndexMax = 0xfffff };
constexpr explicit Handle(NT_Handle handle) : m_handle(handle) {}
constexpr operator NT_Handle() const { return m_handle; }
constexpr operator NT_Handle() const { return m_handle; } // NOLINT
constexpr NT_Handle handle() const { return m_handle; }

View File

@@ -13,16 +13,13 @@
#include <fmt/format.h>
#include "Handle.hpp"
#include "Log.hpp"
#include "Message.hpp"
#include "NetworkInterface.hpp"
#include "WireConnection.hpp"
#include "WireEncoder.hpp"
#include "wpi/nt/NetworkTableValue.hpp"
#include "wpi/util/Logger.hpp"
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::nt;
using namespace wpi::nt::net;

View File

@@ -13,7 +13,7 @@
#include "wpi/util/Logger.hpp"
#include "wpi/util/SpanExtras.hpp"
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::nt;
using namespace wpi::nt::net;

View File

@@ -10,16 +10,14 @@
#include <cstdlib>
#include <cstring>
#include <string_view>
#include <utility>
#include <vector>
#include "Value_internal.hpp"
#include "wpi/nt/ntcore.h"
#include "wpi/nt/ntcore_cpp.hpp"
#include "wpi/util/MemAlloc.hpp"
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/json.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/string.hpp"
using namespace wpi::nt;

View File

@@ -10,7 +10,7 @@
#include "net/WireDecoder.hpp"
#include "server/ServerStorage.hpp"
#include "server/ServerTopic.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::nt::server;

View File

@@ -8,7 +8,6 @@
#include <cassert>
#include <functional>
#include <memory>
#include <optional>
#include <span>
#include <string>

View File

@@ -10,7 +10,7 @@
#include "TestPrinters.hpp"
#include "wpi/nt/ntcore_cpp.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/mutex.hpp"
class ConnectionListenerTest : public ::testing::Test {

View File

@@ -13,8 +13,7 @@
#include "ValueMatcher.hpp"
#include "wpi/nt/ntcore_c.h"
#include "wpi/nt/ntcore_cpp.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/json.hpp"
#include "wpi/util/Synchronization.hpp"
class TopicListenerTest : public ::testing::Test {
public:

View File

@@ -8,8 +8,7 @@
#include "ValueMatcher.hpp"
#include "wpi/nt/ntcore_c.h"
#include "wpi/nt/ntcore_cpp.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
using ::testing::_;
using ::testing::AnyNumber;

View File

@@ -13,6 +13,7 @@
#include "TestPrinters.hpp"
#include "Value_internal.hpp"
#include "wpi/nt/NetworkTableValue.hpp"
#include "wpi/util/string.hpp"
using namespace std::string_view_literals;

View File

@@ -8,6 +8,7 @@
#include <ctime>
#include <random>
#include <string>
#include <string_view>
#include <vector>
#include <fmt/chrono.h>
@@ -20,6 +21,7 @@
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/fs.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/string.hpp"
using namespace wpi;

View File

@@ -32,6 +32,7 @@
#include "wpi/halsim/gui/HALSimGui.hpp"
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/string.hpp"
using namespace halsimgui;

View File

@@ -8,11 +8,9 @@
#include <string>
#include <string_view>
#include "wpi/hal/DriverStation.h"
#include "wpi/hal/Extensions.h"
#include "wpi/hal/Ports.h"
#include "wpi/hal/simulation/DriverStationData.h"
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/string.hpp"
#define REGISTER(halsim, jsonid, ctype, haltype) \
HALSIM_RegisterDriverStation##halsim##Callback( \

View File

@@ -8,7 +8,7 @@
#include <string>
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
using namespace wpi;

View File

@@ -34,12 +34,10 @@
#include "wpi/util/DenseMap.hpp"
#include "wpi/util/EventVector.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/condition_variable.hpp"
#include "wpi/util/json.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/string.h"
#include "wpi/util/struct/Struct.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/string.hpp"
#include "wpi/util/timestamp.hpp"
using namespace wpi;

View File

@@ -14,7 +14,7 @@
#include "wpi/hal/UsageReporting.hpp"
#include "wpi/math/util/MathUtil.hpp"
#include "wpi/util/MathExtras.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi;

View File

@@ -6,7 +6,7 @@
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/hal/DriverStation.h"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
using namespace wpi::internal;

View File

@@ -8,7 +8,7 @@
#include <vector>
#include "wpi/hal/simulation/AlertData.h"
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
using namespace wpi;
using namespace wpi::sim;

View File

@@ -10,6 +10,8 @@
#include "wpi/hal/DriverStation.h"
#include "wpi/hal/simulation/DriverStationData.h"
#include "wpi/hal/simulation/MockHooks.h"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/string.hpp"
using namespace wpi;
using namespace wpi::sim;

View File

@@ -8,6 +8,7 @@
#include <string>
#include "wpi/hal/simulation/RoboRioData.h"
#include "wpi/util/string.hpp"
using namespace wpi;
using namespace wpi::sim;

View File

@@ -17,7 +17,7 @@
#include "wpi/datalog/FileLogger.hpp"
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/framework/RobotBase.hpp"
#include "wpi/hal/UsageReporting.h"
#include "wpi/hal/UsageReporting.hpp"
#include "wpi/nt/NetworkTableInstance.hpp"
#include "wpi/system/Errors.hpp"
#include "wpi/system/Filesystem.hpp"
@@ -26,7 +26,7 @@
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/fs.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi;

View File

@@ -11,6 +11,7 @@
#include "wpi/hal/HALBase.h"
#include "wpi/hal/Power.h"
#include "wpi/system/Errors.hpp"
#include "wpi/util/string.hpp"
using namespace wpi;

View File

@@ -27,7 +27,7 @@
#include "wpi/system/Notifier.hpp"
#include "wpi/system/WPILibVersion.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
static_assert(wpi::RuntimeType::kRoboRIO ==
static_cast<wpi::RuntimeType>(HAL_Runtime_RoboRIO));

View File

@@ -8,7 +8,7 @@
#include <thread>
#include "wpi/hal/DriverStationTypes.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
namespace wpi::internal {
/**

View File

@@ -11,6 +11,7 @@
#include "wpi/simulation/DriverStationSim.hpp"
#include "wpi/simulation/SimHooks.hpp"
#include "wpi/util/Color.hpp"
#include "wpi/util/string.hpp"
namespace {
class OpModeRobotTest : public ::testing::Test {

View File

@@ -9,7 +9,7 @@
#include "wpi/units/time.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::math;

View File

@@ -4,7 +4,7 @@
#pragma once
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#ifdef __cplusplus

View File

@@ -27,7 +27,7 @@
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
namespace uv = wpi::net::uv;

View File

@@ -18,7 +18,7 @@
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
namespace uv = wpi::net::uv;

View File

@@ -40,7 +40,15 @@ def wpiutil_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], inclu
class_name = "Synchronization",
yml_file = "semiwrap/Synchronization.yml",
header_root = "$(execpath :robotpy-native-wpiutil.copy_headers)",
header_file = "$(execpath :robotpy-native-wpiutil.copy_headers)/wpi/util/Synchronization.h",
header_file = "$(execpath :robotpy-native-wpiutil.copy_headers)/wpi/util/Synchronization.hpp",
tmpl_class_names = [],
trampolines = [],
),
struct(
class_name = "RawFrame_c",
yml_file = "semiwrap/RawFrame_c.yml",
header_root = "$(execpath :robotpy-native-wpiutil.copy_headers)",
header_file = "$(execpath :robotpy-native-wpiutil.copy_headers)/wpi/util/RawFrame.h",
tmpl_class_names = [],
trampolines = [],
),
@@ -48,7 +56,7 @@ def wpiutil_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], inclu
class_name = "RawFrame",
yml_file = "semiwrap/RawFrame.yml",
header_root = "$(execpath :robotpy-native-wpiutil.copy_headers)",
header_file = "$(execpath :robotpy-native-wpiutil.copy_headers)/wpi/util/RawFrame.h",
header_file = "$(execpath :robotpy-native-wpiutil.copy_headers)/wpi/util/RawFrame.hpp",
tmpl_class_names = [],
trampolines = [],
),

View File

@@ -2,7 +2,7 @@
// 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.
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include <algorithm>
#include <atomic>

View File

@@ -7,12 +7,12 @@
#include <jni.h>
#include "org_wpilib_util_WPIUtilJNI.h"
#include "wpi/util/RawFrame.h"
#include "wpi/util/RawFrame.hpp"
#include "wpi/util/RuntimeCheck.h"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/jni_util.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
using namespace wpi::util::java;

View File

@@ -2,11 +2,9 @@
// 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.
#include "wpi/util/timestamp.h"
#include "wpi/util/timestamp.hpp"
#include <atomic>
#include <optional>
#include <utility>
#ifdef _WIN32
#include <windows.h>
@@ -19,8 +17,6 @@
#include <cstdio>
#include "wpi/util/print.hpp"
// offset in microseconds
static uint64_t time_since_epoch() noexcept {
#ifdef _WIN32

View File

@@ -5,7 +5,7 @@
#pragma once
#include "wpi/util/SmallVector.hpp"
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::util {

View File

@@ -4,22 +4,8 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
#include <concepts>
#include <cstddef>
#else
#include <stddef.h> // NOLINT
#endif
#ifdef WPI_RAWFRAME_JNI
#include "wpi/util/jni_util.hpp"
#endif
// NOLINT
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@@ -85,79 +71,3 @@ void WPI_SetRawFrameData(WPI_RawFrame* frame, void* data, size_t size,
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
namespace wpi::util {
struct RawFrame : public WPI_RawFrame {
RawFrame() {
data = nullptr;
freeFunc = nullptr;
freeCbData = nullptr;
capacity = 0;
size = 0;
pixelFormat = WPI_PIXFMT_UNKNOWN;
width = 0;
height = 0;
timestamp = 0;
timestampSrc = WPI_TIMESRC_UNKNOWN;
}
RawFrame(const RawFrame&) = delete;
RawFrame& operator=(const RawFrame&) = delete;
RawFrame(RawFrame&& rhs) noexcept : WPI_RawFrame{rhs} {
rhs.data = nullptr;
rhs.freeFunc = nullptr;
rhs.freeCbData = nullptr;
rhs.capacity = 0;
rhs.size = 0;
}
RawFrame& operator=(RawFrame&& rhs) noexcept {
*static_cast<WPI_RawFrame*>(this) = rhs;
rhs.data = nullptr;
rhs.freeFunc = nullptr;
rhs.freeCbData = nullptr;
rhs.capacity = 0;
rhs.size = 0;
return *this;
}
void SetData(void* data, size_t size, size_t capacity, void* cbdata,
void (*freeFunc)(void* cbdata, void* data, size_t capacity)) {
WPI_SetRawFrameData(this, data, size, capacity, cbdata, freeFunc);
}
// returns true if the frame data was allocated/reallocated
bool Reserve(size_t size) {
return WPI_AllocateRawFrameData(this, size) != 0;
}
~RawFrame() { WPI_FreeRawFrameData(this); }
};
#ifdef WPI_RAWFRAME_JNI
template <std::same_as<wpi::util::RawFrame> T>
void SetFrameData(JNIEnv* env, jclass rawFrameCls, jobject jframe,
const T& frame, bool newData) {
if (newData) {
static jmethodID setData = env->GetMethodID(
rawFrameCls, "setDataJNI", "(Ljava/nio/ByteBuffer;IIIIJI)V");
env->CallVoidMethod(
jframe, setData, env->NewDirectByteBuffer(frame.data, frame.size),
static_cast<jint>(frame.width), static_cast<jint>(frame.height),
static_cast<jint>(frame.stride), static_cast<jint>(frame.pixelFormat),
static_cast<jlong>(frame.timestamp),
static_cast<jint>(frame.timestampSrc));
} else {
static jmethodID setInfo =
env->GetMethodID(rawFrameCls, "setInfoJNI", "(IIIIJI)V");
env->CallVoidMethod(jframe, setInfo, static_cast<jint>(frame.width),
static_cast<jint>(frame.height),
static_cast<jint>(frame.stride),
static_cast<jint>(frame.pixelFormat),
static_cast<jlong>(frame.timestamp),
static_cast<jint>(frame.timestampSrc));
}
}
#endif
} // namespace wpi::util
#endif

View File

@@ -0,0 +1,90 @@
// 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 "wpi/util/RawFrame.h"
#ifdef WPI_RAWFRAME_JNI
#include <concepts>
#endif
#include <cstddef>
#ifdef WPI_RAWFRAME_JNI
#include "wpi/util/jni_util.hpp"
#endif
namespace wpi::util {
struct RawFrame : public WPI_RawFrame {
RawFrame() {
data = nullptr;
freeFunc = nullptr;
freeCbData = nullptr;
capacity = 0;
size = 0;
pixelFormat = WPI_PIXFMT_UNKNOWN;
width = 0;
height = 0;
timestamp = 0;
timestampSrc = WPI_TIMESRC_UNKNOWN;
}
RawFrame(const RawFrame&) = delete;
RawFrame& operator=(const RawFrame&) = delete;
RawFrame(RawFrame&& rhs) noexcept : WPI_RawFrame{rhs} {
rhs.data = nullptr;
rhs.freeFunc = nullptr;
rhs.freeCbData = nullptr;
rhs.capacity = 0;
rhs.size = 0;
}
RawFrame& operator=(RawFrame&& rhs) noexcept {
*static_cast<WPI_RawFrame*>(this) = rhs;
rhs.data = nullptr;
rhs.freeFunc = nullptr;
rhs.freeCbData = nullptr;
rhs.capacity = 0;
rhs.size = 0;
return *this;
}
void SetData(void* data, size_t size, size_t capacity, void* cbdata,
void (*freeFunc)(void* cbdata, void* data, size_t capacity)) {
WPI_SetRawFrameData(this, data, size, capacity, cbdata, freeFunc);
}
// returns true if the frame data was allocated/reallocated
bool Reserve(size_t size) {
return WPI_AllocateRawFrameData(this, size) != 0;
}
~RawFrame() { WPI_FreeRawFrameData(this); }
};
#ifdef WPI_RAWFRAME_JNI
template <std::same_as<wpi::util::RawFrame> T>
void SetFrameData(JNIEnv* env, jclass rawFrameCls, jobject jframe,
const T& frame, bool newData) {
if (newData) {
static jmethodID setData = env->GetMethodID(
rawFrameCls, "setDataJNI", "(Ljava/nio/ByteBuffer;IIIIJI)V");
env->CallVoidMethod(
jframe, setData, env->NewDirectByteBuffer(frame.data, frame.size),
static_cast<jint>(frame.width), static_cast<jint>(frame.height),
static_cast<jint>(frame.stride), static_cast<jint>(frame.pixelFormat),
static_cast<jlong>(frame.timestamp),
static_cast<jint>(frame.timestampSrc));
} else {
static jmethodID setInfo =
env->GetMethodID(rawFrameCls, "setInfoJNI", "(IIIIJI)V");
env->CallVoidMethod(jframe, setInfo, static_cast<jint>(frame.width),
static_cast<jint>(frame.height),
static_cast<jint>(frame.stride),
static_cast<jint>(frame.pixelFormat),
static_cast<jlong>(frame.timestamp),
static_cast<jint>(frame.timestampSrc));
}
}
#endif
} // namespace wpi::util

View File

@@ -9,7 +9,7 @@
#include <thread>
#include <utility>
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/condition_variable.hpp"
#include "wpi/util/mutex.hpp"

View File

@@ -4,12 +4,6 @@
#pragma once
#ifdef __cplusplus
#include <climits>
#include <initializer_list>
#include <span>
#endif
/**
* Generic handle for all WPI handle-based interfaces.
*
@@ -27,425 +21,8 @@ typedef WPI_Handle WPI_EventHandle; // NOLINT
typedef WPI_Handle WPI_SemaphoreHandle; // NOLINT
#ifdef __cplusplus
namespace wpi::util {
/** Constant representing an invalid handle. */
constexpr unsigned int kInvalidHandle = 0;
/**
* Standard types for handles.
* @{
*/
constexpr int kHandleTypeEvent = 1;
constexpr int kHandleTypeSemaphore = 2;
constexpr int kHandleTypeCSBase = 3;
constexpr int kHandleTypeNTBase = 16;
constexpr int kHandleTypeHALBase = 48;
constexpr int kHandleTypeUserBase = 80;
/** @} */
/**
* Creates an event. Events have binary state (signaled or not signaled) and
* may be either automatically reset or manually reset. Automatic-reset events
* go to non-signaled state when a WaitForObject is woken up by the event;
* manual-reset events require ResetEvent() to be called to set the event to
* non-signaled state; if ResetEvent() is not called, any waiter on that event
* will immediately wake when called.
*
* @param manualReset true for manual reset, false for automatic reset
* @param initialState true to make the event initially in signaled state
* @return Event handle
*/
WPI_EventHandle CreateEvent(bool manualReset = false,
bool initialState = false);
/**
* Destroys an event. Destruction wakes up any waiters.
*
* @param handle event handle
*/
void DestroyEvent(WPI_EventHandle handle);
/**
* Sets an event to signaled state.
*
* @param handle event handle
*/
void SetEvent(WPI_EventHandle handle);
/**
* Sets an event to non-signaled state.
*
* @param handle event handle
*/
void ResetEvent(WPI_EventHandle handle);
/**
* Creates a semaphore. Semaphores keep an internal counter. Releasing the
* semaphore increases the count. A semaphore with a non-zero count is
* considered signaled. When a waiter wakes up it atomically decrements the
* count by 1. This is generally useful in a single-supplier,
* multiple-consumer scenario.
*
* @param initialCount initial value for the semaphore's internal counter
* @param maximumCount maximum value for the semaphore's internal counter
* @return Semaphore handle
*/
WPI_SemaphoreHandle CreateSemaphore(int initialCount = 0,
int maximumCount = INT_MAX);
/**
* Destroys a semaphore. Destruction wakes up any waiters.
*
* @param handle semaphore handle
*/
void DestroySemaphore(WPI_SemaphoreHandle handle);
/**
* Releases N counts of a semaphore.
*
* @param handle semaphore handle
* @param releaseCount amount to add to semaphore's internal counter;
* must be positive
* @param prevCount if non-null, previous count (output parameter)
* @return True on successful release, false on failure (e.g. release count
* would exceed maximum value, or handle invalid)
*/
bool ReleaseSemaphore(WPI_SemaphoreHandle handle, int releaseCount = 1,
int* prevCount = nullptr);
/**
* Waits for an handle to be signaled.
*
* @param handle handle to wait on
* @return True if handle was signaled, false otherwise (e.g. object was
* destroyed)
*/
bool WaitForObject(WPI_Handle handle);
/**
* Waits for an handle to be signaled, with timeout.
*
* @param handle handle to wait on
* @param timeout timeout in seconds
* @param timedOut if non-null, set to true if timeout reached without handle
* being signaled; set to false otherwise (output)
* @return True if handle was signaled, false otherwise (e.g. object was
* destroyed or timed out)
*/
bool WaitForObject(WPI_Handle handle, double timeout, bool* timedOut);
/**
* Waits for one or more handles to be signaled.
*
* Invalid handles are treated as signaled; the returned array will have the
* handle error bit set for any invalid handles.
*
* @param handles array of handles to wait on
* @param signaled output array for storage of signaled handles; must be at
* least the size of the handles input array
* @return array of signaled handles (points into signaled array)
*/
std::span<WPI_Handle> WaitForObjects(std::span<const WPI_Handle> handles,
std::span<WPI_Handle> signaled);
/**
* Waits for one or more handles to be signaled.
*
* Invalid handles are treated as signaled; the returned array will have the
* handle error bit set for any invalid handles.
*
* @param handles array of handles to wait on
* @param signaled output array for storage of signaled handles; must be at
* least the size of the handles input array
* @return array of signaled handles (points into signaled array)
*/
inline std::span<WPI_Handle> WaitForObjects(
std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled) {
return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled);
}
/**
* Waits for one or more handles to be signaled, with timeout.
*
* Invalid handles are treated as signaled; the returned array will have the
* handle error bit set for any invalid handles.
*
* @param handles array of handles to wait on
* @param signaled output array for storage of signaled handles; must be at
* least the size of the handles input array
* @param timeout timeout in seconds
* @param timedOut if non-null, set to true if timeout reached without any
* handle being signaled; set to false otherwise (output)
* @return array of signaled handles (points into signaled array)
*/
std::span<WPI_Handle> WaitForObjects(std::span<const WPI_Handle> handles,
std::span<WPI_Handle> signaled,
double timeout, bool* timedOut);
/**
* Waits for one or more handles to be signaled, with timeout.
*
* Invalid handles are treated as signaled; the returned array will have the
* handle error bit set for any invalid handles.
*
* @param handles array of handles to wait on
* @param signaled output array for storage of signaled handles; must be at
* least the size of the handles input array
* @param timeout timeout in seconds
* @param timedOut if non-null, set to true if timeout reached without any
* handle being signaled; set to false otherwise (output)
* @return array of signaled handles (points into signaled array)
*/
inline std::span<WPI_Handle> WaitForObjects(
std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled,
double timeout, bool* timedOut) {
return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled,
timeout, timedOut);
}
/**
* Sets up signaling for an arbitrary handle. With this function, any handle
* can operate like an event handle.
*
* @param handle Event handle
* @param manualReset true for manual reset, false for automatic reset
* @param initialState true to make the handle initially in signaled state
*/
void CreateSignalObject(WPI_Handle handle, bool manualReset = false,
bool initialState = false);
/**
* Sets a handle to signaled state.
*
* @param handle handle
*/
void SetSignalObject(WPI_Handle handle);
/**
* Sets a handle to non-signaled state.
*
* @param handle handle
*/
void ResetSignalObject(WPI_Handle handle);
/**
* Cleans up signaling for a handle. Destruction wakes up any waiters.
*
* @param handle handle
*/
void DestroySignalObject(WPI_Handle handle);
/**
* An atomic signaling event for synchronization.
*
* Events have binary state (signaled or not signaled) and may be either
* automatically reset or manually reset. Automatic-reset events go to
* non-signaled state when a WaitForObject is woken up by the event;
* manual-reset events require Reset() to be called to set the event to
* non-signaled state; if Reset() is not called, any waiter on that event
* will immediately wake when called.
*/
class Event final {
public:
/**
* Constructor.
*
* @param manualReset true for manual reset, false for automatic reset
* @param initialState true to make the event initially in signaled state
*/
explicit Event(bool manualReset = false, bool initialState = false)
: m_handle{CreateEvent(manualReset, initialState)} {}
~Event() {
if (m_handle != 0) {
DestroyEvent(m_handle);
}
}
Event(const Event&) = delete;
Event& operator=(const Event&) = delete;
Event(Event&& rhs) : m_handle{rhs.m_handle} { rhs.m_handle = 0; }
Event& operator=(Event&& rhs) {
if (m_handle != 0) {
DestroyEvent(m_handle);
}
m_handle = rhs.m_handle;
rhs.m_handle = 0;
return *this;
}
/**
* Gets the event handle (e.g. for WaitForObject).
*
* @return handle
*/
explicit operator WPI_Handle() const { return m_handle; }
/**
* Gets the event handle (e.g. for WaitForObject).
*
* @return handle
*/
WPI_EventHandle GetHandle() const { return m_handle; }
/**
* Sets the event to signaled state.
*/
void Set() { SetEvent(m_handle); }
/**
* Sets the event to non-signaled state.
*/
void Reset() { ResetEvent(m_handle); }
private:
WPI_EventHandle m_handle;
};
/**
* A semaphore for synchronization.
*
* Semaphores keep an internal counter. Releasing the semaphore increases
* the count. A semaphore with a non-zero count is considered signaled.
* When a waiter wakes up it atomically decrements the count by 1. This
* is generally useful in a single-supplier, multiple-consumer scenario.
*/
class Semaphore final {
public:
/**
* Constructor.
*
* @param initialCount initial value for the semaphore's internal counter
* @param maximumCount maximum value for the semaphore's internal counter
*/
explicit Semaphore(int initialCount = 0, int maximumCount = INT_MAX)
: m_handle{CreateSemaphore(initialCount, maximumCount)} {}
~Semaphore() {
if (m_handle != 0) {
DestroySemaphore(m_handle);
}
}
Semaphore(const Semaphore&) = delete;
Semaphore& operator=(const Semaphore&) = delete;
Semaphore(Semaphore&& rhs) : m_handle{rhs.m_handle} { rhs.m_handle = 0; }
Semaphore& operator=(Semaphore&& rhs) {
if (m_handle != 0) {
DestroySemaphore(m_handle);
}
m_handle = rhs.m_handle;
rhs.m_handle = 0;
return *this;
}
/**
* Gets the semaphore handle (e.g. for WaitForObject).
*
* @return handle
*/
explicit operator WPI_Handle() const { return m_handle; }
/**
* Gets the semaphore handle (e.g. for WaitForObject).
*
* @return handle
*/
WPI_SemaphoreHandle GetHandle() const { return m_handle; }
/**
* Releases N counts of the semaphore.
*
* @param releaseCount amount to add to semaphore's internal counter;
* must be positive
* @param prevCount if non-null, previous count (output parameter)
* @return True on successful release, false on failure (e.g. release count
* would exceed maximum value, or handle invalid)
*/
bool Release(int releaseCount = 1, int* prevCount = nullptr) {
return ReleaseSemaphore(m_handle, releaseCount, prevCount);
}
private:
WPI_SemaphoreHandle m_handle;
};
/**
* RAII wrapper for signaling handles.
*
* Sets up signaling for an arbitrary handle. This enables any handle
* to operate like an event handle.
*/
template <typename T>
class SignalObject final {
public:
/**
* Constructor.
*
* @param handle handle
* @param manualReset true for manual reset, false for automatic reset
* @param initialState true to make the handle initially in signaled state
*/
explicit SignalObject(T handle = 0, bool manualReset = false,
bool initialState = false)
: m_handle{handle} {
CreateSignalObject(handle, manualReset, initialState);
}
~SignalObject() {
if (m_handle != 0) {
DestroySignalObject(m_handle);
}
}
SignalObject(const SignalObject&) = delete;
SignalObject& operator=(const SignalObject&) = delete;
SignalObject(SignalObject&& rhs) : m_handle{rhs.m_handle} {
rhs.m_handle = 0;
}
SignalObject& operator=(SignalObject&& rhs) {
if (m_handle != 0) {
DestroySignalObject(m_handle);
}
m_handle = rhs.m_handle;
rhs.m_handle = 0;
return *this;
}
/**
* Gets the handle.
*
* @return handle
*/
/*implicit*/ operator T() const { return m_handle; } // NOLINT
/**
* Gets the handle (e.g. for WaitForObject).
*
* @return handle
*/
T GetHandle() const { return m_handle; }
/**
* Sets the handle to signaled state.
*/
void Set() { SetSignalObject(m_handle); }
/**
* Sets the handle to non-signaled state.
*/
void Reset() { ResetSignalObject(m_handle); }
private:
T m_handle;
};
} // namespace wpi::util
extern "C" {
#endif // __cplusplus
#endif
/**
* Creates an event. Events have binary state (signaled or not signaled) and

View File

@@ -0,0 +1,426 @@
// 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 <climits>
#include <initializer_list>
#include <span>
#include "wpi/util/Synchronization.h"
namespace wpi::util {
/** Constant representing an invalid handle. */
constexpr unsigned int kInvalidHandle = 0;
/**
* Standard types for handles.
* @{
*/
constexpr int kHandleTypeEvent = 1;
constexpr int kHandleTypeSemaphore = 2;
constexpr int kHandleTypeCSBase = 3;
constexpr int kHandleTypeNTBase = 16;
constexpr int kHandleTypeHALBase = 48;
constexpr int kHandleTypeUserBase = 80;
/** @} */
/**
* Creates an event. Events have binary state (signaled or not signaled) and
* may be either automatically reset or manually reset. Automatic-reset events
* go to non-signaled state when a WaitForObject is woken up by the event;
* manual-reset events require ResetEvent() to be called to set the event to
* non-signaled state; if ResetEvent() is not called, any waiter on that event
* will immediately wake when called.
*
* @param manualReset true for manual reset, false for automatic reset
* @param initialState true to make the event initially in signaled state
* @return Event handle
*/
WPI_EventHandle CreateEvent(bool manualReset = false,
bool initialState = false);
/**
* Destroys an event. Destruction wakes up any waiters.
*
* @param handle event handle
*/
void DestroyEvent(WPI_EventHandle handle);
/**
* Sets an event to signaled state.
*
* @param handle event handle
*/
void SetEvent(WPI_EventHandle handle);
/**
* Sets an event to non-signaled state.
*
* @param handle event handle
*/
void ResetEvent(WPI_EventHandle handle);
/**
* Creates a semaphore. Semaphores keep an internal counter. Releasing the
* semaphore increases the count. A semaphore with a non-zero count is
* considered signaled. When a waiter wakes up it atomically decrements the
* count by 1. This is generally useful in a single-supplier,
* multiple-consumer scenario.
*
* @param initialCount initial value for the semaphore's internal counter
* @param maximumCount maximum value for the semaphore's internal counter
* @return Semaphore handle
*/
WPI_SemaphoreHandle CreateSemaphore(int initialCount = 0,
int maximumCount = INT_MAX);
/**
* Destroys a semaphore. Destruction wakes up any waiters.
*
* @param handle semaphore handle
*/
void DestroySemaphore(WPI_SemaphoreHandle handle);
/**
* Releases N counts of a semaphore.
*
* @param handle semaphore handle
* @param releaseCount amount to add to semaphore's internal counter;
* must be positive
* @param prevCount if non-null, previous count (output parameter)
* @return True on successful release, false on failure (e.g. release count
* would exceed maximum value, or handle invalid)
*/
bool ReleaseSemaphore(WPI_SemaphoreHandle handle, int releaseCount = 1,
int* prevCount = nullptr);
/**
* Waits for an handle to be signaled.
*
* @param handle handle to wait on
* @return True if handle was signaled, false otherwise (e.g. object was
* destroyed)
*/
bool WaitForObject(WPI_Handle handle);
/**
* Waits for an handle to be signaled, with timeout.
*
* @param handle handle to wait on
* @param timeout timeout in seconds
* @param timedOut if non-null, set to true if timeout reached without handle
* being signaled; set to false otherwise (output)
* @return True if handle was signaled, false otherwise (e.g. object was
* destroyed or timed out)
*/
bool WaitForObject(WPI_Handle handle, double timeout, bool* timedOut);
/**
* Waits for one or more handles to be signaled.
*
* Invalid handles are treated as signaled; the returned array will have the
* handle error bit set for any invalid handles.
*
* @param handles array of handles to wait on
* @param signaled output array for storage of signaled handles; must be at
* least the size of the handles input array
* @return array of signaled handles (points into signaled array)
*/
std::span<WPI_Handle> WaitForObjects(std::span<const WPI_Handle> handles,
std::span<WPI_Handle> signaled);
/**
* Waits for one or more handles to be signaled.
*
* Invalid handles are treated as signaled; the returned array will have the
* handle error bit set for any invalid handles.
*
* @param handles array of handles to wait on
* @param signaled output array for storage of signaled handles; must be at
* least the size of the handles input array
* @return array of signaled handles (points into signaled array)
*/
inline std::span<WPI_Handle> WaitForObjects(
std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled) {
return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled);
}
/**
* Waits for one or more handles to be signaled, with timeout.
*
* Invalid handles are treated as signaled; the returned array will have the
* handle error bit set for any invalid handles.
*
* @param handles array of handles to wait on
* @param signaled output array for storage of signaled handles; must be at
* least the size of the handles input array
* @param timeout timeout in seconds
* @param timedOut if non-null, set to true if timeout reached without any
* handle being signaled; set to false otherwise (output)
* @return array of signaled handles (points into signaled array)
*/
std::span<WPI_Handle> WaitForObjects(std::span<const WPI_Handle> handles,
std::span<WPI_Handle> signaled,
double timeout, bool* timedOut);
/**
* Waits for one or more handles to be signaled, with timeout.
*
* Invalid handles are treated as signaled; the returned array will have the
* handle error bit set for any invalid handles.
*
* @param handles array of handles to wait on
* @param signaled output array for storage of signaled handles; must be at
* least the size of the handles input array
* @param timeout timeout in seconds
* @param timedOut if non-null, set to true if timeout reached without any
* handle being signaled; set to false otherwise (output)
* @return array of signaled handles (points into signaled array)
*/
inline std::span<WPI_Handle> WaitForObjects(
std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled,
double timeout, bool* timedOut) {
return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled,
timeout, timedOut);
}
/**
* Sets up signaling for an arbitrary handle. With this function, any handle
* can operate like an event handle.
*
* @param handle Event handle
* @param manualReset true for manual reset, false for automatic reset
* @param initialState true to make the handle initially in signaled state
*/
void CreateSignalObject(WPI_Handle handle, bool manualReset = false,
bool initialState = false);
/**
* Sets a handle to signaled state.
*
* @param handle handle
*/
void SetSignalObject(WPI_Handle handle);
/**
* Sets a handle to non-signaled state.
*
* @param handle handle
*/
void ResetSignalObject(WPI_Handle handle);
/**
* Cleans up signaling for a handle. Destruction wakes up any waiters.
*
* @param handle handle
*/
void DestroySignalObject(WPI_Handle handle);
/**
* An atomic signaling event for synchronization.
*
* Events have binary state (signaled or not signaled) and may be either
* automatically reset or manually reset. Automatic-reset events go to
* non-signaled state when a WaitForObject is woken up by the event;
* manual-reset events require Reset() to be called to set the event to
* non-signaled state; if Reset() is not called, any waiter on that event
* will immediately wake when called.
*/
class Event final {
public:
/**
* Constructor.
*
* @param manualReset true for manual reset, false for automatic reset
* @param initialState true to make the event initially in signaled state
*/
explicit Event(bool manualReset = false, bool initialState = false)
: m_handle{CreateEvent(manualReset, initialState)} {}
~Event() {
if (m_handle != 0) {
DestroyEvent(m_handle);
}
}
Event(const Event&) = delete;
Event& operator=(const Event&) = delete;
Event(Event&& rhs) : m_handle{rhs.m_handle} { rhs.m_handle = 0; }
Event& operator=(Event&& rhs) {
if (m_handle != 0) {
DestroyEvent(m_handle);
}
m_handle = rhs.m_handle;
rhs.m_handle = 0;
return *this;
}
/**
* Gets the event handle (e.g. for WaitForObject).
*
* @return handle
*/
explicit operator WPI_Handle() const { return m_handle; }
/**
* Gets the event handle (e.g. for WaitForObject).
*
* @return handle
*/
WPI_EventHandle GetHandle() const { return m_handle; }
/**
* Sets the event to signaled state.
*/
void Set() { SetEvent(m_handle); }
/**
* Sets the event to non-signaled state.
*/
void Reset() { ResetEvent(m_handle); }
private:
WPI_EventHandle m_handle;
};
/**
* A semaphore for synchronization.
*
* Semaphores keep an internal counter. Releasing the semaphore increases
* the count. A semaphore with a non-zero count is considered signaled.
* When a waiter wakes up it atomically decrements the count by 1. This
* is generally useful in a single-supplier, multiple-consumer scenario.
*/
class Semaphore final {
public:
/**
* Constructor.
*
* @param initialCount initial value for the semaphore's internal counter
* @param maximumCount maximum value for the semaphore's internal counter
*/
explicit Semaphore(int initialCount = 0, int maximumCount = INT_MAX)
: m_handle{CreateSemaphore(initialCount, maximumCount)} {}
~Semaphore() {
if (m_handle != 0) {
DestroySemaphore(m_handle);
}
}
Semaphore(const Semaphore&) = delete;
Semaphore& operator=(const Semaphore&) = delete;
Semaphore(Semaphore&& rhs) : m_handle{rhs.m_handle} { rhs.m_handle = 0; }
Semaphore& operator=(Semaphore&& rhs) {
if (m_handle != 0) {
DestroySemaphore(m_handle);
}
m_handle = rhs.m_handle;
rhs.m_handle = 0;
return *this;
}
/**
* Gets the semaphore handle (e.g. for WaitForObject).
*
* @return handle
*/
explicit operator WPI_Handle() const { return m_handle; }
/**
* Gets the semaphore handle (e.g. for WaitForObject).
*
* @return handle
*/
WPI_SemaphoreHandle GetHandle() const { return m_handle; }
/**
* Releases N counts of the semaphore.
*
* @param releaseCount amount to add to semaphore's internal counter;
* must be positive
* @param prevCount if non-null, previous count (output parameter)
* @return True on successful release, false on failure (e.g. release count
* would exceed maximum value, or handle invalid)
*/
bool Release(int releaseCount = 1, int* prevCount = nullptr) {
return ReleaseSemaphore(m_handle, releaseCount, prevCount);
}
private:
WPI_SemaphoreHandle m_handle;
};
/**
* RAII wrapper for signaling handles.
*
* Sets up signaling for an arbitrary handle. This enables any handle
* to operate like an event handle.
*/
template <typename T>
class SignalObject final {
public:
/**
* Constructor.
*
* @param handle handle
* @param manualReset true for manual reset, false for automatic reset
* @param initialState true to make the handle initially in signaled state
*/
explicit SignalObject(T handle = 0, bool manualReset = false,
bool initialState = false)
: m_handle{handle} {
CreateSignalObject(handle, manualReset, initialState);
}
~SignalObject() {
if (m_handle != 0) {
DestroySignalObject(m_handle);
}
}
SignalObject(const SignalObject&) = delete;
SignalObject& operator=(const SignalObject&) = delete;
SignalObject(SignalObject&& rhs) : m_handle{rhs.m_handle} {
rhs.m_handle = 0;
}
SignalObject& operator=(SignalObject&& rhs) {
if (m_handle != 0) {
DestroySignalObject(m_handle);
}
m_handle = rhs.m_handle;
rhs.m_handle = 0;
return *this;
}
/**
* Gets the handle.
*
* @return handle
*/
/*implicit*/ operator T() const { return m_handle; } // NOLINT
/**
* Gets the handle (e.g. for WaitForObject).
*
* @return handle
*/
T GetHandle() const { return m_handle; }
/**
* Sets the handle to signaled state.
*/
void Set() { SetSignalObject(m_handle); }
/**
* Sets the handle to non-signaled state.
*/
void Reset() { ResetSignalObject(m_handle); }
private:
T m_handle;
};
} // namespace wpi::util

View File

@@ -22,7 +22,7 @@
#include "wpi/util/mutex.hpp"
#include "wpi/util/print.hpp"
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
/** Java Native Interface (JNI) utility functions */
namespace wpi::util::java {

View File

@@ -4,10 +4,7 @@
#pragma once
#ifdef __cplusplus
#include <cstring>
#include <string_view>
#endif
#include <stddef.h> // NOLINT
/**
* A const UTF8 string.
@@ -19,27 +16,9 @@ struct WPI_String {
size_t len;
};
#ifdef __cplusplus
namespace wpi::util {
/** Converts a WPI_String to a string_view */
constexpr std::string_view to_string_view(const struct WPI_String* str) {
if (str) {
return {str->str, str->len};
} else {
return "";
}
}
/** Converts a string_view to a WPI_String */
constexpr WPI_String make_string(std::string_view view) {
return WPI_String{view.data(), view.size()};
}
} // namespace wpi::util
#endif // __cplusplus
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#endif
/**
* Initializes a WPI_String from a null terminated UTF-8 string.
@@ -106,25 +85,4 @@ void WPI_FreeStringArray(const struct WPI_String* wpiStringArray,
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#ifdef __cplusplus
namespace wpi::util {
/** Allocates a copy of a string_view and stores the result into a WPI_String */
inline WPI_String alloc_wpi_string(std::string_view view) {
WPI_String out;
size_t len = view.size();
std::memcpy(WPI_AllocateString(&out, len), view.data(), len);
return out;
}
/** Allocates a copy of a WPI_String */
inline WPI_String copy_wpi_string(const WPI_String& str) {
if (str.str == nullptr || str.len == 0) {
return WPI_String{nullptr, 0};
}
return alloc_wpi_string(to_string_view(&str));
}
} // namespace wpi::util
#endif

View File

@@ -0,0 +1,44 @@
// 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 <cstring>
#include <string_view>
#include "wpi/util/string.h"
namespace wpi::util {
/** Converts a WPI_String to a string_view */
constexpr std::string_view to_string_view(const struct WPI_String* str) {
if (str) {
return {str->str, str->len};
} else {
return "";
}
}
/** Converts a string_view to a WPI_String */
constexpr WPI_String make_string(std::string_view view) {
return WPI_String{view.data(), view.size()};
}
/** Allocates a copy of a string_view and stores the result into a WPI_String */
inline WPI_String alloc_wpi_string(std::string_view view) {
WPI_String out;
size_t len = view.size();
std::memcpy(WPI_AllocateString(&out, len), view.data(), len);
return out;
}
/** Allocates a copy of a WPI_String */
inline WPI_String copy_wpi_string(const WPI_String& str) {
if (str.str == nullptr || str.len == 0) {
return WPI_String{nullptr, 0};
}
return alloc_wpi_string(to_string_view(&str));
}
} // namespace wpi::util

View File

@@ -6,11 +6,6 @@
#include <stdint.h>
#ifdef __cplusplus
#include <memory> // NOLINT
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -48,39 +43,3 @@ uint64_t WPI_GetSystemTime(void);
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
namespace wpi::util {
/**
* The default implementation used for Now().
* In general this is the time returned by the operating system.
* @return Time in microseconds.
*/
uint64_t NowDefault();
/**
* Set the implementation used by Now().
* The implementation must return monotonic time in microseconds to maintain
* the contract of Now().
* @param func Function called by Now() to return the time.
*/
void SetNowImpl(uint64_t (*func)());
/**
* Return a value representing the current time in microseconds.
* This is a monotonic clock with an undefined epoch.
* @return Time in microseconds.
*/
uint64_t Now();
/**
* Return the current system time in microseconds since the Unix epoch
* (January 1st, 1970 00:00 UTC).
*
* @return Time in microseconds.
*/
uint64_t GetSystemTime();
} // namespace wpi::util
#endif

View File

@@ -0,0 +1,41 @@
// 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 <stdint.h>
namespace wpi::util {
/**
* The default implementation used for Now().
* In general this is the time returned by the operating system.
* @return Time in microseconds.
*/
uint64_t NowDefault();
/**
* Set the implementation used by Now().
* The implementation must return monotonic time in microseconds to maintain
* the contract of Now().
* @param func Function called by Now() to return the time.
*/
void SetNowImpl(uint64_t (*func)());
/**
* Return a value representing the current time in microseconds.
* This is a monotonic clock with an undefined epoch.
* @return Time in microseconds.
*/
uint64_t Now();
/**
* Return the current system time in microseconds since the Unix epoch
* (January 1st, 1970 00:00 UTC).
*
* @return Time in microseconds.
*/
uint64_t GetSystemTime();
} // namespace wpi::util

View File

@@ -70,8 +70,9 @@ depends = ["wpiutil-casters"]
Color = "wpi/util/Color.hpp"
Color8Bit = "wpi/util/Color8Bit.hpp"
StackTrace = "wpi/util/StackTrace.hpp"
Synchronization = "wpi/util/Synchronization.h"
RawFrame = "wpi/util/RawFrame.h"
Synchronization = "wpi/util/Synchronization.hpp"
RawFrame_c = "wpi/util/RawFrame.h"
RawFrame = "wpi/util/RawFrame.hpp"
# wpi/sendable
Sendable = "wpi/util/sendable/Sendable.hpp"

View File

@@ -1,7 +1,3 @@
defaults:
ignore: true
enums:
WPI_TimestampSource:
value_prefix: WPI_TIMESRC
rename: TimestampSource

View File

@@ -0,0 +1,7 @@
defaults:
ignore: true
enums:
WPI_TimestampSource:
value_prefix: WPI_TIMESRC
rename: TimestampSource

View File

@@ -1,6 +1,6 @@
#include <pybind11/pybind11.h>
#include "wpi/util/string.h"
#include "wpi/util/string.hpp"
namespace pybind11::detail {
@@ -31,4 +31,4 @@ public:
}
};
} // namespace pybind11::detail
} // namespace pybind11::detail

View File

@@ -2,7 +2,7 @@
// 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.
#include "wpi/util/Synchronization.h"
#include "wpi/util/Synchronization.hpp"
#include <thread>