SCRIPT namespace replacements

This commit is contained in:
PJ Reiniger
2025-11-07 20:00:05 -05:00
committed by Peter Johnson
parent ae6c043632
commit 9aca8e0fd6
2622 changed files with 22275 additions and 22275 deletions

View File

@@ -20,31 +20,31 @@
#include "Notifier.hpp"
#include "wpi/util/SafeThread.hpp"
using namespace cs;
using namespace wpi::cs;
class NetworkListener::Impl {
public:
Impl(wpi::Logger& logger, Notifier& notifier)
Impl(wpi::util::Logger& logger, Notifier& notifier)
: m_logger(logger), m_notifier(notifier) {}
wpi::Logger& m_logger;
wpi::util::Logger& m_logger;
Notifier& m_notifier;
class Thread : public wpi::SafeThread {
class Thread : public wpi::util::SafeThread {
public:
Thread(wpi::Logger& logger, Notifier& notifier)
Thread(wpi::util::Logger& logger, Notifier& notifier)
: m_logger(logger), m_notifier(notifier) {}
void Main() override;
wpi::Logger& m_logger;
wpi::util::Logger& m_logger;
Notifier& m_notifier;
int m_command_fd = -1;
};
wpi::SafeThreadOwner<Thread> m_owner;
wpi::util::SafeThreadOwner<Thread> m_owner;
};
NetworkListener::NetworkListener(wpi::Logger& logger, Notifier& notifier)
NetworkListener::NetworkListener(wpi::util::Logger& logger, Notifier& notifier)
: m_impl(std::make_unique<Impl>(logger, notifier)) {}
NetworkListener::~NetworkListener() {

View File

@@ -12,7 +12,7 @@
#include <string>
#include <vector>
namespace cs {
namespace wpi::cs {
std::vector<std::string> GetNetworkInterfaces() {
struct ifaddrs* ifa;
@@ -42,4 +42,4 @@ std::vector<std::string> GetNetworkInterfaces() {
return rv;
}
} // namespace cs
} // namespace wpi::cs

View File

@@ -5,22 +5,22 @@
#include "wpi/cs/cscore_runloop.hpp"
#include "wpi/util/Synchronization.h"
static wpi::Event& GetInstance() {
static wpi::Event event;
static wpi::util::Event& GetInstance() {
static wpi::util::Event event;
return event;
}
namespace cs {
namespace wpi::cs {
void RunMainRunLoop() {
wpi::Event& event = GetInstance();
wpi::WaitForObject(event.GetHandle());
wpi::util::Event& event = GetInstance();
wpi::util::WaitForObject(event.GetHandle());
}
int RunMainRunLoopTimeout(double timeout) {
wpi::Event& event = GetInstance();
wpi::util::Event& event = GetInstance();
bool timedOut = false;
bool signaled = wpi::WaitForObject(event.GetHandle(), timeout, &timedOut);
bool signaled = wpi::util::WaitForObject(event.GetHandle(), timeout, &timedOut);
if (timedOut) {
return 3;
}
@@ -31,8 +31,8 @@ int RunMainRunLoopTimeout(double timeout) {
}
void StopMainRunLoop() {
wpi::Event& event = GetInstance();
wpi::util::Event& event = GetInstance();
event.Set();
}
} // namespace cs
} // namespace wpi::cs

View File

@@ -9,7 +9,7 @@
#include <utility>
namespace cs {
namespace wpi::cs {
class UsbCameraBuffer {
public:
@@ -50,6 +50,6 @@ class UsbCameraBuffer {
size_t m_length{0};
};
} // namespace cs
} // namespace wpi::cs
#endif // CSCORE_USBCAMERABUFFER_HPP_

View File

@@ -41,7 +41,7 @@
#include "wpi/util/raw_ostream.hpp"
#include "wpi/util/timestamp.h"
using namespace cs;
using namespace wpi::cs;
namespace {
// Find the length of an array.
@@ -120,8 +120,8 @@ static __u32 FromPixelFormat(VideoMode::PixelFormat pixelFormat) {
}
static bool IsPercentageProperty(std::string_view name) {
if (wpi::starts_with(name, "raw_")) {
name = wpi::substr(name, 4);
if (wpi::util::starts_with(name, "raw_")) {
name = wpi::util::substr(name, 4);
}
return name == "brightness" || name == "contrast" || name == "saturation" ||
name == "hue" || name == "sharpness" || name == "gain" ||
@@ -206,14 +206,14 @@ static bool GetVendorProduct(int dev, int* vendor, int* product) {
return false;
}
std::string_view readStr{readBuf};
if (auto v = wpi::parse_integer<int>(
wpi::substr(wpi::substr(readStr, readStr.find('v')), 1, 4), 16)) {
if (auto v = wpi::util::parse_integer<int>(
wpi::util::substr(wpi::util::substr(readStr, readStr.find('v')), 1, 4), 16)) {
*vendor = v.value();
} else {
return false;
}
if (auto v = wpi::parse_integer<int>(
wpi::substr(wpi::substr(readStr, readStr.find('p')), 1, 4), 16)) {
if (auto v = wpi::util::parse_integer<int>(
wpi::util::substr(wpi::util::substr(readStr, readStr.find('p')), 1, 4), 16)) {
*product = v.value();
} else {
return false;
@@ -239,7 +239,7 @@ static bool GetDescriptionSysV4L(int dev, std::string* desc) {
return false;
}
*desc = wpi::rtrim(std::string_view(readBuf, n));
*desc = wpi::util::rtrim(std::string_view(readBuf, n));
return true;
}
@@ -261,9 +261,9 @@ static bool GetDescriptionIoctl(const char* cpath, std::string* desc) {
// try to convert "UVC Camera (0000:0000)" into a better name
std::optional<int> vendor;
std::optional<int> product;
if (wpi::starts_with(card, "UVC Camera (") &&
(vendor = wpi::parse_integer<int>(wpi::substr(card, 12, 4), 16)) &&
(product = wpi::parse_integer<int>(wpi::substr(card, 17, 4), 16))) {
if (wpi::util::starts_with(card, "UVC Camera (") &&
(vendor = wpi::util::parse_integer<int>(wpi::util::substr(card, 12, 4), 16)) &&
(product = wpi::util::parse_integer<int>(wpi::util::substr(card, 17, 4), 16))) {
std::string card2 = GetUsbNameFromId(vendor.value(), product.value());
if (!card2.empty()) {
*desc = std::move(card2);
@@ -306,10 +306,10 @@ static int GetDeviceNum(const char* cpath) {
}
std::string fn = path.filename();
if (!wpi::starts_with(fn, "video")) {
if (!wpi::util::starts_with(fn, "video")) {
return -1;
}
if (auto dev = wpi::parse_integer<int>(wpi::substr(fn, 5), 10)) {
if (auto dev = wpi::util::parse_integer<int>(wpi::util::substr(fn, 5), 10)) {
return dev.value();
}
return -1;
@@ -334,7 +334,7 @@ static std::string GetDescriptionImpl(const char* cpath) {
return std::string{};
}
UsbCameraImpl::UsbCameraImpl(std::string_view name, wpi::Logger& logger,
UsbCameraImpl::UsbCameraImpl(std::string_view name, wpi::util::Logger& logger,
Notifier& notifier, Telemetry& telemetry,
std::string_view path)
: SourceImpl{name, logger, notifier, telemetry},
@@ -391,27 +391,27 @@ void UsbCameraImpl::Start() {
void UsbCameraImpl::CameraThreadMain() {
// We want to be notified on file creation and deletion events in the device
// path. This is used to detect disconnects and reconnects.
std::unique_ptr<wpi::raw_fd_istream> notify_is;
std::unique_ptr<wpi::util::raw_fd_istream> notify_is;
int notify_fd = inotify_init();
if (notify_fd >= 0) {
// need to make a copy as dirname can modify it
wpi::SmallString<64> pathCopy{m_path};
wpi::util::SmallString<64> pathCopy{m_path};
pathCopy.push_back('\0');
if (inotify_add_watch(notify_fd, dirname(pathCopy.data()),
IN_CREATE | IN_DELETE) < 0) {
close(notify_fd);
notify_fd = -1;
} else {
notify_is = std::make_unique<wpi::raw_fd_istream>(
notify_is = std::make_unique<wpi::util::raw_fd_istream>(
notify_fd, true, sizeof(struct inotify_event) + NAME_MAX + 1);
}
}
bool notified = (notify_fd < 0); // treat as always notified if cannot notify
// Get the basename for later notify use
wpi::SmallString<64> pathCopy{m_path};
wpi::util::SmallString<64> pathCopy{m_path};
pathCopy.push_back('\0');
wpi::SmallString<64> base{basename(pathCopy.data())};
wpi::util::SmallString<64> base{basename(pathCopy.data())};
// Used to restart streaming on reconnect
bool wasStreaming = false;
@@ -486,7 +486,7 @@ void UsbCameraImpl::CameraThreadMain() {
// Read the event structure
notify_is->read(&event, sizeof(event));
// Read the event name
wpi::SmallString<64> raw_name;
wpi::util::SmallString<64> raw_name;
raw_name.resize(event.len);
notify_is->read(raw_name.data(), event.len);
// If the name is what we expect...
@@ -555,18 +555,18 @@ void UsbCameraImpl::CameraThreadMain() {
good = false;
}
if (good) {
Frame::Time frameTime{wpi::Now()};
Frame::Time frameTime{wpi::util::Now()};
WPI_TimestampSource timeSource{WPI_TIMESRC_FRAME_DEQUEUE};
// check the timestamp time
auto tsFlags = buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
SDEBUG4("Flags {}", tsFlags);
if (tsFlags == V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN) {
SDEBUG4("Got unknown time for frame - default to wpi::Now");
SDEBUG4("Got unknown time for frame - default to wpi::util::Now");
} else if (tsFlags == V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC) {
SDEBUG4("Got valid monotonic time for frame");
// we can't go directly to frametime, since the rest of cscore
// expects us to use wpi::Now, which is in an arbitrary timebase
// expects us to use wpi::util::Now, which is in an arbitrary timebase
// (see timestamp.cpp). Best I can do is (approximately) translate
// between timebases
@@ -595,7 +595,7 @@ void UsbCameraImpl::CameraThreadMain() {
// Can't do anything if we can't access the clock, leave default
}
} else if (tsFlags == V4L2_BUF_FLAG_TIMESTAMP_COPY) {
SDEBUG4("Got valid copy time for frame - default to wpi::Now");
SDEBUG4("Got valid copy time for frame - default to wpi::util::Now");
}
PutFrame(static_cast<VideoMode::PixelFormat>(m_mode.pixelFormat),
@@ -813,7 +813,7 @@ bool UsbCameraImpl::DeviceStreamOff() {
}
CS_StatusValue UsbCameraImpl::DeviceCmdSetMode(
std::unique_lock<wpi::mutex>& lock, const Message& msg) {
std::unique_lock<wpi::util::mutex>& lock, const Message& msg) {
VideoMode newMode;
if (msg.kind == Message::kCmdSetMode) {
newMode.pixelFormat = msg.data[0];
@@ -877,7 +877,7 @@ CS_StatusValue UsbCameraImpl::DeviceCmdSetMode(
}
CS_StatusValue UsbCameraImpl::DeviceCmdSetProperty(
std::unique_lock<wpi::mutex>& lock, const Message& msg) {
std::unique_lock<wpi::util::mutex>& lock, const Message& msg) {
bool setString = (msg.kind == Message::kCmdSetPropertyStr);
int property = msg.data[0];
int value = msg.data[1];
@@ -940,7 +940,7 @@ CS_StatusValue UsbCameraImpl::DeviceCmdSetProperty(
}
CS_StatusValue UsbCameraImpl::DeviceCmdSetPath(
std::unique_lock<wpi::mutex>& lock, const Message& msg) {
std::unique_lock<wpi::util::mutex>& lock, const Message& msg) {
m_path = msg.dataStr;
lock.unlock();
// disconnect and reconnect
@@ -960,7 +960,7 @@ CS_StatusValue UsbCameraImpl::DeviceCmdSetPath(
}
CS_StatusValue UsbCameraImpl::DeviceProcessCommand(
std::unique_lock<wpi::mutex>& lock, const Message& msg) {
std::unique_lock<wpi::util::mutex>& lock, const Message& msg) {
if (msg.kind == Message::kCmdSetMode ||
msg.kind == Message::kCmdSetPixelFormat ||
msg.kind == Message::kCmdSetResolution ||
@@ -1453,12 +1453,12 @@ bool UsbCameraImpl::CacheProperties(CS_Status* status) const {
}
void UsbCameraImpl::SetQuirks() {
wpi::SmallString<128> descbuf;
wpi::util::SmallString<128> descbuf;
std::string_view desc = GetDescription(descbuf);
m_lifecam_exposure = wpi::ends_with(desc, "LifeCam HD-3000") ||
wpi::ends_with(desc, "LifeCam Cinema (TM)");
m_ov9281_exposure = wpi::contains(desc, "OV9281");
m_picamera = wpi::ends_with(desc, "mmal service");
m_lifecam_exposure = wpi::util::ends_with(desc, "LifeCam HD-3000") ||
wpi::util::ends_with(desc, "LifeCam Cinema (TM)");
m_ov9281_exposure = wpi::util::contains(desc, "OV9281");
m_picamera = wpi::util::ends_with(desc, "mmal service");
int deviceNum = GetDeviceNum(m_path.c_str());
if (deviceNum >= 0) {
@@ -1611,7 +1611,7 @@ std::string UsbCameraImpl::GetPath() const {
return m_path;
}
namespace cs {
namespace wpi::cs {
CS_Source CreateUsbCameraDev(std::string_view name, int dev,
CS_Status* status) {
@@ -1668,7 +1668,7 @@ UsbCameraInfo GetUsbCameraInfo(CS_Source source, CS_Status* status) {
// look through /dev/v4l/by-id and /dev/v4l/by-path for symlinks to the
// keypath
wpi::SmallString<128> path;
wpi::util::SmallString<128> path;
for (auto symlinkDir : symlinkDirs) {
if (DIR* dp = ::opendir(symlinkDir)) {
while (struct dirent* ep = ::readdir(dp)) {
@@ -1703,13 +1703,13 @@ std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status) {
if (DIR* dp = ::opendir("/dev")) {
while (struct dirent* ep = ::readdir(dp)) {
std::string_view fname{ep->d_name};
if (!wpi::starts_with(fname, "video")) {
if (!wpi::util::starts_with(fname, "video")) {
continue;
}
unsigned int dev = 0;
if (auto v =
wpi::parse_integer<unsigned int>(wpi::substr(fname, 5), 10)) {
wpi::util::parse_integer<unsigned int>(wpi::util::substr(fname, 5), 10)) {
dev = v.value();
} else {
continue;
@@ -1718,7 +1718,7 @@ std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status) {
UsbCameraInfo info;
info.dev = dev;
wpi::SmallString<32> path{"/dev/"};
wpi::util::SmallString<32> path{"/dev/"};
path += fname;
info.path = path.str();
@@ -1747,7 +1747,7 @@ std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status) {
// look through /dev/v4l/by-id and /dev/v4l/by-path for symlinks to
// /dev/videoN
wpi::SmallString<128> path;
wpi::util::SmallString<128> path;
for (auto symlinkDir : symlinkDirs) {
if (DIR* dp = ::opendir(symlinkDir)) {
while (struct dirent* ep = ::readdir(dp)) {
@@ -1759,8 +1759,8 @@ std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status) {
if (target) {
std::string fname = fs::path{target}.filename();
std::optional<unsigned int> dev;
if (wpi::starts_with(fname, "video") &&
(dev = wpi::parse_integer<unsigned int>(wpi::substr(fname, 5),
if (wpi::util::starts_with(fname, "video") &&
(dev = wpi::util::parse_integer<unsigned int>(wpi::util::substr(fname, 5),
10)) &&
dev.value() < retval.size()) {
retval[dev.value()].otherPaths.emplace_back(path.str());
@@ -1782,4 +1782,4 @@ std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status) {
return retval;
}
} // namespace cs
} // namespace wpi::cs

View File

@@ -24,14 +24,14 @@
#include "wpi/util/raw_istream.hpp"
#include "wpi/util/raw_ostream.hpp"
namespace cs {
namespace wpi::cs {
class Notifier;
class Telemetry;
class UsbCameraImpl : public SourceImpl {
public:
UsbCameraImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier,
UsbCameraImpl(std::string_view name, wpi::util::Logger& logger, Notifier& notifier,
Telemetry& telemetry, std::string_view path);
~UsbCameraImpl() override;
@@ -123,13 +123,13 @@ class UsbCameraImpl : public SourceImpl {
void DeviceCacheVideoModes();
// Command helper functions
CS_StatusValue DeviceProcessCommand(std::unique_lock<wpi::mutex>& lock,
CS_StatusValue DeviceProcessCommand(std::unique_lock<wpi::util::mutex>& lock,
const Message& msg);
CS_StatusValue DeviceCmdSetMode(std::unique_lock<wpi::mutex>& lock,
CS_StatusValue DeviceCmdSetMode(std::unique_lock<wpi::util::mutex>& lock,
const Message& msg);
CS_StatusValue DeviceCmdSetProperty(std::unique_lock<wpi::mutex>& lock,
CS_StatusValue DeviceCmdSetProperty(std::unique_lock<wpi::util::mutex>& lock,
const Message& msg);
CS_StatusValue DeviceCmdSetPath(std::unique_lock<wpi::mutex>& lock,
CS_StatusValue DeviceCmdSetPath(std::unique_lock<wpi::util::mutex>& lock,
const Message& msg);
// Property helper functions
@@ -170,12 +170,12 @@ class UsbCameraImpl : public SourceImpl {
// Message queues
mutable std::vector<Message> m_commands;
mutable std::vector<std::pair<std::thread::id, CS_StatusValue>> m_responses;
mutable wpi::condition_variable m_responseCv;
mutable wpi::util::condition_variable m_responseCv;
// Path
std::string m_path;
};
} // namespace cs
} // namespace wpi::cs
#endif // CSCORE_USBCAMERAIMPL_HPP_

View File

@@ -13,7 +13,7 @@
#include "Notifier.hpp"
#include "wpi/util/StringExtras.hpp"
using namespace cs;
using namespace wpi::cs;
class UsbCameraListener::Impl {
public:
@@ -21,28 +21,28 @@ class UsbCameraListener::Impl {
Notifier& m_notifier;
std::unique_ptr<wpi::EventLoopRunner> m_runner;
std::unique_ptr<wpi::net::EventLoopRunner> m_runner;
};
UsbCameraListener::UsbCameraListener(wpi::Logger& logger, Notifier& notifier)
UsbCameraListener::UsbCameraListener(wpi::util::Logger& logger, Notifier& notifier)
: m_impl(std::make_unique<Impl>(notifier)) {}
UsbCameraListener::~UsbCameraListener() = default;
void UsbCameraListener::Start() {
if (!m_impl->m_runner) {
m_impl->m_runner = std::make_unique<wpi::EventLoopRunner>();
m_impl->m_runner->ExecAsync([impl = m_impl.get()](wpi::uv::Loop& loop) {
auto refreshTimer = wpi::uv::Timer::Create(loop);
m_impl->m_runner = std::make_unique<wpi::net::EventLoopRunner>();
m_impl->m_runner->ExecAsync([impl = m_impl.get()](wpi::net::uv::Loop& loop) {
auto refreshTimer = wpi::net::uv::Timer::Create(loop);
refreshTimer->timeout.connect([notifier = &impl->m_notifier] {
notifier->NotifyUsbCamerasChanged();
});
refreshTimer->Unreference();
auto devEvents = wpi::uv::FsEvent::Create(loop);
auto devEvents = wpi::net::uv::FsEvent::Create(loop);
devEvents->fsEvent.connect([refreshTimer](const char* fn, int flags) {
if (wpi::starts_with(fn, "video")) {
refreshTimer->Start(wpi::uv::Timer::Time(200));
if (wpi::util::starts_with(fn, "video")) {
refreshTimer->Start(wpi::net::uv::Timer::Time(200));
}
});
devEvents->Start("/dev");

View File

@@ -14,7 +14,7 @@
#include "wpi/util/SmallString.hpp"
#include "wpi/util/StringExtras.hpp"
using namespace cs;
using namespace wpi::cs;
static int GetIntCtrlIoctl(int fd, unsigned id, int type, int64_t* value) {
unsigned ctrl_class = V4L2_CTRL_ID2CLASS(id);
@@ -98,7 +98,7 @@ static int GetStringCtrlIoctl(int fd, int id, int maximum, std::string* value) {
static int SetStringCtrlIoctl(int fd, int id, int maximum,
std::string_view value) {
wpi::SmallString<64> str{wpi::substr(value, 0, maximum)};
wpi::util::SmallString<64> str{wpi::util::substr(value, 0, maximum)};
struct v4l2_ext_control ctrl;
struct v4l2_ext_controls ctrls;
@@ -116,7 +116,7 @@ static int SetStringCtrlIoctl(int fd, int id, int maximum,
// Removes non-alphanumeric characters and replaces spaces with underscores.
// e.g. "Zoom, Absolute" -> "zoom_absolute", "Pan (Absolute)" -> "pan_absolute"
static std::string_view NormalizeName(std::string_view name,
wpi::SmallVectorImpl<char>& buf) {
wpi::util::SmallVectorImpl<char>& buf) {
bool newWord = false;
for (auto ch : name) {
if (std::isalnum(ch)) {
@@ -170,7 +170,7 @@ UsbCameraProperty::UsbCameraProperty(const struct v4l2_query_ext_ctrl& ctrl)
while (len < sizeof(ctrl.name) && ctrl.name[len] != '\0') {
++len;
}
wpi::SmallString<64> name_buf;
wpi::util::SmallString<64> name_buf;
name = NormalizeName({ctrl.name, len}, name_buf);
}
#endif
@@ -209,7 +209,7 @@ UsbCameraProperty::UsbCameraProperty(const struct v4l2_queryctrl& ctrl)
while (len < sizeof(ctrl.name) && ctrl.name[len] != '\0') {
++len;
}
wpi::SmallString<64> name_buf;
wpi::util::SmallString<64> name_buf;
name =
NormalizeName({reinterpret_cast<const char*>(ctrl.name), len}, name_buf);
}
@@ -267,7 +267,7 @@ std::unique_ptr<UsbCameraProperty> UsbCameraProperty::DeviceQuery(int fd,
return prop;
}
bool UsbCameraProperty::DeviceGet(std::unique_lock<wpi::mutex>& lock, int fd) {
bool UsbCameraProperty::DeviceGet(std::unique_lock<wpi::util::mutex>& lock, int fd) {
if (fd < 0) {
return true;
}
@@ -306,14 +306,14 @@ bool UsbCameraProperty::DeviceGet(std::unique_lock<wpi::mutex>& lock, int fd) {
return rv >= 0;
}
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock,
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::util::mutex>& lock,
int fd) const {
// Make a copy of the string as we're about to release the lock
wpi::SmallString<128> valueStrCopy{valueStr};
wpi::util::SmallString<128> valueStrCopy{valueStr};
return DeviceSet(lock, fd, value, valueStrCopy.str());
}
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd,
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::util::mutex>& lock, int fd,
int newValue,
std::string_view newValueStr) const {
if (!device || fd < 0) {

View File

@@ -13,7 +13,7 @@
#include "PropertyImpl.hpp"
#include "wpi/util/mutex.hpp"
namespace cs {
namespace wpi::cs {
// Property data
class UsbCameraProperty : public PropertyImpl {
@@ -52,9 +52,9 @@ class UsbCameraProperty : public PropertyImpl {
static std::unique_ptr<UsbCameraProperty> DeviceQuery(int fd, __u32* id);
bool DeviceGet(std::unique_lock<wpi::mutex>& lock, int fd);
bool DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd) const;
bool DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd, int newValue,
bool DeviceGet(std::unique_lock<wpi::util::mutex>& lock, int fd);
bool DeviceSet(std::unique_lock<wpi::util::mutex>& lock, int fd) const;
bool DeviceSet(std::unique_lock<wpi::util::mutex>& lock, int fd, int newValue,
std::string_view newValueStr) const;
// If this is a device (rather than software) property
@@ -73,6 +73,6 @@ class UsbCameraProperty : public PropertyImpl {
bool intMenu{false};
};
} // namespace cs
} // namespace wpi::cs
#endif // CSCORE_USBCAMERAPROPERTY_HPP_

View File

@@ -19,7 +19,7 @@
#include "wpi/util/raw_istream.hpp"
#include "wpi/util/raw_ostream.hpp"
namespace cs {
namespace wpi::cs {
static std::string GetUsbNameFromFile(int vendor, int product) {
int fd = open("/var/lib/usbutils/usb.ids", O_RDONLY);
@@ -27,15 +27,15 @@ static std::string GetUsbNameFromFile(int vendor, int product) {
return {};
}
wpi::SmallString<128> buf;
wpi::raw_fd_istream is{fd, true};
wpi::util::SmallString<128> buf;
wpi::util::raw_fd_istream is{fd, true};
// build vendor and product 4-char hex strings
auto vendorStr = fmt::format("{:04x}", vendor);
auto productStr = fmt::format("{:04x}", product);
// scan file
wpi::SmallString<128> lineBuf;
wpi::util::SmallString<128> lineBuf;
bool foundVendor = false;
for (;;) {
auto line = is.getline(lineBuf, 4096);
@@ -48,9 +48,9 @@ static std::string GetUsbNameFromFile(int vendor, int product) {
}
// look for vendor at start of line
if (wpi::starts_with(line, vendorStr)) {
if (wpi::util::starts_with(line, vendorStr)) {
foundVendor = true;
buf += wpi::trim(wpi::substr(line, 5));
buf += wpi::util::trim(wpi::util::substr(line, 5));
buf += ' ';
continue;
}
@@ -63,8 +63,8 @@ static std::string GetUsbNameFromFile(int vendor, int product) {
}
// look for product
if (wpi::starts_with(wpi::substr(line, 1), productStr)) {
buf += wpi::trim(wpi::substr(line, 6));
if (wpi::util::starts_with(wpi::util::substr(line, 1), productStr)) {
buf += wpi::util::trim(wpi::util::substr(line, 6));
return std::string{buf};
}
}
@@ -161,4 +161,4 @@ int CheckedIoctl(int fd, unsigned long req, void* data, // NOLINT(runtime/int)
return retval;
}
} // namespace cs
} // namespace wpi::cs

View File

@@ -7,7 +7,7 @@
#include <string>
namespace cs {
namespace wpi::cs {
std::string GetUsbNameFromId(int vendor, int product);
@@ -19,6 +19,6 @@ int CheckedIoctl(int fd, unsigned long req, void* data, // NOLINT(runtime/int)
#define TryIoctl(fd, req, data) \
CheckedIoctl(fd, req, data, #req, __FILE__, __LINE__, true)
} // namespace cs
} // namespace wpi::cs
#endif // CSCORE_USBUTIL_HPP_