cscore: Use Twine instead of StringRef in API (#1244)

This commit is contained in:
Peter Johnson
2018-07-29 12:53:41 -07:00
committed by GitHub
parent 97a8f8f47b
commit 195e101816
35 changed files with 365 additions and 350 deletions

View File

@@ -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<void(uint64_t time)> 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<CvSinkImpl>(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<void(uint64_t time)> processFrame,
CS_Status* status) {
auto sink = std::make_shared<CvSinkImpl>(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) {

View File

@@ -17,6 +17,7 @@
#include <wpi/NetworkStream.h>
#include <wpi/SmallVector.h>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#include <wpi/raw_istream.h>
#include <wpi/raw_ostream.h>
#include <wpi/raw_socket_ostream.h>
@@ -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<void(uint64_t time)> processFrame);
~CvSinkImpl() override;

View File

@@ -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<wpi::mutex> 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<void(CS_Property property)> 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<CvSourceImpl>(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<CvSourceImpl&>(*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<CvSourceImpl&>(*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<CvSourceImpl&>(*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<void(CS_Property property)> onChange, CS_Status* status) {
auto data = Sources::GetInstance().Get(source);

View File

@@ -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<void(CS_Property property)> onChange);
void SetEnumPropertyChoices(int property, wpi::ArrayRef<std::string> choices,

View File

@@ -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;
}

View File

@@ -15,6 +15,7 @@
#include <vector>
#include <wpi/SmallVector.h>
#include <wpi/Twine.h>
#include <wpi/mutex.h>
#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> image, Time time);

View File

@@ -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<std::string> 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<wpi::mutex> lock(m_mutex);
m_propertyData.emplace_back(wpi::make_unique<PropertyData>(
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 <typename T>
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<T> choices) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
m_propertyData.emplace_back(wpi::make_unique<PropertyData>(
@@ -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<PropertyImpl> HttpCameraImpl::CreateEmptyProperty(
wpi::StringRef name) const {
const wpi::Twine& name) const {
return wpi::make_unique<PropertyData>(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<HttpCameraImpl> source;
switch (kind) {
@@ -485,8 +485,7 @@ CS_Source CreateHttpCamera(wpi::StringRef name, wpi::StringRef url,
source = std::make_shared<HttpCameraImpl>(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<std::string> urls,
CS_Source CreateHttpCamera(const wpi::Twine& name,
wpi::ArrayRef<std::string> urls,
CS_HttpCameraKind kind, CS_Status* status) {
if (urls.empty()) {
*status = CS_EMPTY_VALUE;

View File

@@ -19,6 +19,7 @@
#include <wpi/HttpUtil.h>
#include <wpi/SmallString.h>
#include <wpi/StringMap.h>
#include <wpi/Twine.h>
#include <wpi/condition_variable.h>
#include <wpi/raw_istream.h>
@@ -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<PropertyImpl> 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 <typename T>
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<T> 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:

View File

@@ -73,7 +73,7 @@ static const char* endRootPage = "</div></body></html>";
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<wpi::NetworkAcceptor> 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<SourceImpl> 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<MjpegServerImpl>(
name, listenAddress, port,
std::unique_ptr<wpi::NetworkAcceptor>(
new wpi::TCPAcceptor(port, str.c_str(), Logger::GetInstance())));
std::unique_ptr<wpi::NetworkAcceptor>(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;

View File

@@ -18,7 +18,7 @@
#include <wpi/NetworkStream.h>
#include <wpi/SafeThread.h>
#include <wpi/SmallVector.h>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#include <wpi/raw_istream.h>
#include <wpi/raw_ostream.h>
#include <wpi/raw_socket_ostream.h>
@@ -31,8 +31,8 @@ class SourceImpl;
class MjpegServerImpl : public SinkImpl {
public:
MjpegServerImpl(wpi::StringRef name, wpi::StringRef listenAddress, int port,
std::unique_ptr<wpi::NetworkAcceptor> acceptor);
MjpegServerImpl(const wpi::Twine& name, const wpi::Twine& listenAddress,
int port, std::unique_ptr<wpi::NetworkAcceptor> acceptor);
~MjpegServerImpl() override;
void Stop();

View File

@@ -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;

View File

@@ -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();

View File

@@ -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<wpi::mutex> lock(m_mutex);
int& ndx = m_properties[name];
wpi::SmallVector<char, 64> 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<wpi::mutex> lock(m_mutex);
auto prop = GetProperty(property);
@@ -194,7 +195,7 @@ std::vector<std::string> PropertyContainer::GetEnumPropertyChoices(
}
std::unique_ptr<PropertyImpl> PropertyContainer::CreateEmptyProperty(
wpi::StringRef name) const {
const wpi::Twine& name) const {
return wpi::make_unique<PropertyImpl>(name);
}

View File

@@ -18,6 +18,7 @@
#include <wpi/SmallVector.h>
#include <wpi/StringMap.h>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#include <wpi/mutex.h>
#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<int> EnumerateProperties(wpi::SmallVectorImpl<int>& vec,
CS_Status* status) const;
CS_PropertyKind GetPropertyKind(int property) const;
@@ -44,7 +45,7 @@ class PropertyContainer {
wpi::StringRef GetStringProperty(int property,
wpi::SmallVectorImpl<char>& 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<std::string> GetEnumPropertyChoices(int property,
CS_Status* status) const;
@@ -65,9 +66,10 @@ class PropertyContainer {
// @tparam NewFunc functor that returns a std::unique_ptr<PropertyImpl>
// @tparam UpdateFunc functor that takes a PropertyImpl&.
template <typename NewFunc, typename UpdateFunc>
int CreateOrUpdateProperty(wpi::StringRef name, NewFunc newFunc,
int CreateOrUpdateProperty(const wpi::Twine& name, NewFunc newFunc,
UpdateFunc updateFunc) {
int& ndx = m_properties[name];
wpi::SmallVector<char, 64> 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 <typename NewFunc>
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<PropertyImpl> 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)

View File

@@ -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;

View File

@@ -13,6 +13,7 @@
#include <wpi/Signal.h>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#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;

View File

@@ -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<wpi::mutex> lock(m_mutex);
m_description = description;
m_description = description.str();
}
wpi::StringRef SinkImpl::GetDescription(wpi::SmallVectorImpl<char>& 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;

View File

@@ -12,6 +12,7 @@
#include <string>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#include <wpi/mutex.h>
#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<char>& 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<SourceImpl> source);

View File

@@ -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<wpi::mutex> 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> 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<wpi::mutex> 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;

View File

@@ -16,6 +16,7 @@
#include <wpi/ArrayRef.h>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
@@ -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<char>& 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> 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;

View File

@@ -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<PropertyImpl> UsbCameraImpl::CreateEmptyProperty(
wpi::StringRef name) const {
const wpi::Twine& name) const {
return wpi::make_unique<UsbCameraProperty>(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<UsbCameraImpl>(name, path);
auto handle = Sources::GetInstance().Allocate(CS_SOURCE_USB, source);

View File

@@ -21,6 +21,7 @@
#include <wpi/STLExtras.h>
#include <wpi/SmallVector.h>
#include <wpi/Twine.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include <wpi/raw_istream.h>
@@ -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<PropertyImpl> 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

View File

@@ -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<size_t>(maximum)))};
const wpi::Twine& value) {
wpi::SmallString<64> strBuf, strBuf2;
wpi::StringRef str = value.toNullTerminatedStringRef(strBuf);
if (str.size() > static_cast<size_t>(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<char*>(str.c_str());
ctrl.string = const_cast<char*>(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<wpi::mutex>& lock,
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& 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;

View File

@@ -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<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,
wpi::StringRef newValueStr) const;
const wpi::Twine& newValueStr) const;
#endif
// If this is a device (rather than software) property

View File

@@ -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<char>& 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) {

View File

@@ -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<CS_HttpCameraKind>(kind), &status);
auto val = cs::CreateHttpCamera(
JStringRef{env, name}.str(), JStringRef{env, url}.str(),
static_cast<CS_HttpCameraKind>(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<CS_HttpCameraKind>(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<cs::VideoMode::PixelFormat>(pixelFormat),
static_cast<int>(width), static_cast<int>(height),
static_cast<int>(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<CS_PropertyKind>(kind),
source, JStringRef{env, name}.str(), static_cast<CS_PropertyKind>(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);
}