mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[hal] Replace const char* with std::string_view in Driver Station sim functions (#4532)
This commit is contained in:
@@ -103,13 +103,13 @@ void HALSIM_SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox) {}
|
||||
|
||||
void HALSIM_SetJoystickType(int32_t stick, int32_t type) {}
|
||||
|
||||
void HALSIM_SetJoystickName(int32_t stick, const char* name) {}
|
||||
void HALSIM_SetJoystickName(int32_t stick, const char* name, size_t size) {}
|
||||
|
||||
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type) {}
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const char* message) {}
|
||||
void HALSIM_SetGameSpecificMessage(const char* message, size_t size) {}
|
||||
|
||||
void HALSIM_SetEventName(const char* name) {}
|
||||
void HALSIM_SetEventName(const char* name, size_t size) {}
|
||||
|
||||
void HALSIM_SetMatchType(HAL_MatchType type) {}
|
||||
|
||||
|
||||
@@ -732,7 +732,8 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickName
|
||||
(JNIEnv* env, jclass, jint stick, jstring name)
|
||||
{
|
||||
HALSIM_SetJoystickName(stick, JStringRef{env, name}.c_str());
|
||||
JStringRef nameJString{env, name};
|
||||
HALSIM_SetJoystickName(stick, nameJString.c_str(), nameJString.size());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -756,7 +757,8 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setGameSpecificMessage
|
||||
(JNIEnv* env, jclass, jstring message)
|
||||
{
|
||||
HALSIM_SetGameSpecificMessage(JStringRef{env, message}.c_str());
|
||||
JStringRef messageJString{env, message};
|
||||
HALSIM_SetGameSpecificMessage(messageJString.c_str(), messageJString.size());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -768,7 +770,8 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setEventName
|
||||
(JNIEnv* env, jclass, jstring name)
|
||||
{
|
||||
HALSIM_SetEventName(JStringRef{env, name}.c_str());
|
||||
JStringRef nameJString{env, name};
|
||||
HALSIM_SetEventName(nameJString.c_str(), nameJString.size());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "hal/DriverStationTypes.h"
|
||||
#include "hal/Types.h"
|
||||
#include "hal/simulation/NotifyListener.h"
|
||||
@@ -145,11 +147,11 @@ void HALSIM_GetJoystickCounts(int32_t stick, int32_t* axisCount,
|
||||
|
||||
void HALSIM_SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox);
|
||||
void HALSIM_SetJoystickType(int32_t stick, int32_t type);
|
||||
void HALSIM_SetJoystickName(int32_t stick, const char* name);
|
||||
void HALSIM_SetJoystickName(int32_t stick, const char* name, size_t size);
|
||||
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type);
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const char* message);
|
||||
void HALSIM_SetEventName(const char* name);
|
||||
void HALSIM_SetGameSpecificMessage(const char* message, size_t size);
|
||||
void HALSIM_SetEventName(const char* name, size_t size);
|
||||
void HALSIM_SetMatchType(HAL_MatchType type);
|
||||
void HALSIM_SetMatchNumber(int32_t matchNumber);
|
||||
void HALSIM_SetReplayNumber(int32_t replayNumber);
|
||||
|
||||
@@ -339,14 +339,17 @@ void DriverStationData::SetJoystickType(int32_t stick, int32_t type) {
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickName(int32_t stick, const char* name) {
|
||||
void DriverStationData::SetJoystickName(int32_t stick, const char* name,
|
||||
size_t size) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
std::strncpy(m_joystickData[stick].descriptor.name, name,
|
||||
sizeof(m_joystickData[stick].descriptor.name) - 1);
|
||||
*(std::end(m_joystickData[stick].descriptor.name) - 1) = '\0';
|
||||
if (size > sizeof(m_joystickData[stick].descriptor.name) - 1) {
|
||||
size = sizeof(m_joystickData[stick].descriptor.name) - 1;
|
||||
}
|
||||
std::strncpy(m_joystickData[stick].descriptor.name, name, size);
|
||||
m_joystickData[stick].descriptor.name[size] = '\0';
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
@@ -363,19 +366,27 @@ void DriverStationData::SetJoystickAxisType(int32_t stick, int32_t axis,
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetGameSpecificMessage(const char* message) {
|
||||
void DriverStationData::SetGameSpecificMessage(const char* message,
|
||||
size_t size) {
|
||||
std::scoped_lock lock(m_matchInfoMutex);
|
||||
if (size > sizeof(m_matchInfo.gameSpecificMessage) - 1) {
|
||||
size = sizeof(m_matchInfo.gameSpecificMessage) - 1;
|
||||
}
|
||||
std::strncpy(reinterpret_cast<char*>(m_matchInfo.gameSpecificMessage),
|
||||
message, sizeof(m_matchInfo.gameSpecificMessage) - 1);
|
||||
*(std::end(m_matchInfo.gameSpecificMessage) - 1) = '\0';
|
||||
m_matchInfo.gameSpecificMessageSize = std::strlen(message);
|
||||
message, size);
|
||||
m_matchInfo.gameSpecificMessage[size] = '\0';
|
||||
m_matchInfo.gameSpecificMessageSize =
|
||||
std::strlen(reinterpret_cast<char*>(m_matchInfo.gameSpecificMessage));
|
||||
m_matchInfoCallbacks(&m_matchInfo);
|
||||
}
|
||||
|
||||
void DriverStationData::SetEventName(const char* name) {
|
||||
void DriverStationData::SetEventName(const char* name, size_t size) {
|
||||
std::scoped_lock lock(m_matchInfoMutex);
|
||||
std::strncpy(m_matchInfo.eventName, name, sizeof(m_matchInfo.eventName) - 1);
|
||||
*(std::end(m_matchInfo.eventName) - 1) = '\0';
|
||||
if (size > sizeof(m_matchInfo.eventName) - 1) {
|
||||
size = sizeof(m_matchInfo.eventName) - 1;
|
||||
}
|
||||
std::strncpy(m_matchInfo.eventName, name, size);
|
||||
m_matchInfo.eventName[size] = '\0';
|
||||
m_matchInfoCallbacks(&m_matchInfo);
|
||||
}
|
||||
|
||||
@@ -540,20 +551,20 @@ void HALSIM_SetJoystickType(int32_t stick, int32_t type) {
|
||||
SimDriverStationData->SetJoystickType(stick, type);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickName(int32_t stick, const char* name) {
|
||||
SimDriverStationData->SetJoystickName(stick, name);
|
||||
void HALSIM_SetJoystickName(int32_t stick, const char* name, size_t size) {
|
||||
SimDriverStationData->SetJoystickName(stick, name, size);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type) {
|
||||
SimDriverStationData->SetJoystickAxisType(stick, axis, type);
|
||||
}
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const char* message) {
|
||||
SimDriverStationData->SetGameSpecificMessage(message);
|
||||
void HALSIM_SetGameSpecificMessage(const char* message, size_t size) {
|
||||
SimDriverStationData->SetGameSpecificMessage(message, size);
|
||||
}
|
||||
|
||||
void HALSIM_SetEventName(const char* name) {
|
||||
SimDriverStationData->SetEventName(name);
|
||||
void HALSIM_SetEventName(const char* name, size_t size) {
|
||||
SimDriverStationData->SetEventName(name, size);
|
||||
}
|
||||
|
||||
void HALSIM_SetMatchType(HAL_MatchType type) {
|
||||
|
||||
@@ -107,11 +107,11 @@ class DriverStationData {
|
||||
|
||||
void SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox);
|
||||
void SetJoystickType(int32_t stick, int32_t type);
|
||||
void SetJoystickName(int32_t stick, const char* name);
|
||||
void SetJoystickName(int32_t stick, const char* name, size_t size);
|
||||
void SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type);
|
||||
|
||||
void SetGameSpecificMessage(const char* message);
|
||||
void SetEventName(const char* name);
|
||||
void SetGameSpecificMessage(const char* message, size_t size);
|
||||
void SetEventName(const char* name, size_t size);
|
||||
void SetMatchType(HAL_MatchType type);
|
||||
void SetMatchNumber(int32_t matchNumber);
|
||||
void SetReplayNumber(int32_t replayNumber);
|
||||
|
||||
Reference in New Issue
Block a user