diff --git a/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp b/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp index cdd3ba9bad..dca14b9d4a 100644 --- a/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp +++ b/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp @@ -82,12 +82,10 @@ static wpi::StringRef MakeSourceValue(CS_Source source, return wpi::StringRef{buf.begin(), buf.size()}; } -static std::string MakeStreamValue(wpi::StringRef address, int port) { - std::string rv; - wpi::raw_string_ostream stream(rv); - stream << "mjpg:http://" << address << ':' << port << "/?action=stream"; - stream.flush(); - return rv; +static std::string MakeStreamValue(const wpi::Twine& address, int port) { + return ("mjpg:http://" + address + wpi::Twine(':') + wpi::Twine(port) + + "/?action=stream") + .str(); } std::shared_ptr CameraServer::Impl::GetSourceTable( @@ -223,14 +221,6 @@ static std::vector GetSourceModeValues(int source) { return rv; } -static inline wpi::StringRef Concatenate(wpi::StringRef lhs, wpi::StringRef rhs, - wpi::SmallVectorImpl& buf) { - buf.clear(); - wpi::raw_svector_ostream oss{buf}; - oss << lhs << rhs; - return oss.str(); -} - static void PutSourcePropertyValue(nt::NetworkTable* table, const cs::VideoEvent& event, bool isNew) { wpi::SmallString<64> name; @@ -261,13 +251,13 @@ static void PutSourcePropertyValue(nt::NetworkTable* table, case cs::VideoProperty::kEnum: if (isNew) { entry.SetDefaultDouble(event.value); - table->GetEntry(Concatenate(infoName, "/min", buf)) + table->GetEntry(infoName + "/min") .SetDouble(cs::GetPropertyMin(event.propertyHandle, &status)); - table->GetEntry(Concatenate(infoName, "/max", buf)) + table->GetEntry(infoName + "/max") .SetDouble(cs::GetPropertyMax(event.propertyHandle, &status)); - table->GetEntry(Concatenate(infoName, "/step", buf)) + table->GetEntry(infoName + "/step") .SetDouble(cs::GetPropertyStep(event.propertyHandle, &status)); - table->GetEntry(Concatenate(infoName, "/default", buf)) + table->GetEntry(infoName + "/default") .SetDouble(cs::GetPropertyDefault(event.propertyHandle, &status)); } else { entry.SetDouble(event.value); @@ -411,7 +401,7 @@ CameraServer::Impl::Impl() // else tries to change it. wpi::SmallString<64> buf; m_tableListener = nt::NetworkTableInstance::GetDefault().AddEntryListener( - Concatenate(kPublishName, "/", buf), + kPublishName + wpi::Twine('/'), [=](const nt::EntryNotification& event) { wpi::StringRef relativeKey = event.name.substr(wpi::StringRef(kPublishName).size() + 1); @@ -476,18 +466,14 @@ cs::UsbCamera CameraServer::StartAutomaticCapture() { } cs::UsbCamera CameraServer::StartAutomaticCapture(int dev) { - wpi::SmallString<64> buf; - wpi::raw_svector_ostream name{buf}; - name << "USB Camera " << dev; - - cs::UsbCamera camera{name.str(), dev}; + cs::UsbCamera camera{"USB Camera " + wpi::Twine(dev), dev}; StartAutomaticCapture(camera); auto csShared = GetCameraServerShared(); csShared->ReportUsbCamera(camera.GetHandle()); return camera; } -cs::UsbCamera CameraServer::StartAutomaticCapture(wpi::StringRef name, +cs::UsbCamera CameraServer::StartAutomaticCapture(const wpi::Twine& name, int dev) { cs::UsbCamera camera{name, dev}; StartAutomaticCapture(camera); @@ -496,8 +482,8 @@ cs::UsbCamera CameraServer::StartAutomaticCapture(wpi::StringRef name, return camera; } -cs::UsbCamera CameraServer::StartAutomaticCapture(wpi::StringRef name, - wpi::StringRef path) { +cs::UsbCamera CameraServer::StartAutomaticCapture(const wpi::Twine& name, + const wpi::Twine& path) { cs::UsbCamera camera{name, path}; StartAutomaticCapture(camera); auto csShared = GetCameraServerShared(); @@ -506,7 +492,7 @@ cs::UsbCamera CameraServer::StartAutomaticCapture(wpi::StringRef name, } #endif -cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef host) { +cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& host) { return AddAxisCamera("Axis Camera", host); } @@ -522,8 +508,8 @@ cs::AxisCamera CameraServer::AddAxisCamera(wpi::ArrayRef hosts) { return AddAxisCamera("Axis Camera", hosts); } -cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef name, - wpi::StringRef host) { +cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name, + const wpi::Twine& host) { cs::AxisCamera camera{name, host}; StartAutomaticCapture(camera); auto csShared = GetCameraServerShared(); @@ -531,7 +517,7 @@ cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef name, return camera; } -cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef name, +cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name, const char* host) { cs::AxisCamera camera{name, host}; StartAutomaticCapture(camera); @@ -540,7 +526,7 @@ cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef name, return camera; } -cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef name, +cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name, const std::string& host) { cs::AxisCamera camera{name, host}; StartAutomaticCapture(camera); @@ -549,7 +535,7 @@ cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef name, return camera; } -cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef name, +cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name, wpi::ArrayRef hosts) { cs::AxisCamera camera{name, hosts}; StartAutomaticCapture(camera); @@ -559,11 +545,8 @@ cs::AxisCamera CameraServer::AddAxisCamera(wpi::StringRef name, } void CameraServer::StartAutomaticCapture(const cs::VideoSource& camera) { - wpi::SmallString<64> name{"serve_"}; - name += camera.GetName(); - AddCamera(camera); - auto server = AddServer(name); + auto server = AddServer(wpi::Twine("serve_") + camera.GetName()); server.SetSource(camera); } @@ -596,11 +579,9 @@ cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) { if (it != m_impl->m_sinks.end()) { auto kind = it->second.GetKind(); if (kind != cs::VideoSink::kCv) { - wpi::SmallString<64> buf; - wpi::raw_svector_ostream err{buf}; - err << "expected OpenCV sink, but got " << kind; auto csShared = GetCameraServerShared(); - csShared->SetCameraServerError(err.str()); + csShared->SetCameraServerError("expected OpenCV sink, but got " + + wpi::Twine(kind)); return cs::CvSink{}; } return *static_cast(&it->second); @@ -613,17 +594,16 @@ cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) { return newsink; } -cs::CvSink CameraServer::GetVideo(wpi::StringRef name) { +cs::CvSink CameraServer::GetVideo(const wpi::Twine& name) { + wpi::SmallString<64> nameBuf; + wpi::StringRef nameStr = name.toStringRef(nameBuf); cs::VideoSource source; { std::lock_guard lock(m_impl->m_mutex); - auto it = m_impl->m_sources.find(name); + auto it = m_impl->m_sources.find(nameStr); if (it == m_impl->m_sources.end()) { - wpi::SmallString<64> buf; - wpi::raw_svector_ostream err{buf}; - err << "could not find camera " << name; auto csShared = GetCameraServerShared(); - csShared->SetCameraServerError(err.str()); + csShared->SetCameraServerError("could not find camera " + nameStr); return cs::CvSink{}; } source = it->second; @@ -631,14 +611,14 @@ cs::CvSink CameraServer::GetVideo(wpi::StringRef name) { return GetVideo(source); } -cs::CvSource CameraServer::PutVideo(wpi::StringRef name, int width, +cs::CvSource CameraServer::PutVideo(const wpi::Twine& name, int width, int height) { cs::CvSource source{name, cs::VideoMode::kMJPEG, width, height, 30}; StartAutomaticCapture(source); return source; } -cs::MjpegServer CameraServer::AddServer(wpi::StringRef name) { +cs::MjpegServer CameraServer::AddServer(const wpi::Twine& name) { int port; { std::lock_guard lock(m_impl->m_mutex); @@ -647,7 +627,7 @@ cs::MjpegServer CameraServer::AddServer(wpi::StringRef name) { return AddServer(name, port); } -cs::MjpegServer CameraServer::AddServer(wpi::StringRef name, int port) { +cs::MjpegServer CameraServer::AddServer(const wpi::Twine& name, int port) { cs::MjpegServer server{name, port}; AddServer(server); return server; @@ -658,9 +638,10 @@ void CameraServer::AddServer(const cs::VideoSink& server) { m_impl->m_sinks.try_emplace(server.GetName(), server); } -void CameraServer::RemoveServer(wpi::StringRef name) { +void CameraServer::RemoveServer(const wpi::Twine& name) { std::lock_guard lock(m_impl->m_mutex); - m_impl->m_sinks.erase(name); + wpi::SmallString<64> nameBuf; + m_impl->m_sinks.erase(name.toStringRef(nameBuf)); } cs::VideoSink CameraServer::GetServer() { @@ -678,15 +659,14 @@ cs::VideoSink CameraServer::GetServer() { return GetServer(name); } -cs::VideoSink CameraServer::GetServer(wpi::StringRef name) { +cs::VideoSink CameraServer::GetServer(const wpi::Twine& name) { + wpi::SmallString<64> nameBuf; + wpi::StringRef nameStr = name.toStringRef(nameBuf); std::lock_guard lock(m_impl->m_mutex); - auto it = m_impl->m_sinks.find(name); + auto it = m_impl->m_sinks.find(nameStr); if (it == m_impl->m_sinks.end()) { - wpi::SmallString<64> buf; - wpi::raw_svector_ostream err{buf}; - err << "could not find server " << name; auto csShared = GetCameraServerShared(); - csShared->SetCameraServerError(err.str()); + csShared->SetCameraServerError("could not find server " + nameStr); return cs::VideoSink{}; } return it->second; @@ -699,9 +679,10 @@ void CameraServer::AddCamera(const cs::VideoSource& camera) { m_impl->m_sources.try_emplace(name, camera); } -void CameraServer::RemoveCamera(wpi::StringRef name) { +void CameraServer::RemoveCamera(const wpi::Twine& name) { std::lock_guard lock(m_impl->m_mutex); - m_impl->m_sources.erase(name); + wpi::SmallString<64> nameBuf; + m_impl->m_sources.erase(name.toStringRef(nameBuf)); } void CameraServer::SetSize(int size) { diff --git a/cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp b/cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp index 1095899961..97ab0904aa 100644 --- a/cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp +++ b/cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp @@ -15,9 +15,9 @@ class DefaultCameraServerShared : public frc::CameraServerShared { void ReportUsbCamera(int id) override {} void ReportAxisCamera(int id) override {} void ReportVideoServer(int id) override {} - void SetCameraServerError(wpi::StringRef error) override {} - void SetVisionRunnerError(wpi::StringRef error) override {} - void ReportDriverStationError(wpi::StringRef error) override {} + void SetCameraServerError(const wpi::Twine& error) override {} + void SetVisionRunnerError(const wpi::Twine& error) override {} + void ReportDriverStationError(const wpi::Twine& error) override {} std::pair GetRobotMainThreadId() const override { return std::make_pair(std::thread::id(), false); } diff --git a/cameraserver/src/main/native/include/cameraserver/CameraServer.h b/cameraserver/src/main/native/include/cameraserver/CameraServer.h index 82ef061e7f..261d84958d 100644 --- a/cameraserver/src/main/native/include/cameraserver/CameraServer.h +++ b/cameraserver/src/main/native/include/cameraserver/CameraServer.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include "cscore.h" @@ -67,7 +67,7 @@ class CameraServer { * @param name The name to give the camera * @param dev The device number of the camera interface */ - cs::UsbCamera StartAutomaticCapture(wpi::StringRef name, int dev); + cs::UsbCamera StartAutomaticCapture(const wpi::Twine& name, int dev); /** * Start automatically capturing images to send to the dashboard. @@ -75,7 +75,8 @@ class CameraServer { * @param name The name to give the camera * @param path The device path (e.g. "/dev/video0") of the camera */ - cs::UsbCamera StartAutomaticCapture(wpi::StringRef name, wpi::StringRef path); + cs::UsbCamera StartAutomaticCapture(const wpi::Twine& name, + const wpi::Twine& path); #endif /** @@ -93,7 +94,7 @@ class CameraServer { * * @param host Camera host IP or DNS name (e.g. "10.x.y.11") */ - cs::AxisCamera AddAxisCamera(wpi::StringRef host); + cs::AxisCamera AddAxisCamera(const wpi::Twine& host); /** * Adds an Axis IP camera. @@ -138,7 +139,7 @@ class CameraServer { * @param name The name to give the camera * @param host Camera host IP or DNS name (e.g. "10.x.y.11") */ - cs::AxisCamera AddAxisCamera(wpi::StringRef name, wpi::StringRef host); + cs::AxisCamera AddAxisCamera(const wpi::Twine& name, const wpi::Twine& host); /** * Adds an Axis IP camera. @@ -146,7 +147,7 @@ class CameraServer { * @param name The name to give the camera * @param host Camera host IP or DNS name (e.g. "10.x.y.11") */ - cs::AxisCamera AddAxisCamera(wpi::StringRef name, const char* host); + cs::AxisCamera AddAxisCamera(const wpi::Twine& name, const char* host); /** * Adds an Axis IP camera. @@ -154,7 +155,7 @@ class CameraServer { * @param name The name to give the camera * @param host Camera host IP or DNS name (e.g. "10.x.y.11") */ - cs::AxisCamera AddAxisCamera(wpi::StringRef name, const std::string& host); + cs::AxisCamera AddAxisCamera(const wpi::Twine& name, const std::string& host); /** * Adds an Axis IP camera. @@ -162,7 +163,7 @@ class CameraServer { * @param name The name to give the camera * @param hosts Array of Camera host IPs/DNS names */ - cs::AxisCamera AddAxisCamera(wpi::StringRef name, + cs::AxisCamera AddAxisCamera(const wpi::Twine& name, wpi::ArrayRef hosts); /** @@ -172,7 +173,7 @@ class CameraServer { * @param hosts Array of Camera host IPs/DNS names */ template - cs::AxisCamera AddAxisCamera(wpi::StringRef name, + cs::AxisCamera AddAxisCamera(const wpi::Twine& name, std::initializer_list hosts); /** @@ -198,7 +199,7 @@ class CameraServer { * * @param name Camera name */ - cs::CvSink GetVideo(wpi::StringRef name); + cs::CvSink GetVideo(const wpi::Twine& name); /** * Create a MJPEG stream with OpenCV input. This can be called to pass custom @@ -208,21 +209,21 @@ class CameraServer { * @param width Width of the image being sent * @param height Height of the image being sent */ - cs::CvSource PutVideo(wpi::StringRef name, int width, int height); + cs::CvSource PutVideo(const wpi::Twine& name, int width, int height); /** * Adds a MJPEG server at the next available port. * * @param name Server name */ - cs::MjpegServer AddServer(wpi::StringRef name); + cs::MjpegServer AddServer(const wpi::Twine& name); /** * Adds a MJPEG server. * * @param name Server name */ - cs::MjpegServer AddServer(wpi::StringRef name, int port); + cs::MjpegServer AddServer(const wpi::Twine& name, int port); /** * Adds an already created server. @@ -236,7 +237,7 @@ class CameraServer { * * @param name Server name */ - void RemoveServer(wpi::StringRef name); + void RemoveServer(const wpi::Twine& name); /** * Get server for the primary camera feed. @@ -251,7 +252,7 @@ class CameraServer { * * @param name Server name */ - cs::VideoSink GetServer(wpi::StringRef name); + cs::VideoSink GetServer(const wpi::Twine& name); /** * Adds an already created camera. @@ -265,7 +266,7 @@ class CameraServer { * * @param name Camera name */ - void RemoveCamera(wpi::StringRef name); + void RemoveCamera(const wpi::Twine& name); /** * Sets the size of the image to use. Use the public kSize constants to set diff --git a/cameraserver/src/main/native/include/cameraserver/CameraServer.inc b/cameraserver/src/main/native/include/cameraserver/CameraServer.inc index bf3272e841..5daf29f70b 100644 --- a/cameraserver/src/main/native/include/cameraserver/CameraServer.inc +++ b/cameraserver/src/main/native/include/cameraserver/CameraServer.inc @@ -20,7 +20,7 @@ inline cs::AxisCamera CameraServer::AddAxisCamera( template inline cs::AxisCamera CameraServer::AddAxisCamera( - wpi::StringRef name, std::initializer_list hosts) { + const wpi::Twine& name, std::initializer_list hosts) { std::vector vec; vec.reserve(hosts.size()); for (const auto& host : hosts) vec.emplace_back(host); diff --git a/cameraserver/src/main/native/include/cameraserver/CameraServerShared.h b/cameraserver/src/main/native/include/cameraserver/CameraServerShared.h index ff0ceac771..8dbad3644a 100644 --- a/cameraserver/src/main/native/include/cameraserver/CameraServerShared.h +++ b/cameraserver/src/main/native/include/cameraserver/CameraServerShared.h @@ -11,7 +11,7 @@ #include #include -#include +#include namespace frc { class CameraServerShared { @@ -19,9 +19,9 @@ class CameraServerShared { virtual void ReportUsbCamera(int id) = 0; virtual void ReportAxisCamera(int id) = 0; virtual void ReportVideoServer(int id) = 0; - virtual void SetCameraServerError(wpi::StringRef error) = 0; - virtual void SetVisionRunnerError(wpi::StringRef error) = 0; - virtual void ReportDriverStationError(wpi::StringRef error) = 0; + virtual void SetCameraServerError(const wpi::Twine& error) = 0; + virtual void SetVisionRunnerError(const wpi::Twine& error) = 0; + virtual void ReportDriverStationError(const wpi::Twine& error) = 0; virtual std::pair GetRobotMainThreadId() const = 0; }; diff --git a/cscore/src/main/native/cpp/CvSinkImpl.cpp b/cscore/src/main/native/cpp/CvSinkImpl.cpp index 3cdc93db07..3f2d902f23 100644 --- a/cscore/src/main/native/cpp/CvSinkImpl.cpp +++ b/cscore/src/main/native/cpp/CvSinkImpl.cpp @@ -20,12 +20,12 @@ using namespace cs; -CvSinkImpl::CvSinkImpl(wpi::StringRef name) : SinkImpl{name} { +CvSinkImpl::CvSinkImpl(const wpi::Twine& name) : SinkImpl{name} { m_active = true; // m_thread = std::thread(&CvSinkImpl::ThreadMain, this); } -CvSinkImpl::CvSinkImpl(wpi::StringRef name, +CvSinkImpl::CvSinkImpl(const wpi::Twine& name, std::function processFrame) : SinkImpl{name} {} @@ -118,14 +118,14 @@ void CvSinkImpl::ThreadMain() { namespace cs { -CS_Sink CreateCvSink(wpi::StringRef name, CS_Status* status) { +CS_Sink CreateCvSink(const wpi::Twine& name, CS_Status* status) { auto sink = std::make_shared(name); auto handle = Sinks::GetInstance().Allocate(CS_SINK_CV, sink); Notifier::GetInstance().NotifySink(name, handle, CS_SINK_CREATED); return handle; } -CS_Sink CreateCvSinkCallback(wpi::StringRef name, +CS_Sink CreateCvSinkCallback(const wpi::Twine& name, std::function processFrame, CS_Status* status) { auto sink = std::make_shared(name, processFrame); @@ -134,7 +134,7 @@ CS_Sink CreateCvSinkCallback(wpi::StringRef name, return handle; } -void SetSinkDescription(CS_Sink sink, wpi::StringRef description, +void SetSinkDescription(CS_Sink sink, const wpi::Twine& description, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); if (!data || data->kind != CS_SINK_CV) { diff --git a/cscore/src/main/native/cpp/CvSinkImpl.h b/cscore/src/main/native/cpp/CvSinkImpl.h index 7ef764baea..36452dbe85 100644 --- a/cscore/src/main/native/cpp/CvSinkImpl.h +++ b/cscore/src/main/native/cpp/CvSinkImpl.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -29,8 +30,8 @@ class SourceImpl; class CvSinkImpl : public SinkImpl { public: - explicit CvSinkImpl(wpi::StringRef name); - CvSinkImpl(wpi::StringRef name, + explicit CvSinkImpl(const wpi::Twine& name); + CvSinkImpl(const wpi::Twine& name, std::function processFrame); ~CvSinkImpl() override; diff --git a/cscore/src/main/native/cpp/CvSourceImpl.cpp b/cscore/src/main/native/cpp/CvSourceImpl.cpp index 1be71480bb..cf3c845a51 100644 --- a/cscore/src/main/native/cpp/CvSourceImpl.cpp +++ b/cscore/src/main/native/cpp/CvSourceImpl.cpp @@ -21,7 +21,7 @@ using namespace cs; -CvSourceImpl::CvSourceImpl(wpi::StringRef name, const VideoMode& mode) +CvSourceImpl::CvSourceImpl(const wpi::Twine& name, const VideoMode& mode) : SourceImpl{name} { m_mode = mode; m_videoModes.push_back(m_mode); @@ -82,11 +82,11 @@ void CvSourceImpl::PutFrame(cv::Mat& image) { SourceImpl::PutFrame(std::move(dest), wpi::Now()); } -void CvSourceImpl::NotifyError(wpi::StringRef msg) { +void CvSourceImpl::NotifyError(const wpi::Twine& msg) { PutError(msg, wpi::Now()); } -int CvSourceImpl::CreateProperty(wpi::StringRef name, CS_PropertyKind kind, +int CvSourceImpl::CreateProperty(const wpi::Twine& name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value) { std::lock_guard lock(m_mutex); @@ -106,13 +106,12 @@ int CvSourceImpl::CreateProperty(wpi::StringRef name, CS_PropertyKind kind, value = prop.value; }); Notifier::GetInstance().NotifySourceProperty( - *this, CS_SOURCE_PROPERTY_CREATED, name, ndx, kind, value, - wpi::StringRef{}); + *this, CS_SOURCE_PROPERTY_CREATED, name, ndx, kind, value, wpi::Twine{}); return ndx; } int CvSourceImpl::CreateProperty( - wpi::StringRef name, CS_PropertyKind kind, int minimum, int maximum, + const wpi::Twine& name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, std::function onChange) { // TODO @@ -135,12 +134,12 @@ void CvSourceImpl::SetEnumPropertyChoices(int property, prop->enumChoices = choices; Notifier::GetInstance().NotifySourceProperty( *this, CS_SOURCE_PROPERTY_CHOICES_UPDATED, prop->name, property, - CS_PROP_ENUM, prop->value, wpi::StringRef{}); + CS_PROP_ENUM, prop->value, wpi::Twine{}); } namespace cs { -CS_Source CreateCvSource(wpi::StringRef name, const VideoMode& mode, +CS_Source CreateCvSource(const wpi::Twine& name, const VideoMode& mode, CS_Status* status) { auto source = std::make_shared(name, mode); auto handle = Sources::GetInstance().Allocate(CS_SOURCE_CV, source); @@ -163,7 +162,7 @@ void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status) { static_cast(*data->source).PutFrame(image); } -void NotifySourceError(CS_Source source, wpi::StringRef msg, +void NotifySourceError(CS_Source source, const wpi::Twine& msg, CS_Status* status) { auto data = Sources::GetInstance().Get(source); if (!data || data->kind != CS_SOURCE_CV) { @@ -182,7 +181,7 @@ void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) { static_cast(*data->source).SetConnected(connected); } -void SetSourceDescription(CS_Source source, wpi::StringRef description, +void SetSourceDescription(CS_Source source, const wpi::Twine& description, CS_Status* status) { auto data = Sources::GetInstance().Get(source); if (!data || data->kind != CS_SOURCE_CV) { @@ -192,7 +191,7 @@ void SetSourceDescription(CS_Source source, wpi::StringRef description, static_cast(*data->source).SetDescription(description); } -CS_Property CreateSourceProperty(CS_Source source, wpi::StringRef name, +CS_Property CreateSourceProperty(CS_Source source, const wpi::Twine& name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, CS_Status* status) { @@ -208,7 +207,7 @@ CS_Property CreateSourceProperty(CS_Source source, wpi::StringRef name, } CS_Property CreateSourcePropertyCallback( - CS_Source source, wpi::StringRef name, CS_PropertyKind kind, int minimum, + CS_Source source, const wpi::Twine& name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, std::function onChange, CS_Status* status) { auto data = Sources::GetInstance().Get(source); diff --git a/cscore/src/main/native/cpp/CvSourceImpl.h b/cscore/src/main/native/cpp/CvSourceImpl.h index b888e838a9..4de1bcb3a4 100644 --- a/cscore/src/main/native/cpp/CvSourceImpl.h +++ b/cscore/src/main/native/cpp/CvSourceImpl.h @@ -20,7 +20,7 @@ namespace cs { class CvSourceImpl : public SourceImpl { public: - CvSourceImpl(wpi::StringRef name, const VideoMode& mode); + CvSourceImpl(const wpi::Twine& name, const VideoMode& mode); ~CvSourceImpl() override; void Start(); @@ -32,10 +32,10 @@ class CvSourceImpl : public SourceImpl { // OpenCV-specific functions void PutFrame(cv::Mat& image); - void NotifyError(wpi::StringRef msg); - int CreateProperty(wpi::StringRef name, CS_PropertyKind kind, int minimum, + void NotifyError(const wpi::Twine& msg); + int CreateProperty(const wpi::Twine& name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value); - int CreateProperty(wpi::StringRef name, CS_PropertyKind kind, int minimum, + int CreateProperty(const wpi::Twine& name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, std::function onChange); void SetEnumPropertyChoices(int property, wpi::ArrayRef choices, diff --git a/cscore/src/main/native/cpp/Frame.cpp b/cscore/src/main/native/cpp/Frame.cpp index eb8a5c0fd0..68edfe49c3 100644 --- a/cscore/src/main/native/cpp/Frame.cpp +++ b/cscore/src/main/native/cpp/Frame.cpp @@ -18,10 +18,10 @@ using namespace cs; -Frame::Frame(SourceImpl& source, wpi::StringRef error, Time time) +Frame::Frame(SourceImpl& source, const wpi::Twine& error, Time time) : m_impl{source.AllocFrameImpl().release()} { m_impl->refcount = 1; - m_impl->error = error; + m_impl->error = error.str(); m_impl->time = time; } diff --git a/cscore/src/main/native/cpp/Frame.h b/cscore/src/main/native/cpp/Frame.h index ed4e67dac4..07bf5b0ae1 100644 --- a/cscore/src/main/native/cpp/Frame.h +++ b/cscore/src/main/native/cpp/Frame.h @@ -15,6 +15,7 @@ #include #include +#include #include #include "Image.h" @@ -46,7 +47,7 @@ class Frame { public: Frame() noexcept : m_impl{nullptr} {} - Frame(SourceImpl& source, wpi::StringRef error, Time time); + Frame(SourceImpl& source, const wpi::Twine& error, Time time); Frame(SourceImpl& source, std::unique_ptr image, Time time); diff --git a/cscore/src/main/native/cpp/HttpCameraImpl.cpp b/cscore/src/main/native/cpp/HttpCameraImpl.cpp index e87891ea7d..17456ad2c3 100644 --- a/cscore/src/main/native/cpp/HttpCameraImpl.cpp +++ b/cscore/src/main/native/cpp/HttpCameraImpl.cpp @@ -21,7 +21,7 @@ using namespace cs; -HttpCameraImpl::HttpCameraImpl(wpi::StringRef name, CS_HttpCameraKind kind) +HttpCameraImpl::HttpCameraImpl(const wpi::Twine& name, CS_HttpCameraKind kind) : SourceImpl{name}, m_kind{kind} {} HttpCameraImpl::~HttpCameraImpl() { @@ -332,11 +332,11 @@ std::vector HttpCameraImpl::GetUrls() const { return urls; } -void HttpCameraImpl::CreateProperty(wpi::StringRef name, - wpi::StringRef httpParam, bool viaSettings, - CS_PropertyKind kind, int minimum, - int maximum, int step, int defaultValue, - int value) const { +void HttpCameraImpl::CreateProperty(const wpi::Twine& name, + const wpi::Twine& httpParam, + bool viaSettings, CS_PropertyKind kind, + int minimum, int maximum, int step, + int defaultValue, int value) const { std::lock_guard lock(m_mutex); m_propertyData.emplace_back(wpi::make_unique( name, httpParam, viaSettings, kind, minimum, maximum, step, defaultValue, @@ -344,12 +344,12 @@ void HttpCameraImpl::CreateProperty(wpi::StringRef name, Notifier::GetInstance().NotifySourceProperty( *this, CS_SOURCE_PROPERTY_CREATED, name, m_propertyData.size() + 1, kind, - value, wpi::StringRef{}); + value, wpi::Twine{}); } template void HttpCameraImpl::CreateEnumProperty( - wpi::StringRef name, wpi::StringRef httpParam, bool viaSettings, + const wpi::Twine& name, const wpi::Twine& httpParam, bool viaSettings, int defaultValue, int value, std::initializer_list choices) const { std::lock_guard lock(m_mutex); m_propertyData.emplace_back(wpi::make_unique( @@ -362,14 +362,14 @@ void HttpCameraImpl::CreateEnumProperty( Notifier::GetInstance().NotifySourceProperty( *this, CS_SOURCE_PROPERTY_CREATED, name, m_propertyData.size() + 1, - CS_PROP_ENUM, value, wpi::StringRef{}); + CS_PROP_ENUM, value, wpi::Twine{}); Notifier::GetInstance().NotifySourceProperty( *this, CS_SOURCE_PROPERTY_CHOICES_UPDATED, name, - m_propertyData.size() + 1, CS_PROP_ENUM, value, wpi::StringRef{}); + m_propertyData.size() + 1, CS_PROP_ENUM, value, wpi::Twine{}); } std::unique_ptr HttpCameraImpl::CreateEmptyProperty( - wpi::StringRef name) const { + const wpi::Twine& name) const { return wpi::make_unique(name); } @@ -390,7 +390,7 @@ void HttpCameraImpl::SetProperty(int property, int value, CS_Status* status) { // TODO } -void HttpCameraImpl::SetStringProperty(int property, wpi::StringRef value, +void HttpCameraImpl::SetStringProperty(int property, const wpi::Twine& value, CS_Status* status) { // TODO } @@ -474,7 +474,7 @@ bool AxisCameraImpl::CacheProperties(CS_Status* status) const { namespace cs { -CS_Source CreateHttpCamera(wpi::StringRef name, wpi::StringRef url, +CS_Source CreateHttpCamera(const wpi::Twine& name, const wpi::Twine& url, CS_HttpCameraKind kind, CS_Status* status) { std::shared_ptr source; switch (kind) { @@ -485,8 +485,7 @@ CS_Source CreateHttpCamera(wpi::StringRef name, wpi::StringRef url, source = std::make_shared(name, kind); break; } - std::string urlCopy{url}; - if (!source->SetUrls(urlCopy, status)) return 0; + if (!source->SetUrls(url.str(), status)) return 0; auto handle = Sources::GetInstance().Allocate(CS_SOURCE_HTTP, source); auto& notifier = Notifier::GetInstance(); notifier.NotifySource(name, handle, CS_SOURCE_CREATED); @@ -494,7 +493,8 @@ CS_Source CreateHttpCamera(wpi::StringRef name, wpi::StringRef url, return handle; } -CS_Source CreateHttpCamera(wpi::StringRef name, wpi::ArrayRef urls, +CS_Source CreateHttpCamera(const wpi::Twine& name, + wpi::ArrayRef urls, CS_HttpCameraKind kind, CS_Status* status) { if (urls.empty()) { *status = CS_EMPTY_VALUE; diff --git a/cscore/src/main/native/cpp/HttpCameraImpl.h b/cscore/src/main/native/cpp/HttpCameraImpl.h index 2f666d4d2b..201aebd855 100644 --- a/cscore/src/main/native/cpp/HttpCameraImpl.h +++ b/cscore/src/main/native/cpp/HttpCameraImpl.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -29,14 +30,14 @@ namespace cs { class HttpCameraImpl : public SourceImpl { public: - HttpCameraImpl(wpi::StringRef name, CS_HttpCameraKind kind); + HttpCameraImpl(const wpi::Twine& name, CS_HttpCameraKind kind); ~HttpCameraImpl() override; void Start(); // Property functions void SetProperty(int property, int value, CS_Status* status) override; - void SetStringProperty(int property, wpi::StringRef value, + void SetStringProperty(int property, const wpi::Twine& value, CS_Status* status) override; // Standard common camera properties @@ -62,13 +63,13 @@ class HttpCameraImpl : public SourceImpl { class PropertyData : public PropertyImpl { public: PropertyData() = default; - explicit PropertyData(wpi::StringRef name_) : PropertyImpl{name_} {} - PropertyData(wpi::StringRef name_, wpi::StringRef httpParam_, + explicit PropertyData(const wpi::Twine& name_) : PropertyImpl{name_} {} + PropertyData(const wpi::Twine& name_, const wpi::Twine& httpParam_, bool viaSettings_, CS_PropertyKind kind_, int minimum_, int maximum_, int step_, int defaultValue_, int value_) : PropertyImpl(name_, kind_, step_, defaultValue_, value_), viaSettings(viaSettings_), - httpParam(httpParam_) { + httpParam(httpParam_.str()) { hasMinimum = true; minimum = minimum_; hasMaximum = true; @@ -82,16 +83,16 @@ class HttpCameraImpl : public SourceImpl { protected: std::unique_ptr CreateEmptyProperty( - wpi::StringRef name) const override; + const wpi::Twine& name) const override; bool CacheProperties(CS_Status* status) const override; - void CreateProperty(wpi::StringRef name, wpi::StringRef httpParam, + void CreateProperty(const wpi::Twine& name, const wpi::Twine& httpParam, bool viaSettings, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value) const; template - void CreateEnumProperty(wpi::StringRef name, wpi::StringRef httpParam, + void CreateEnumProperty(const wpi::Twine& name, const wpi::Twine& httpParam, bool viaSettings, int defaultValue, int value, std::initializer_list choices) const; @@ -139,11 +140,11 @@ class HttpCameraImpl : public SourceImpl { class AxisCameraImpl : public HttpCameraImpl { public: - explicit AxisCameraImpl(wpi::StringRef name) + explicit AxisCameraImpl(const wpi::Twine& name) : HttpCameraImpl{name, CS_HTTP_AXIS} {} #if 0 void SetProperty(int property, int value, CS_Status* status) override; - void SetStringProperty(int property, wpi::StringRef value, + void SetStringProperty(int property, const wpi::Twine& value, CS_Status* status) override; #endif protected: diff --git a/cscore/src/main/native/cpp/MjpegServerImpl.cpp b/cscore/src/main/native/cpp/MjpegServerImpl.cpp index 299419023f..51606f3f8a 100644 --- a/cscore/src/main/native/cpp/MjpegServerImpl.cpp +++ b/cscore/src/main/native/cpp/MjpegServerImpl.cpp @@ -73,7 +73,7 @@ static const char* endRootPage = ""; class MjpegServerImpl::ConnThread : public wpi::SafeThread { public: - explicit ConnThread(wpi::StringRef name) : m_name(name) {} + explicit ConnThread(const wpi::Twine& name) : m_name(name.str()) {} void Main(); @@ -124,9 +124,10 @@ class MjpegServerImpl::ConnThread : public wpi::SafeThread { // A browser should connect for each file and not serve files from its cache. // Using cached pictures would lead to showing old/outdated pictures. // Many browsers seem to ignore, or at least not always obey, those headers. -static void SendHeader(wpi::raw_ostream& os, int code, wpi::StringRef codeText, - wpi::StringRef contentType, - wpi::StringRef extra = wpi::StringRef{}) { +static void SendHeader(wpi::raw_ostream& os, int code, + const wpi::Twine& codeText, + const wpi::Twine& contentType, + const wpi::Twine& extra = wpi::Twine{}) { os << "HTTP/1.0 " << code << ' ' << codeText << "\r\n"; os << "Connection: close\r\n" "Server: CameraServer/1.0\r\n" @@ -136,14 +137,17 @@ static void SendHeader(wpi::raw_ostream& os, int code, wpi::StringRef codeText, "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"; os << "Content-Type: " << contentType << "\r\n"; os << "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: *\r\n"; - if (!extra.empty()) os << extra << "\r\n"; + wpi::SmallString<128> extraBuf; + wpi::StringRef extraStr = extra.toStringRef(extraBuf); + if (!extraStr.empty()) os << extraStr << "\r\n"; os << "\r\n"; // header ends with a blank line } // Send error header and message // @param code HTTP error code (e.g. 404) // @param message Additional message text -static void SendError(wpi::raw_ostream& os, int code, wpi::StringRef message) { +static void SendError(wpi::raw_ostream& os, int code, + const wpi::Twine& message) { wpi::StringRef codeText, extra, baseMessage; switch (code) { case 401: @@ -544,11 +548,11 @@ void MjpegServerImpl::ConnThread::SendJSON(wpi::raw_ostream& os, os.flush(); } -MjpegServerImpl::MjpegServerImpl(wpi::StringRef name, - wpi::StringRef listenAddress, int port, +MjpegServerImpl::MjpegServerImpl(const wpi::Twine& name, + const wpi::Twine& listenAddress, int port, std::unique_ptr acceptor) : SinkImpl{name}, - m_listenAddress(listenAddress), + m_listenAddress(listenAddress.str()), m_port(port), m_acceptor{std::move(acceptor)} { m_active = true; @@ -905,13 +909,16 @@ void MjpegServerImpl::SetSourceImpl(std::shared_ptr source) { namespace cs { -CS_Sink CreateMjpegServer(wpi::StringRef name, wpi::StringRef listenAddress, - int port, CS_Status* status) { - wpi::SmallString<128> str{listenAddress}; +CS_Sink CreateMjpegServer(const wpi::Twine& name, + const wpi::Twine& listenAddress, int port, + CS_Status* status) { + wpi::SmallString<128> listenAddressBuf; auto sink = std::make_shared( name, listenAddress, port, - std::unique_ptr( - new wpi::TCPAcceptor(port, str.c_str(), Logger::GetInstance()))); + std::unique_ptr(new wpi::TCPAcceptor( + port, + listenAddress.toNullTerminatedStringRef(listenAddressBuf).data(), + Logger::GetInstance()))); auto handle = Sinks::GetInstance().Allocate(CS_SINK_MJPEG, sink); Notifier::GetInstance().NotifySink(name, handle, CS_SINK_CREATED); return handle; diff --git a/cscore/src/main/native/cpp/MjpegServerImpl.h b/cscore/src/main/native/cpp/MjpegServerImpl.h index 16b7a71e81..cc16d78cf1 100644 --- a/cscore/src/main/native/cpp/MjpegServerImpl.h +++ b/cscore/src/main/native/cpp/MjpegServerImpl.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -31,8 +31,8 @@ class SourceImpl; class MjpegServerImpl : public SinkImpl { public: - MjpegServerImpl(wpi::StringRef name, wpi::StringRef listenAddress, int port, - std::unique_ptr acceptor); + MjpegServerImpl(const wpi::Twine& name, const wpi::Twine& listenAddress, + int port, std::unique_ptr acceptor); ~MjpegServerImpl() override; void Stop(); diff --git a/cscore/src/main/native/cpp/Notifier.cpp b/cscore/src/main/native/cpp/Notifier.cpp index 830537717e..9fcaea1e5d 100644 --- a/cscore/src/main/native/cpp/Notifier.cpp +++ b/cscore/src/main/native/cpp/Notifier.cpp @@ -151,7 +151,7 @@ void Notifier::RemoveListener(int uid) { thr->m_listeners.erase(uid); } -void Notifier::NotifySource(wpi::StringRef name, CS_Source source, +void Notifier::NotifySource(const wpi::Twine& name, CS_Source source, CS_EventKind kind) { auto thr = m_owner.GetThread(); if (!thr) return; @@ -176,9 +176,9 @@ void Notifier::NotifySourceVideoMode(const SourceImpl& source, } void Notifier::NotifySourceProperty(const SourceImpl& source, CS_EventKind kind, - wpi::StringRef propertyName, int property, - CS_PropertyKind propertyKind, int value, - wpi::StringRef valueStr) { + const wpi::Twine& propertyName, + int property, CS_PropertyKind propertyKind, + int value, const wpi::Twine& valueStr) { auto thr = m_owner.GetThread(); if (!thr) return; @@ -191,7 +191,7 @@ void Notifier::NotifySourceProperty(const SourceImpl& source, CS_EventKind kind, thr->m_cond.notify_one(); } -void Notifier::NotifySink(wpi::StringRef name, CS_Sink sink, +void Notifier::NotifySink(const wpi::Twine& name, CS_Sink sink, CS_EventKind kind) { auto thr = m_owner.GetThread(); if (!thr) return; @@ -205,7 +205,7 @@ void Notifier::NotifySink(const SinkImpl& sink, CS_EventKind kind) { NotifySink(sink.GetName(), handleData.first, kind); } -void Notifier::NotifySinkSourceChanged(wpi::StringRef name, CS_Sink sink, +void Notifier::NotifySinkSourceChanged(const wpi::Twine& name, CS_Sink sink, CS_Source source) { auto thr = m_owner.GetThread(); if (!thr) return; @@ -218,9 +218,9 @@ void Notifier::NotifySinkSourceChanged(wpi::StringRef name, CS_Sink sink, } void Notifier::NotifySinkProperty(const SinkImpl& sink, CS_EventKind kind, - wpi::StringRef propertyName, int property, + const wpi::Twine& propertyName, int property, CS_PropertyKind propertyKind, int value, - wpi::StringRef valueStr) { + const wpi::Twine& valueStr) { auto thr = m_owner.GetThread(); if (!thr) return; diff --git a/cscore/src/main/native/cpp/Notifier.h b/cscore/src/main/native/cpp/Notifier.h index 2de7754a90..6c3c48e0f0 100644 --- a/cscore/src/main/native/cpp/Notifier.h +++ b/cscore/src/main/native/cpp/Notifier.h @@ -42,21 +42,22 @@ class Notifier { void RemoveListener(int uid); // Notification events - void NotifySource(wpi::StringRef name, CS_Source source, CS_EventKind kind); + void NotifySource(const wpi::Twine& name, CS_Source source, + CS_EventKind kind); void NotifySource(const SourceImpl& source, CS_EventKind kind); void NotifySourceVideoMode(const SourceImpl& source, const VideoMode& mode); void NotifySourceProperty(const SourceImpl& source, CS_EventKind kind, - wpi::StringRef propertyName, int property, + const wpi::Twine& propertyName, int property, CS_PropertyKind propertyKind, int value, - wpi::StringRef valueStr); - void NotifySink(wpi::StringRef name, CS_Sink sink, CS_EventKind kind); + const wpi::Twine& valueStr); + void NotifySink(const wpi::Twine& name, CS_Sink sink, CS_EventKind kind); void NotifySink(const SinkImpl& sink, CS_EventKind kind); - void NotifySinkSourceChanged(wpi::StringRef name, CS_Sink sink, + void NotifySinkSourceChanged(const wpi::Twine& name, CS_Sink sink, CS_Source source); void NotifySinkProperty(const SinkImpl& sink, CS_EventKind kind, - wpi::StringRef propertyName, int property, + const wpi::Twine& propertyName, int property, CS_PropertyKind propertyKind, int value, - wpi::StringRef valueStr); + const wpi::Twine& valueStr); void NotifyNetworkInterfacesChanged(); void NotifyTelemetryUpdated(); diff --git a/cscore/src/main/native/cpp/PropertyContainer.cpp b/cscore/src/main/native/cpp/PropertyContainer.cpp index 177b3f5579..d7fae628ab 100644 --- a/cscore/src/main/native/cpp/PropertyContainer.cpp +++ b/cscore/src/main/native/cpp/PropertyContainer.cpp @@ -9,12 +9,13 @@ using namespace cs; -int PropertyContainer::GetPropertyIndex(wpi::StringRef name) const { +int PropertyContainer::GetPropertyIndex(const wpi::Twine& name) const { // We can't fail, so instead we create a new index if caching fails. CS_Status status = 0; if (!m_properties_cached) CacheProperties(&status); std::lock_guard lock(m_mutex); - int& ndx = m_properties[name]; + wpi::SmallVector nameBuf; + int& ndx = m_properties[name.toStringRef(nameBuf)]; if (ndx == 0) { // create a new index ndx = m_propertyData.size() + 1; @@ -90,7 +91,7 @@ void PropertyContainer::SetProperty(int property, int value, return; } - UpdatePropertyValue(property, false, value, wpi::StringRef{}); + UpdatePropertyValue(property, false, value, wpi::Twine{}); } int PropertyContainer::GetPropertyMin(int property, CS_Status* status) const { @@ -156,7 +157,7 @@ wpi::StringRef PropertyContainer::GetStringProperty( return wpi::StringRef(buf.data(), buf.size()); } -void PropertyContainer::SetStringProperty(int property, wpi::StringRef value, +void PropertyContainer::SetStringProperty(int property, const wpi::Twine& value, CS_Status* status) { std::lock_guard lock(m_mutex); auto prop = GetProperty(property); @@ -194,7 +195,7 @@ std::vector PropertyContainer::GetEnumPropertyChoices( } std::unique_ptr PropertyContainer::CreateEmptyProperty( - wpi::StringRef name) const { + const wpi::Twine& name) const { return wpi::make_unique(name); } diff --git a/cscore/src/main/native/cpp/PropertyContainer.h b/cscore/src/main/native/cpp/PropertyContainer.h index 210b27d3a7..4aeaf11152 100644 --- a/cscore/src/main/native/cpp/PropertyContainer.h +++ b/cscore/src/main/native/cpp/PropertyContainer.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "PropertyImpl.h" @@ -29,7 +30,7 @@ class PropertyContainer { public: virtual ~PropertyContainer() = default; - int GetPropertyIndex(wpi::StringRef name) const; + int GetPropertyIndex(const wpi::Twine& name) const; wpi::ArrayRef EnumerateProperties(wpi::SmallVectorImpl& vec, CS_Status* status) const; CS_PropertyKind GetPropertyKind(int property) const; @@ -44,7 +45,7 @@ class PropertyContainer { wpi::StringRef GetStringProperty(int property, wpi::SmallVectorImpl& buf, CS_Status* status) const; - virtual void SetStringProperty(int property, wpi::StringRef value, + virtual void SetStringProperty(int property, const wpi::Twine& value, CS_Status* status); std::vector GetEnumPropertyChoices(int property, CS_Status* status) const; @@ -65,9 +66,10 @@ class PropertyContainer { // @tparam NewFunc functor that returns a std::unique_ptr // @tparam UpdateFunc functor that takes a PropertyImpl&. template - int CreateOrUpdateProperty(wpi::StringRef name, NewFunc newFunc, + int CreateOrUpdateProperty(const wpi::Twine& name, NewFunc newFunc, UpdateFunc updateFunc) { - int& ndx = m_properties[name]; + wpi::SmallVector nameBuf; + int& ndx = m_properties[name.toStringRef(nameBuf)]; if (ndx == 0) { // create a new index ndx = m_propertyData.size() + 1; @@ -79,7 +81,7 @@ class PropertyContainer { return ndx; } template - int CreateProperty(wpi::StringRef name, NewFunc newFunc) { + int CreateProperty(const wpi::Twine& name, NewFunc newFunc) { return CreateOrUpdateProperty(name, newFunc, [](PropertyImpl&) {}); } @@ -88,7 +90,7 @@ class PropertyContainer { // Note: called with m_mutex held. // The default implementation simply creates a PropertyImpl object. virtual std::unique_ptr CreateEmptyProperty( - wpi::StringRef name) const; + const wpi::Twine& name) const; // Cache properties. Implementations must return false and set status to // CS_SOURCE_IS_DISCONNECTED if not possible to cache. @@ -99,7 +101,7 @@ class PropertyContainer { // Update property value; must be called with m_mutex held. virtual void UpdatePropertyValue(int property, bool setString, int value, - wpi::StringRef valueStr) = 0; + const wpi::Twine& valueStr) = 0; // Whether CacheProperties() has been successful at least once (and thus // should not be called again) diff --git a/cscore/src/main/native/cpp/PropertyImpl.cpp b/cscore/src/main/native/cpp/PropertyImpl.cpp index 40c094080b..4f1602e76c 100644 --- a/cscore/src/main/native/cpp/PropertyImpl.cpp +++ b/cscore/src/main/native/cpp/PropertyImpl.cpp @@ -9,18 +9,18 @@ using namespace cs; -PropertyImpl::PropertyImpl(wpi::StringRef name_) : name{name_} {} -PropertyImpl::PropertyImpl(wpi::StringRef name_, CS_PropertyKind kind_, +PropertyImpl::PropertyImpl(const wpi::Twine& name_) : name{name_.str()} {} +PropertyImpl::PropertyImpl(const wpi::Twine& name_, CS_PropertyKind kind_, int step_, int defaultValue_, int value_) - : name{name_}, + : name{name_.str()}, propKind{kind_}, step{step_}, defaultValue{defaultValue_}, value{value_} {} -PropertyImpl::PropertyImpl(wpi::StringRef name_, CS_PropertyKind kind_, +PropertyImpl::PropertyImpl(const wpi::Twine& name_, CS_PropertyKind kind_, int minimum_, int maximum_, int step_, int defaultValue_, int value_) - : name{name_}, + : name{name_.str()}, propKind{kind_}, hasMinimum{true}, hasMaximum{true}, @@ -43,10 +43,11 @@ void PropertyImpl::SetValue(int v) { if (!wasValueSet || value != oldValue) changed(); } -void PropertyImpl::SetValue(wpi::StringRef v) { +void PropertyImpl::SetValue(const wpi::Twine& v) { bool valueChanged = false; - if (valueStr != v) { - valueStr = v; + std::string vStr = v.str(); + if (valueStr != vStr) { + valueStr = vStr; valueChanged = true; } bool wasValueSet = valueSet; diff --git a/cscore/src/main/native/cpp/PropertyImpl.h b/cscore/src/main/native/cpp/PropertyImpl.h index daad8292f5..d93213216c 100644 --- a/cscore/src/main/native/cpp/PropertyImpl.h +++ b/cscore/src/main/native/cpp/PropertyImpl.h @@ -13,6 +13,7 @@ #include #include +#include #include "cscore_c.h" @@ -22,17 +23,17 @@ namespace cs { class PropertyImpl { public: PropertyImpl() = default; - explicit PropertyImpl(wpi::StringRef name_); - PropertyImpl(wpi::StringRef name_, CS_PropertyKind kind_, int step_, + explicit PropertyImpl(const wpi::Twine& name_); + PropertyImpl(const wpi::Twine& name_, CS_PropertyKind kind_, int step_, int defaultValue_, int value_); - PropertyImpl(wpi::StringRef name_, CS_PropertyKind kind_, int minimum_, + PropertyImpl(const wpi::Twine& name_, CS_PropertyKind kind_, int minimum_, int maximum_, int step_, int defaultValue_, int value_); virtual ~PropertyImpl() = default; PropertyImpl(const PropertyImpl& oth) = delete; PropertyImpl& operator=(const PropertyImpl& oth) = delete; void SetValue(int v); - void SetValue(wpi::StringRef v); + void SetValue(const wpi::Twine& v); void SetDefaultValue(int v); std::string name; diff --git a/cscore/src/main/native/cpp/SinkImpl.cpp b/cscore/src/main/native/cpp/SinkImpl.cpp index cdf4f9177b..5e00dc0df2 100644 --- a/cscore/src/main/native/cpp/SinkImpl.cpp +++ b/cscore/src/main/native/cpp/SinkImpl.cpp @@ -12,7 +12,7 @@ using namespace cs; -SinkImpl::SinkImpl(wpi::StringRef name) : m_name{name} {} +SinkImpl::SinkImpl(const wpi::Twine& name) : m_name{name.str()} {} SinkImpl::~SinkImpl() { if (m_source) { @@ -21,9 +21,9 @@ SinkImpl::~SinkImpl() { } } -void SinkImpl::SetDescription(wpi::StringRef description) { +void SinkImpl::SetDescription(const wpi::Twine& description) { std::lock_guard lock(m_mutex); - m_description = description; + m_description = description.str(); } wpi::StringRef SinkImpl::GetDescription(wpi::SmallVectorImpl& buf) const { @@ -105,11 +105,11 @@ void SinkImpl::NotifyPropertyCreated(int propIndex, PropertyImpl& prop) { if (prop.propKind == CS_PROP_ENUM) notifier.NotifySinkProperty(*this, CS_SINK_PROPERTY_CHOICES_UPDATED, prop.name, propIndex, prop.propKind, prop.value, - wpi::StringRef{}); + wpi::Twine{}); } void SinkImpl::UpdatePropertyValue(int property, bool setString, int value, - wpi::StringRef valueStr) { + const wpi::Twine& valueStr) { auto prop = GetProperty(property); if (!prop) return; diff --git a/cscore/src/main/native/cpp/SinkImpl.h b/cscore/src/main/native/cpp/SinkImpl.h index 1080403e7f..dd4cab7d64 100644 --- a/cscore/src/main/native/cpp/SinkImpl.h +++ b/cscore/src/main/native/cpp/SinkImpl.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "SourceImpl.h" @@ -22,14 +23,14 @@ class Frame; class SinkImpl : public PropertyContainer { public: - explicit SinkImpl(wpi::StringRef name); + explicit SinkImpl(const wpi::Twine& name); virtual ~SinkImpl(); SinkImpl(const SinkImpl& queue) = delete; SinkImpl& operator=(const SinkImpl& queue) = delete; wpi::StringRef GetName() const { return m_name; } - void SetDescription(wpi::StringRef description); + void SetDescription(const wpi::Twine& description); wpi::StringRef GetDescription(wpi::SmallVectorImpl& buf) const; void Enable(); @@ -50,7 +51,7 @@ class SinkImpl : public PropertyContainer { // PropertyContainer implementation void NotifyPropertyCreated(int propIndex, PropertyImpl& prop) override; void UpdatePropertyValue(int property, bool setString, int value, - wpi::StringRef valueStr) override; + const wpi::Twine& valueStr) override; virtual void SetSourceImpl(std::shared_ptr source); diff --git a/cscore/src/main/native/cpp/SourceImpl.cpp b/cscore/src/main/native/cpp/SourceImpl.cpp index 2e775d7f11..4333e9147f 100644 --- a/cscore/src/main/native/cpp/SourceImpl.cpp +++ b/cscore/src/main/native/cpp/SourceImpl.cpp @@ -21,7 +21,7 @@ using namespace cs; static constexpr size_t kMaxImagesAvail = 32; -SourceImpl::SourceImpl(wpi::StringRef name) : m_name{name} { +SourceImpl::SourceImpl(const wpi::Twine& name) : m_name{name.str()} { m_frame = Frame{*this, wpi::StringRef{}, 0}; } @@ -38,9 +38,9 @@ SourceImpl::~SourceImpl() { // Everything else can clean up itself. } -void SourceImpl::SetDescription(wpi::StringRef description) { +void SourceImpl::SetDescription(const wpi::Twine& description) { std::lock_guard lock(m_mutex); - m_description = description; + m_description = description.str(); } wpi::StringRef SourceImpl::GetDescription( @@ -229,7 +229,7 @@ void SourceImpl::PutFrame(std::unique_ptr image, Frame::Time time) { m_frameCv.notify_all(); } -void SourceImpl::PutError(wpi::StringRef msg, Frame::Time time) { +void SourceImpl::PutError(const wpi::Twine& msg, Frame::Time time) { // Update frame { std::lock_guard lock{m_frameMutex}; @@ -249,11 +249,11 @@ void SourceImpl::NotifyPropertyCreated(int propIndex, PropertyImpl& prop) { if (prop.propKind == CS_PROP_ENUM) notifier.NotifySourceProperty(*this, CS_SOURCE_PROPERTY_CHOICES_UPDATED, prop.name, propIndex, prop.propKind, - prop.value, wpi::StringRef{}); + prop.value, wpi::Twine{}); } void SourceImpl::UpdatePropertyValue(int property, bool setString, int value, - wpi::StringRef valueStr) { + const wpi::Twine& valueStr) { auto prop = GetProperty(property); if (!prop) return; diff --git a/cscore/src/main/native/cpp/SourceImpl.h b/cscore/src/main/native/cpp/SourceImpl.h index 5ef50e533e..a6b50101ac 100644 --- a/cscore/src/main/native/cpp/SourceImpl.h +++ b/cscore/src/main/native/cpp/SourceImpl.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -30,14 +31,14 @@ class SourceImpl : public PropertyContainer { friend class Frame; public: - explicit SourceImpl(wpi::StringRef name); + explicit SourceImpl(const wpi::Twine& name); virtual ~SourceImpl(); SourceImpl(const SourceImpl& oth) = delete; SourceImpl& operator=(const SourceImpl& oth) = delete; wpi::StringRef GetName() const { return m_name; } - void SetDescription(wpi::StringRef description); + void SetDescription(const wpi::Twine& description); wpi::StringRef GetDescription(wpi::SmallVectorImpl& buf) const; void SetConnected(bool connected); @@ -117,12 +118,12 @@ class SourceImpl : public PropertyContainer { protected: void NotifyPropertyCreated(int propIndex, PropertyImpl& prop) override; void UpdatePropertyValue(int property, bool setString, int value, - wpi::StringRef valueStr) override; + const wpi::Twine& valueStr) override; void PutFrame(VideoMode::PixelFormat pixelFormat, int width, int height, wpi::StringRef data, Frame::Time time); void PutFrame(std::unique_ptr image, Frame::Time time); - void PutError(wpi::StringRef msg, Frame::Time time); + void PutError(const wpi::Twine& msg, Frame::Time time); // Notification functions for corresponding atomics virtual void NumSinksChanged() = 0; diff --git a/cscore/src/main/native/cpp/UsbCameraImpl.cpp b/cscore/src/main/native/cpp/UsbCameraImpl.cpp index 95b7893f09..c48b421b65 100644 --- a/cscore/src/main/native/cpp/UsbCameraImpl.cpp +++ b/cscore/src/main/native/cpp/UsbCameraImpl.cpp @@ -215,9 +215,9 @@ static std::string GetDescriptionImpl(const char* cpath) { return std::string{}; } -UsbCameraImpl::UsbCameraImpl(wpi::StringRef name, wpi::StringRef path) +UsbCameraImpl::UsbCameraImpl(const wpi::Twine& name, const wpi::Twine& path) : SourceImpl{name}, - m_path{path}, + m_path{path.str()}, m_fd{-1}, m_command_fd{eventfd(0, 0)}, m_active{true} { @@ -1130,7 +1130,7 @@ void UsbCameraImpl::Send(Message&& msg) const { } std::unique_ptr UsbCameraImpl::CreateEmptyProperty( - wpi::StringRef name) const { + const wpi::Twine& name) const { return wpi::make_unique(name); } @@ -1159,11 +1159,11 @@ void UsbCameraImpl::SetProperty(int property, int value, CS_Status* status) { *status = SendAndWait(std::move(msg)); } -void UsbCameraImpl::SetStringProperty(int property, wpi::StringRef value, +void UsbCameraImpl::SetStringProperty(int property, const wpi::Twine& value, CS_Status* status) { Message msg{Message::kCmdSetPropertyStr}; msg.data[0] = property; - msg.dataStr = value; + msg.dataStr = value.str(); *status = SendAndWait(std::move(msg)); } @@ -1255,14 +1255,15 @@ void UsbCameraImpl::NumSinksEnabledChanged() { namespace cs { -CS_Source CreateUsbCameraDev(wpi::StringRef name, int dev, CS_Status* status) { +CS_Source CreateUsbCameraDev(const wpi::Twine& name, int dev, + CS_Status* status) { wpi::SmallString<32> path; wpi::raw_svector_ostream oss{path}; oss << "/dev/video" << dev; return CreateUsbCameraPath(name, oss.str(), status); } -CS_Source CreateUsbCameraPath(wpi::StringRef name, wpi::StringRef path, +CS_Source CreateUsbCameraPath(const wpi::Twine& name, const wpi::Twine& path, CS_Status* status) { auto source = std::make_shared(name, path); auto handle = Sources::GetInstance().Allocate(CS_SOURCE_USB, source); diff --git a/cscore/src/main/native/cpp/UsbCameraImpl.h b/cscore/src/main/native/cpp/UsbCameraImpl.h index d4b83595ed..6037033743 100644 --- a/cscore/src/main/native/cpp/UsbCameraImpl.h +++ b/cscore/src/main/native/cpp/UsbCameraImpl.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -34,14 +35,14 @@ namespace cs { class UsbCameraImpl : public SourceImpl { public: - UsbCameraImpl(wpi::StringRef name, wpi::StringRef path); + UsbCameraImpl(const wpi::Twine& name, const wpi::Twine& path); ~UsbCameraImpl() override; void Start(); // Property functions void SetProperty(int property, int value, CS_Status* status) override; - void SetStringProperty(int property, wpi::StringRef value, + void SetStringProperty(int property, const wpi::Twine& value, CS_Status* status) override; // Standard common camera properties @@ -93,7 +94,7 @@ class UsbCameraImpl : public SourceImpl { protected: std::unique_ptr CreateEmptyProperty( - wpi::StringRef name) const override; + const wpi::Twine& name) const override; // Cache properties. Immediately successful if properties are already cached. // If they are not, tries to connect to the camera to do so; returns false and diff --git a/cscore/src/main/native/cpp/UsbCameraProperty.cpp b/cscore/src/main/native/cpp/UsbCameraProperty.cpp index dc5bb460e1..c58280beb5 100644 --- a/cscore/src/main/native/cpp/UsbCameraProperty.cpp +++ b/cscore/src/main/native/cpp/UsbCameraProperty.cpp @@ -92,9 +92,15 @@ static int GetStringCtrlIoctl(int fd, int id, int maximum, std::string* value) { } static int SetStringCtrlIoctl(int fd, int id, int maximum, - wpi::StringRef value) { - wpi::SmallString<64> str{ - value.substr(0, std::min(value.size(), static_cast(maximum)))}; + const wpi::Twine& value) { + wpi::SmallString<64> strBuf, strBuf2; + wpi::StringRef str = value.toNullTerminatedStringRef(strBuf); + if (str.size() > static_cast(maximum)) { + // don't know if strBuf was used, just recopy + strBuf2 = str.take_front(maximum); + str = strBuf2; + strBuf2.push_back('\0'); // null terminate + } struct v4l2_ext_control ctrl; struct v4l2_ext_controls ctrls; @@ -102,7 +108,7 @@ static int SetStringCtrlIoctl(int fd, int id, int maximum, std::memset(&ctrls, 0, sizeof(ctrls)); ctrl.id = id; ctrl.size = str.size(); - ctrl.string = const_cast(str.c_str()); + ctrl.string = const_cast(str.data()); ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(id); ctrls.count = 1; ctrls.controls = &ctrl; @@ -288,7 +294,7 @@ bool UsbCameraProperty::DeviceSet(std::unique_lock& lock, bool UsbCameraProperty::DeviceSet(std::unique_lock& lock, int fd, int newValue, - wpi::StringRef newValueStr) const { + const wpi::Twine& newValueStr) const { if (!device || fd < 0) return true; unsigned idCopy = id; int rv = 0; diff --git a/cscore/src/main/native/cpp/UsbCameraProperty.h b/cscore/src/main/native/cpp/UsbCameraProperty.h index b977ef2bc6..fd804f56b7 100644 --- a/cscore/src/main/native/cpp/UsbCameraProperty.h +++ b/cscore/src/main/native/cpp/UsbCameraProperty.h @@ -24,19 +24,19 @@ namespace cs { class UsbCameraProperty : public PropertyImpl { public: UsbCameraProperty() = default; - explicit UsbCameraProperty(wpi::StringRef name_) : PropertyImpl{name_} {} + explicit UsbCameraProperty(const wpi::Twine& name_) : PropertyImpl{name_} {} // Software property constructor - UsbCameraProperty(wpi::StringRef name_, unsigned id_, CS_PropertyKind kind_, - int minimum_, int maximum_, int step_, int defaultValue_, - int value_) + UsbCameraProperty(const wpi::Twine& name_, unsigned id_, + CS_PropertyKind kind_, int minimum_, int maximum_, + int step_, int defaultValue_, int value_) : PropertyImpl(name_, kind_, minimum_, maximum_, step_, defaultValue_, value_), device{false}, id{id_} {} // Normalized property constructor - UsbCameraProperty(wpi::StringRef name_, int rawIndex_, + UsbCameraProperty(const wpi::Twine& name_, int rawIndex_, const UsbCameraProperty& rawProp, int defaultValue_, int value_) : PropertyImpl(name_, rawProp.propKind, 1, defaultValue_, value_), @@ -61,7 +61,7 @@ class UsbCameraProperty : public PropertyImpl { bool DeviceGet(std::unique_lock& lock, int fd); bool DeviceSet(std::unique_lock& lock, int fd) const; bool DeviceSet(std::unique_lock& lock, int fd, int newValue, - wpi::StringRef newValueStr) const; + const wpi::Twine& newValueStr) const; #endif // If this is a device (rather than software) property diff --git a/cscore/src/main/native/cpp/cscore_cpp.cpp b/cscore/src/main/native/cpp/cscore_cpp.cpp index e35d213052..52f9264b18 100644 --- a/cscore/src/main/native/cpp/cscore_cpp.cpp +++ b/cscore/src/main/native/cpp/cscore_cpp.cpp @@ -144,7 +144,7 @@ wpi::StringRef GetStringProperty(CS_Property property, return container->GetStringProperty(propertyIndex, buf, status); } -void SetStringProperty(CS_Property property, wpi::StringRef value, +void SetStringProperty(CS_Property property, const wpi::Twine& value, CS_Status* status) { int propertyIndex; auto container = GetPropertyContainer(property, &propertyIndex, status); @@ -231,7 +231,7 @@ bool IsSourceConnected(CS_Source source, CS_Status* status) { return data->source->IsConnected(); } -CS_Property GetSourceProperty(CS_Source source, wpi::StringRef name, +CS_Property GetSourceProperty(CS_Source source, const wpi::Twine& name, CS_Status* status) { auto data = Sources::GetInstance().Get(source); if (!data) { @@ -489,7 +489,7 @@ wpi::StringRef GetSinkDescription(CS_Sink sink, wpi::SmallVectorImpl& buf, return data->sink->GetDescription(buf); } -CS_Property GetSinkProperty(CS_Sink sink, wpi::StringRef name, +CS_Property GetSinkProperty(CS_Sink sink, const wpi::Twine& name, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); if (!data) { @@ -547,7 +547,7 @@ CS_Source GetSinkSource(CS_Sink sink, CS_Status* status) { return data->sourceHandle.load(); } -CS_Property GetSinkSourceProperty(CS_Sink sink, wpi::StringRef name, +CS_Property GetSinkSourceProperty(CS_Sink sink, const wpi::Twine& name, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); if (!data) { diff --git a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp index 1ed75d3b1e..49e091998c 100644 --- a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp +++ b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp @@ -378,7 +378,7 @@ Java_edu_wpi_cscore_CameraServerJNI_setStringProperty return; } CS_Status status = 0; - cs::SetStringProperty(property, JStringRef{env, value}, &status); + cs::SetStringProperty(property, JStringRef{env, value}.str(), &status); CheckStatus(env, status); } @@ -415,7 +415,7 @@ Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraDev return 0; } CS_Status status = 0; - auto val = cs::CreateUsbCameraDev(JStringRef{env, name}, dev, &status); + auto val = cs::CreateUsbCameraDev(JStringRef{env, name}.str(), dev, &status); CheckStatus(env, status); return val; #endif @@ -443,8 +443,8 @@ Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraPath return 0; } CS_Status status = 0; - auto val = cs::CreateUsbCameraPath(JStringRef{env, name}, - JStringRef{env, path}, &status); + auto val = cs::CreateUsbCameraPath(JStringRef{env, name}.str(), + JStringRef{env, path}.str(), &status); CheckStatus(env, status); return val; #endif @@ -468,9 +468,9 @@ Java_edu_wpi_cscore_CameraServerJNI_createHttpCamera return 0; } CS_Status status = 0; - auto val = - cs::CreateHttpCamera(JStringRef{env, name}, JStringRef{env, url}, - static_cast(kind), &status); + auto val = cs::CreateHttpCamera( + JStringRef{env, name}.str(), JStringRef{env, url}.str(), + static_cast(kind), &status); CheckStatus(env, status); return val; } @@ -506,7 +506,7 @@ Java_edu_wpi_cscore_CameraServerJNI_createHttpCameraMulti } CS_Status status = 0; auto val = - cs::CreateHttpCamera(JStringRef{env, name}, vec, + cs::CreateHttpCamera(JStringRef{env, name}.str(), vec, static_cast(kind), &status); CheckStatus(env, status); return val; @@ -528,7 +528,7 @@ Java_edu_wpi_cscore_CameraServerJNI_createCvSource } CS_Status status = 0; auto val = cs::CreateCvSource( - JStringRef{env, name}, + JStringRef{env, name}.str(), cs::VideoMode{static_cast(pixelFormat), static_cast(width), static_cast(height), static_cast(fps)}, @@ -628,7 +628,8 @@ Java_edu_wpi_cscore_CameraServerJNI_getSourceProperty return 0; } CS_Status status = 0; - auto val = cs::GetSourceProperty(source, JStringRef{env, name}, &status); + auto val = + cs::GetSourceProperty(source, JStringRef{env, name}.str(), &status); CheckStatus(env, status); return val; } @@ -1018,7 +1019,7 @@ Java_edu_wpi_cscore_CameraServerJNI_notifySourceError return; } CS_Status status = 0; - cs::NotifySourceError(source, JStringRef{env, msg}, &status); + cs::NotifySourceError(source, JStringRef{env, msg}.str(), &status); CheckStatus(env, status); } @@ -1050,7 +1051,7 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceDescription return; } CS_Status status = 0; - cs::SetSourceDescription(source, JStringRef{env, description}, &status); + cs::SetSourceDescription(source, JStringRef{env, description}.str(), &status); CheckStatus(env, status); } @@ -1066,7 +1067,7 @@ Java_edu_wpi_cscore_CameraServerJNI_createSourceProperty { CS_Status status = 0; auto val = cs::CreateSourceProperty( - source, JStringRef{env, name}, static_cast(kind), + source, JStringRef{env, name}.str(), static_cast(kind), minimum, maximum, step, defaultValue, value, &status); CheckStatus(env, status); return val; @@ -1120,8 +1121,9 @@ Java_edu_wpi_cscore_CameraServerJNI_createMjpegServer return 0; } CS_Status status = 0; - auto val = cs::CreateMjpegServer( - JStringRef{env, name}, JStringRef{env, listenAddress}, port, &status); + auto val = cs::CreateMjpegServer(JStringRef{env, name}.str(), + JStringRef{env, listenAddress}.str(), port, + &status); CheckStatus(env, status); return val; } @@ -1140,7 +1142,7 @@ Java_edu_wpi_cscore_CameraServerJNI_createCvSink return 0; } CS_Status status = 0; - auto val = cs::CreateCvSink(JStringRef{env, name}, &status); + auto val = cs::CreateCvSink(JStringRef{env, name}.str(), &status); CheckStatus(env, status); return val; } @@ -1206,7 +1208,7 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkProperty return 0; } CS_Status status = 0; - auto val = cs::GetSinkProperty(sink, JStringRef{env, name}, &status); + auto val = cs::GetSinkProperty(sink, JStringRef{env, name}.str(), &status); CheckStatus(env, status); return val; } @@ -1255,7 +1257,8 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkSourceProperty return 0; } CS_Status status = 0; - auto val = cs::GetSinkSourceProperty(sink, JStringRef{env, name}, &status); + auto val = + cs::GetSinkSourceProperty(sink, JStringRef{env, name}.str(), &status); CheckStatus(env, status); return val; } @@ -1348,7 +1351,7 @@ Java_edu_wpi_cscore_CameraServerJNI_setSinkDescription return; } CS_Status status = 0; - cs::SetSinkDescription(sink, JStringRef{env, description}, &status); + cs::SetSinkDescription(sink, JStringRef{env, description}.str(), &status); CheckStatus(env, status); } diff --git a/cscore/src/main/native/include/cscore_cpp.h b/cscore/src/main/native/include/cscore_cpp.h index 924817f969..894a4106c6 100644 --- a/cscore/src/main/native/include/cscore_cpp.h +++ b/cscore/src/main/native/include/cscore_cpp.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "cscore_c.h" @@ -104,29 +105,29 @@ struct RawEvent { RawEvent() = default; explicit RawEvent(RawEvent::Kind kind_) : kind{kind_} {} - RawEvent(wpi::StringRef name_, CS_Handle handle_, RawEvent::Kind kind_) - : kind{kind_}, name{name_} { + RawEvent(const wpi::Twine& name_, CS_Handle handle_, RawEvent::Kind kind_) + : kind{kind_}, name{name_.str()} { if (kind_ == kSinkCreated || kind_ == kSinkDestroyed || kind_ == kSinkEnabled || kind_ == kSinkDisabled) sinkHandle = handle_; else sourceHandle = handle_; } - RawEvent(wpi::StringRef name_, CS_Source source_, const VideoMode& mode_) + RawEvent(const wpi::Twine& name_, CS_Source source_, const VideoMode& mode_) : kind{kSourceVideoModeChanged}, sourceHandle{source_}, - name{name_}, + name{name_.str()}, mode{mode_} {} - RawEvent(wpi::StringRef name_, CS_Source source_, RawEvent::Kind kind_, + RawEvent(const wpi::Twine& name_, CS_Source source_, RawEvent::Kind kind_, CS_Property property_, CS_PropertyKind propertyKind_, int value_, - wpi::StringRef valueStr_) + const wpi::Twine& valueStr_) : kind{kind_}, sourceHandle{source_}, - name{name_}, + name{name_.str()}, propertyHandle{property_}, propertyKind{propertyKind_}, value{value_}, - valueStr{valueStr_} {} + valueStr{valueStr_.str()} {} Kind kind; @@ -166,7 +167,7 @@ std::string GetStringProperty(CS_Property property, CS_Status* status); wpi::StringRef GetStringProperty(CS_Property property, wpi::SmallVectorImpl& buf, CS_Status* status); -void SetStringProperty(CS_Property property, wpi::StringRef value, +void SetStringProperty(CS_Property property, const wpi::Twine& value, CS_Status* status); std::vector GetEnumPropertyChoices(CS_Property property, CS_Status* status); @@ -176,14 +177,16 @@ std::vector GetEnumPropertyChoices(CS_Property property, * @defgroup cscore_source_create_func Source Creation Functions * @{ */ -CS_Source CreateUsbCameraDev(wpi::StringRef name, int dev, CS_Status* status); -CS_Source CreateUsbCameraPath(wpi::StringRef name, wpi::StringRef path, +CS_Source CreateUsbCameraDev(const wpi::Twine& name, int dev, + CS_Status* status); +CS_Source CreateUsbCameraPath(const wpi::Twine& name, const wpi::Twine& path, CS_Status* status); -CS_Source CreateHttpCamera(wpi::StringRef name, wpi::StringRef url, +CS_Source CreateHttpCamera(const wpi::Twine& name, const wpi::Twine& url, CS_HttpCameraKind kind, CS_Status* status); -CS_Source CreateHttpCamera(wpi::StringRef name, wpi::ArrayRef urls, +CS_Source CreateHttpCamera(const wpi::Twine& name, + wpi::ArrayRef urls, CS_HttpCameraKind kind, CS_Status* status); -CS_Source CreateCvSource(wpi::StringRef name, const VideoMode& mode, +CS_Source CreateCvSource(const wpi::Twine& name, const VideoMode& mode, CS_Status* status); /** @} */ @@ -201,7 +204,7 @@ wpi::StringRef GetSourceDescription(CS_Source source, CS_Status* status); uint64_t GetSourceLastFrameTime(CS_Source source, CS_Status* status); bool IsSourceConnected(CS_Source source, CS_Status* status); -CS_Property GetSourceProperty(CS_Source source, wpi::StringRef name, +CS_Property GetSourceProperty(CS_Source source, const wpi::Twine& name, CS_Status* status); wpi::ArrayRef EnumerateSourceProperties( CS_Source source, wpi::SmallVectorImpl& vec, @@ -260,11 +263,12 @@ std::vector GetHttpCameraUrls(CS_Source source, CS_Status* status); * @{ */ void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status); -void NotifySourceError(CS_Source source, wpi::StringRef msg, CS_Status* status); +void NotifySourceError(CS_Source source, const wpi::Twine& msg, + CS_Status* status); void SetSourceConnected(CS_Source source, bool connected, CS_Status* status); -void SetSourceDescription(CS_Source source, wpi::StringRef description, +void SetSourceDescription(CS_Source source, const wpi::Twine& description, CS_Status* status); -CS_Property CreateSourceProperty(CS_Source source, wpi::StringRef name, +CS_Property CreateSourceProperty(CS_Source source, const wpi::Twine& name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, CS_Status* status); @@ -277,10 +281,11 @@ void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, * @defgroup cscore_sink_create_func Sink Creation Functions * @{ */ -CS_Sink CreateMjpegServer(wpi::StringRef name, wpi::StringRef listenAddress, - int port, CS_Status* status); -CS_Sink CreateCvSink(wpi::StringRef name, CS_Status* status); -CS_Sink CreateCvSinkCallback(wpi::StringRef name, +CS_Sink CreateMjpegServer(const wpi::Twine& name, + const wpi::Twine& listenAddress, int port, + CS_Status* status); +CS_Sink CreateCvSink(const wpi::Twine& name, CS_Status* status); +CS_Sink CreateCvSinkCallback(const wpi::Twine& name, std::function processFrame, CS_Status* status); /** @} */ @@ -296,12 +301,12 @@ wpi::StringRef GetSinkName(CS_Sink sink, wpi::SmallVectorImpl& buf, std::string GetSinkDescription(CS_Sink sink, CS_Status* status); wpi::StringRef GetSinkDescription(CS_Sink sink, wpi::SmallVectorImpl& buf, CS_Status* status); -CS_Property GetSinkProperty(CS_Sink sink, wpi::StringRef name, +CS_Property GetSinkProperty(CS_Sink sink, const wpi::Twine& name, CS_Status* status); wpi::ArrayRef EnumerateSinkProperties( CS_Sink sink, wpi::SmallVectorImpl& vec, CS_Status* status); void SetSinkSource(CS_Sink sink, CS_Source source, CS_Status* status); -CS_Property GetSinkSourceProperty(CS_Sink sink, wpi::StringRef name, +CS_Property GetSinkSourceProperty(CS_Sink sink, const wpi::Twine& name, CS_Status* status); CS_Source GetSinkSource(CS_Sink sink, CS_Status* status); CS_Sink CopySink(CS_Sink sink, CS_Status* status); @@ -320,7 +325,7 @@ int GetMjpegServerPort(CS_Sink sink, CS_Status* status); * @defgroup cscore_opencv_sink_func OpenCV Sink Functions * @{ */ -void SetSinkDescription(CS_Sink sink, wpi::StringRef description, +void SetSinkDescription(CS_Sink sink, const wpi::Twine& description, CS_Status* status); uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat& image, CS_Status* status); uint64_t GrabSinkFrameTimeout(CS_Sink sink, cv::Mat& image, double timeout, diff --git a/cscore/src/main/native/include/cscore_oo.h b/cscore/src/main/native/include/cscore_oo.h index 937c356a4c..0eb20507fa 100644 --- a/cscore/src/main/native/include/cscore_oo.h +++ b/cscore/src/main/native/include/cscore_oo.h @@ -75,7 +75,7 @@ class VideoProperty { // String-specific functions std::string GetString() const; wpi::StringRef GetString(wpi::SmallVectorImpl& buf) const; - void SetString(wpi::StringRef value); + void SetString(const wpi::Twine& value); // Enum-specific functions std::vector GetChoices() const; @@ -157,7 +157,7 @@ class VideoSource { * @return Property contents (of kind Property::kNone if no property with * the given name exists) */ - VideoProperty GetProperty(wpi::StringRef name); + VideoProperty GetProperty(const wpi::Twine& name); /** * Enumerate all properties of this source. @@ -337,7 +337,7 @@ class UsbCamera : public VideoCamera { * @param name Source name (arbitrary unique identifier) * @param dev Device number (e.g. 0 for /dev/video0) */ - UsbCamera(wpi::StringRef name, int dev); + UsbCamera(const wpi::Twine& name, int dev); /** * Create a source for a USB camera based on device path. @@ -345,7 +345,7 @@ class UsbCamera : public VideoCamera { * @param name Source name (arbitrary unique identifier) * @param path Path to device (e.g. "/dev/video0" on Linux) */ - UsbCamera(wpi::StringRef name, wpi::StringRef path); + UsbCamera(const wpi::Twine& name, const wpi::Twine& path); /** * Enumerate USB cameras on the local system. @@ -386,7 +386,7 @@ class HttpCamera : public VideoCamera { * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg") * @param kind Camera kind (e.g. kAxis) */ - HttpCamera(wpi::StringRef name, wpi::StringRef url, + HttpCamera(const wpi::Twine& name, const wpi::Twine& url, HttpCameraKind kind = kUnknown); /** @@ -396,7 +396,7 @@ class HttpCamera : public VideoCamera { * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg") * @param kind Camera kind (e.g. kAxis) */ - HttpCamera(wpi::StringRef name, const char* url, + HttpCamera(const wpi::Twine& name, const char* url, HttpCameraKind kind = kUnknown); /** @@ -406,7 +406,7 @@ class HttpCamera : public VideoCamera { * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg") * @param kind Camera kind (e.g. kAxis) */ - HttpCamera(wpi::StringRef name, const std::string& url, + HttpCamera(const wpi::Twine& name, const std::string& url, HttpCameraKind kind = kUnknown); /** @@ -416,7 +416,7 @@ class HttpCamera : public VideoCamera { * @param urls Array of Camera URLs * @param kind Camera kind (e.g. kAxis) */ - HttpCamera(wpi::StringRef name, wpi::ArrayRef urls, + HttpCamera(const wpi::Twine& name, wpi::ArrayRef urls, HttpCameraKind kind = kUnknown); /** @@ -427,7 +427,7 @@ class HttpCamera : public VideoCamera { * @param kind Camera kind (e.g. kAxis) */ template - HttpCamera(wpi::StringRef name, std::initializer_list urls, + HttpCamera(const wpi::Twine& name, std::initializer_list urls, HttpCameraKind kind = kUnknown); /** @@ -459,7 +459,7 @@ class HttpCamera : public VideoCamera { * A source that represents an Axis IP camera. */ class AxisCamera : public HttpCamera { - static std::string HostToUrl(wpi::StringRef host); + static std::string HostToUrl(const wpi::Twine& host); static std::vector HostToUrl(wpi::ArrayRef hosts); template static std::vector HostToUrl(std::initializer_list hosts); @@ -472,7 +472,7 @@ class AxisCamera : public HttpCamera { * @param host Camera host IP or DNS name (e.g. "10.x.y.11") * @param kind Camera kind (e.g. kAxis) */ - AxisCamera(wpi::StringRef name, wpi::StringRef host); + AxisCamera(const wpi::Twine& name, const wpi::Twine& host); /** * Create a source for an Axis IP camera. @@ -481,7 +481,7 @@ class AxisCamera : public HttpCamera { * @param host Camera host IP or DNS name (e.g. "10.x.y.11") * @param kind Camera kind (e.g. kAxis) */ - AxisCamera(wpi::StringRef name, const char* host); + AxisCamera(const wpi::Twine& name, const char* host); /** * Create a source for an Axis IP camera. @@ -490,7 +490,7 @@ class AxisCamera : public HttpCamera { * @param host Camera host IP or DNS name (e.g. "10.x.y.11") * @param kind Camera kind (e.g. kAxis) */ - AxisCamera(wpi::StringRef name, const std::string& host); + AxisCamera(const wpi::Twine& name, const std::string& host); /** * Create a source for an Axis IP camera. @@ -499,7 +499,7 @@ class AxisCamera : public HttpCamera { * @param hosts Array of Camera host IPs/DNS names * @param kind Camera kind (e.g. kAxis) */ - AxisCamera(wpi::StringRef name, wpi::ArrayRef hosts); + AxisCamera(const wpi::Twine& name, wpi::ArrayRef hosts); /** * Create a source for an Axis IP camera. @@ -509,7 +509,7 @@ class AxisCamera : public HttpCamera { * @param kind Camera kind (e.g. kAxis) */ template - AxisCamera(wpi::StringRef name, std::initializer_list hosts); + AxisCamera(const wpi::Twine& name, std::initializer_list hosts); }; /** @@ -525,7 +525,7 @@ class CvSource : public VideoSource { * @param name Source name (arbitrary unique identifier) * @param mode Video mode being generated */ - CvSource(wpi::StringRef name, const VideoMode& mode); + CvSource(const wpi::Twine& name, const VideoMode& mode); /** * Create an OpenCV source. @@ -536,8 +536,8 @@ class CvSource : public VideoSource { * @param height height * @param fps fps */ - CvSource(wpi::StringRef name, VideoMode::PixelFormat pixelFormat, int width, - int height, int fps); + CvSource(const wpi::Twine& name, VideoMode::PixelFormat pixelFormat, + int width, int height, int fps); /** * Put an OpenCV image and notify sinks. @@ -554,7 +554,7 @@ class CvSource : public VideoSource { * Signal sinks that an error has occurred. This should be called instead * of NotifyFrame when an error occurs. */ - void NotifyError(wpi::StringRef msg); + void NotifyError(const wpi::Twine& msg); /** * Set source connection status. Defaults to true. @@ -568,7 +568,7 @@ class CvSource : public VideoSource { * * @param description Description */ - void SetDescription(wpi::StringRef description); + void SetDescription(const wpi::Twine& description); /** * Create a property. @@ -582,7 +582,7 @@ class CvSource : public VideoSource { * @param value Current value * @return Property */ - VideoProperty CreateProperty(wpi::StringRef name, VideoProperty::Kind kind, + VideoProperty CreateProperty(const wpi::Twine& name, VideoProperty::Kind kind, int minimum, int maximum, int step, int defaultValue, int value); @@ -597,7 +597,7 @@ class CvSource : public VideoSource { * @param value Current value * @return Property */ - VideoProperty CreateIntegerProperty(wpi::StringRef name, int minimum, + VideoProperty CreateIntegerProperty(const wpi::Twine& name, int minimum, int maximum, int step, int defaultValue, int value); @@ -609,7 +609,7 @@ class CvSource : public VideoSource { * @param value Current value * @return Property */ - VideoProperty CreateBooleanProperty(wpi::StringRef name, bool defaultValue, + VideoProperty CreateBooleanProperty(const wpi::Twine& name, bool defaultValue, bool value); /** @@ -620,7 +620,8 @@ class CvSource : public VideoSource { * @param value Current value * @return Property */ - VideoProperty CreateStringProperty(wpi::StringRef name, wpi::StringRef value); + VideoProperty CreateStringProperty(const wpi::Twine& name, + const wpi::Twine& value); /** * Configure enum property choices. @@ -695,7 +696,7 @@ class VideoSink { * @return Property (kind Property::kNone if no property with * the given name exists) */ - VideoProperty GetProperty(wpi::StringRef name); + VideoProperty GetProperty(const wpi::Twine& name); /** * Enumerate all properties of this sink. @@ -725,7 +726,7 @@ class VideoSink { * @return Property (kind Property::kNone if no property with * the given name exists or no source connected) */ - VideoProperty GetSourceProperty(wpi::StringRef name); + VideoProperty GetSourceProperty(const wpi::Twine& name); CS_Status GetLastStatus() const { return m_status; } @@ -763,7 +764,8 @@ class MjpegServer : public VideoSink { * @param listenAddress TCP listen address (empty string for all addresses) * @param port TCP port number */ - MjpegServer(wpi::StringRef name, wpi::StringRef listenAddress, int port); + MjpegServer(const wpi::Twine& name, const wpi::Twine& listenAddress, + int port); /** * Create a MJPEG-over-HTTP server sink. @@ -771,7 +773,7 @@ class MjpegServer : public VideoSink { * @param name Sink name (arbitrary unique identifier) * @param port TCP port number */ - MjpegServer(wpi::StringRef name, int port) : MjpegServer(name, "", port) {} + MjpegServer(const wpi::Twine& name, int port) : MjpegServer(name, "", port) {} /** * Get the listen address of the server. @@ -844,7 +846,7 @@ class CvSink : public VideoSink { * * @param name Source name (arbitrary unique identifier) */ - explicit CvSink(wpi::StringRef name); + explicit CvSink(const wpi::Twine& name); /** * Create a sink for accepting OpenCV images in a separate thread. @@ -858,14 +860,15 @@ class CvSink : public VideoSink { * or GetError() as needed, but should not call (except in very * unusual circumstances) WaitForImage(). */ - CvSink(wpi::StringRef name, std::function processFrame); + CvSink(const wpi::Twine& name, + std::function processFrame); /** * Set sink description. * * @param description Description */ - void SetDescription(wpi::StringRef description); + void SetDescription(const wpi::Twine& description); /** * Wait for the next frame and get the image. diff --git a/cscore/src/main/native/include/cscore_oo.inl b/cscore/src/main/native/include/cscore_oo.inl index 3c95487b1e..9693045069 100644 --- a/cscore/src/main/native/include/cscore_oo.inl +++ b/cscore/src/main/native/include/cscore_oo.inl @@ -56,7 +56,7 @@ inline wpi::StringRef VideoProperty::GetString( return GetStringProperty(m_handle, buf, &m_status); } -inline void VideoProperty::SetString(wpi::StringRef value) { +inline void VideoProperty::SetString(const wpi::Twine& value) { m_status = 0; SetStringProperty(m_handle, value, &m_status); } @@ -121,7 +121,7 @@ inline bool VideoSource::IsConnected() const { return IsSourceConnected(m_handle, &m_status); } -inline VideoProperty VideoSource::GetProperty(wpi::StringRef name) { +inline VideoProperty VideoSource::GetProperty(const wpi::Twine& name) { m_status = 0; return VideoProperty{GetSourceProperty(m_handle, name, &m_status)}; } @@ -215,11 +215,11 @@ inline void VideoCamera::SetExposureManual(int value) { SetCameraExposureManual(m_handle, value, &m_status); } -inline UsbCamera::UsbCamera(wpi::StringRef name, int dev) { +inline UsbCamera::UsbCamera(const wpi::Twine& name, int dev) { m_handle = CreateUsbCameraDev(name, dev, &m_status); } -inline UsbCamera::UsbCamera(wpi::StringRef name, wpi::StringRef path) { +inline UsbCamera::UsbCamera(const wpi::Twine& name, const wpi::Twine& path) { m_handle = CreateUsbCameraPath(name, path, &m_status); } @@ -239,25 +239,25 @@ inline void UsbCamera::SetConnectVerbose(int level) { &m_status); } -inline HttpCamera::HttpCamera(wpi::StringRef name, wpi::StringRef url, +inline HttpCamera::HttpCamera(const wpi::Twine& name, const wpi::Twine& url, HttpCameraKind kind) { m_handle = CreateHttpCamera( name, url, static_cast(static_cast(kind)), &m_status); } -inline HttpCamera::HttpCamera(wpi::StringRef name, const char* url, +inline HttpCamera::HttpCamera(const wpi::Twine& name, const char* url, HttpCameraKind kind) { m_handle = CreateHttpCamera( name, url, static_cast(static_cast(kind)), &m_status); } -inline HttpCamera::HttpCamera(wpi::StringRef name, const std::string& url, +inline HttpCamera::HttpCamera(const wpi::Twine& name, const std::string& url, HttpCameraKind kind) - : HttpCamera(name, wpi::StringRef{url}, kind) {} + : HttpCamera(name, wpi::Twine{url}, kind) {} -inline HttpCamera::HttpCamera(wpi::StringRef name, +inline HttpCamera::HttpCamera(const wpi::Twine& name, wpi::ArrayRef urls, HttpCameraKind kind) { m_handle = CreateHttpCamera( @@ -266,7 +266,7 @@ inline HttpCamera::HttpCamera(wpi::StringRef name, } template -inline HttpCamera::HttpCamera(wpi::StringRef name, +inline HttpCamera::HttpCamera(const wpi::Twine& name, std::initializer_list urls, HttpCameraKind kind) { std::vector vec; @@ -302,11 +302,8 @@ inline std::vector HttpCamera::GetUrls() const { return ::cs::GetHttpCameraUrls(m_handle, &m_status); } -inline std::string AxisCamera::HostToUrl(wpi::StringRef host) { - std::string rv{"http://"}; - rv += host; - rv += "/mjpg/video.mjpg"; - return rv; +inline std::string AxisCamera::HostToUrl(const wpi::Twine& host) { + return ("http://" + host + "/mjpg/video.mjpg").str(); } inline std::vector AxisCamera::HostToUrl( @@ -328,29 +325,29 @@ inline std::vector AxisCamera::HostToUrl( return rv; } -inline AxisCamera::AxisCamera(wpi::StringRef name, wpi::StringRef host) +inline AxisCamera::AxisCamera(const wpi::Twine& name, const wpi::Twine& host) : HttpCamera(name, HostToUrl(host), kAxis) {} -inline AxisCamera::AxisCamera(wpi::StringRef name, const char* host) +inline AxisCamera::AxisCamera(const wpi::Twine& name, const char* host) : HttpCamera(name, HostToUrl(host), kAxis) {} -inline AxisCamera::AxisCamera(wpi::StringRef name, const std::string& host) - : HttpCamera(name, HostToUrl(wpi::StringRef{host}), kAxis) {} +inline AxisCamera::AxisCamera(const wpi::Twine& name, const std::string& host) + : HttpCamera(name, HostToUrl(wpi::Twine{host}), kAxis) {} -inline AxisCamera::AxisCamera(wpi::StringRef name, +inline AxisCamera::AxisCamera(const wpi::Twine& name, wpi::ArrayRef hosts) : HttpCamera(name, HostToUrl(hosts), kAxis) {} template -inline AxisCamera::AxisCamera(wpi::StringRef name, +inline AxisCamera::AxisCamera(const wpi::Twine& name, std::initializer_list hosts) : HttpCamera(name, HostToUrl(hosts), kAxis) {} -inline CvSource::CvSource(wpi::StringRef name, const VideoMode& mode) { +inline CvSource::CvSource(const wpi::Twine& name, const VideoMode& mode) { m_handle = CreateCvSource(name, mode, &m_status); } -inline CvSource::CvSource(wpi::StringRef name, VideoMode::PixelFormat format, +inline CvSource::CvSource(const wpi::Twine& name, VideoMode::PixelFormat format, int width, int height, int fps) { m_handle = CreateCvSource(name, VideoMode{format, width, height, fps}, &m_status); @@ -361,7 +358,7 @@ inline void CvSource::PutFrame(cv::Mat& image) { PutSourceFrame(m_handle, image, &m_status); } -inline void CvSource::NotifyError(wpi::StringRef msg) { +inline void CvSource::NotifyError(const wpi::Twine& msg) { m_status = 0; NotifySourceError(m_handle, msg, &m_status); } @@ -371,12 +368,12 @@ inline void CvSource::SetConnected(bool connected) { SetSourceConnected(m_handle, connected, &m_status); } -inline void CvSource::SetDescription(wpi::StringRef description) { +inline void CvSource::SetDescription(const wpi::Twine& description) { m_status = 0; SetSourceDescription(m_handle, description, &m_status); } -inline VideoProperty CvSource::CreateProperty(wpi::StringRef name, +inline VideoProperty CvSource::CreateProperty(const wpi::Twine& name, VideoProperty::Kind kind, int minimum, int maximum, int step, int defaultValue, @@ -387,7 +384,7 @@ inline VideoProperty CvSource::CreateProperty(wpi::StringRef name, minimum, maximum, step, defaultValue, value, &m_status)}; } -inline VideoProperty CvSource::CreateIntegerProperty(wpi::StringRef name, +inline VideoProperty CvSource::CreateIntegerProperty(const wpi::Twine& name, int minimum, int maximum, int step, int defaultValue, int value) { @@ -397,7 +394,7 @@ inline VideoProperty CvSource::CreateIntegerProperty(wpi::StringRef name, minimum, maximum, step, defaultValue, value, &m_status)}; } -inline VideoProperty CvSource::CreateBooleanProperty(wpi::StringRef name, +inline VideoProperty CvSource::CreateBooleanProperty(const wpi::Twine& name, bool defaultValue, bool value) { m_status = 0; @@ -406,8 +403,8 @@ inline VideoProperty CvSource::CreateBooleanProperty(wpi::StringRef name, 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0, &m_status)}; } -inline VideoProperty CvSource::CreateStringProperty(wpi::StringRef name, - wpi::StringRef value) { +inline VideoProperty CvSource::CreateStringProperty(const wpi::Twine& name, + const wpi::Twine& value) { m_status = 0; auto prop = VideoProperty{CreateSourceProperty( m_handle, name, static_cast(static_cast(VideoProperty::Kind::kString)), @@ -465,7 +462,7 @@ inline std::string VideoSink::GetDescription() const { return GetSinkDescription(m_handle, &m_status); } -inline VideoProperty VideoSink::GetProperty(wpi::StringRef name) { +inline VideoProperty VideoSink::GetProperty(const wpi::Twine& name) { m_status = 0; return VideoProperty{GetSinkProperty(m_handle, name, &m_status)}; } @@ -484,13 +481,13 @@ inline VideoSource VideoSink::GetSource() const { return VideoSource{handle == 0 ? 0 : CopySource(handle, &m_status)}; } -inline VideoProperty VideoSink::GetSourceProperty(wpi::StringRef name) { +inline VideoProperty VideoSink::GetSourceProperty(const wpi::Twine& name) { m_status = 0; return VideoProperty{GetSinkSourceProperty(m_handle, name, &m_status)}; } -inline MjpegServer::MjpegServer(wpi::StringRef name, - wpi::StringRef listenAddress, int port) { +inline MjpegServer::MjpegServer(const wpi::Twine& name, + const wpi::Twine& listenAddress, int port) { m_handle = CreateMjpegServer(name, listenAddress, port, &m_status); } @@ -528,16 +525,16 @@ inline void MjpegServer::SetDefaultCompression(int quality) { quality, &m_status); } -inline CvSink::CvSink(wpi::StringRef name) { +inline CvSink::CvSink(const wpi::Twine& name) { m_handle = CreateCvSink(name, &m_status); } -inline CvSink::CvSink(wpi::StringRef name, +inline CvSink::CvSink(const wpi::Twine& name, std::function processFrame) { m_handle = CreateCvSinkCallback(name, processFrame, &m_status); } -inline void CvSink::SetDescription(wpi::StringRef description) { +inline void CvSink::SetDescription(const wpi::Twine& description) { m_status = 0; SetSinkDescription(m_handle, description, &m_status); } diff --git a/wpilibc/src/main/native/cpp/RobotBase.cpp b/wpilibc/src/main/native/cpp/RobotBase.cpp index b9e3338422..ddcda7db98 100644 --- a/wpilibc/src/main/native/cpp/RobotBase.cpp +++ b/wpilibc/src/main/native/cpp/RobotBase.cpp @@ -37,13 +37,13 @@ class WPILibCameraServerShared : public frc::CameraServerShared { void ReportVideoServer(int id) override { HAL_Report(HALUsageReporting::kResourceType_PCVideoServer, id); } - void SetCameraServerError(wpi::StringRef error) override { + void SetCameraServerError(const wpi::Twine& error) override { wpi_setGlobalWPIErrorWithContext(CameraServerError, error); } - void SetVisionRunnerError(wpi::StringRef error) override { + void SetVisionRunnerError(const wpi::Twine& error) override { wpi_setGlobalErrorWithContext(-1, error); } - void ReportDriverStationError(wpi::StringRef error) override { + void ReportDriverStationError(const wpi::Twine& error) override { DriverStation::ReportError(error); } std::pair GetRobotMainThreadId() const override {