mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
Collapse boolean/double/enum properties into just integer.
This commit is contained in:
@@ -206,19 +206,15 @@ void HTTPSinkImpl::SendJSON(llvm::raw_ostream& os, SourceImpl& source,
|
||||
os << ",\n\"value\": \"";
|
||||
switch (type) {
|
||||
case CS_PROP_BOOLEAN:
|
||||
os << (source.GetBooleanProperty(prop, &status) ? "1" : "0");
|
||||
break;
|
||||
case CS_PROP_DOUBLE:
|
||||
os << source.GetDoubleProperty(prop, &status);
|
||||
case CS_PROP_INTEGER:
|
||||
case CS_PROP_ENUM:
|
||||
os << source.GetProperty(prop, &status);
|
||||
break;
|
||||
case CS_PROP_STRING: {
|
||||
llvm::SmallString<128> strval_buf;
|
||||
os << source.GetStringProperty(prop, strval_buf, &status);
|
||||
break;
|
||||
}
|
||||
case CS_PROP_ENUM:
|
||||
os << source.GetEnumProperty(prop, &status);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -78,30 +78,24 @@ class SourceImpl {
|
||||
void Wakeup();
|
||||
|
||||
// Property functions
|
||||
virtual int GetProperty(llvm::StringRef name) const = 0;
|
||||
virtual int GetPropertyIndex(llvm::StringRef name) const = 0;
|
||||
virtual llvm::ArrayRef<int> EnumerateProperties(
|
||||
llvm::SmallVectorImpl<int>& vec) const = 0;
|
||||
virtual CS_PropertyType GetPropertyType(int property) const = 0;
|
||||
virtual llvm::StringRef GetPropertyName(int property,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) const = 0;
|
||||
virtual bool GetBooleanProperty(int property, CS_Status* status) const = 0;
|
||||
virtual void SetBooleanProperty(int property, bool value,
|
||||
CS_Status* status) = 0;
|
||||
virtual double GetDoubleProperty(int property, CS_Status* status) const = 0;
|
||||
virtual void SetDoubleProperty(int property, double value,
|
||||
CS_Status* status) = 0;
|
||||
virtual double GetPropertyMin(int property, CS_Status* status) const = 0;
|
||||
virtual double GetPropertyMax(int property, CS_Status* status) const = 0;
|
||||
virtual double GetPropertyStep(int property, CS_Status* status) const = 0;
|
||||
virtual double GetPropertyDefault(int property, CS_Status* status) const = 0;
|
||||
virtual int GetProperty(int property, CS_Status* status) const = 0;
|
||||
virtual void SetProperty(int property, int value, CS_Status* status) = 0;
|
||||
virtual int GetPropertyMin(int property, CS_Status* status) const = 0;
|
||||
virtual int GetPropertyMax(int property, CS_Status* status) const = 0;
|
||||
virtual int GetPropertyStep(int property, CS_Status* status) const = 0;
|
||||
virtual int GetPropertyDefault(int property, CS_Status* status) const = 0;
|
||||
virtual llvm::StringRef GetStringProperty(int property,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) const = 0;
|
||||
virtual void SetStringProperty(int property, llvm::StringRef value,
|
||||
CS_Status* status) = 0;
|
||||
virtual int GetEnumProperty(int property, CS_Status* status) const = 0;
|
||||
virtual void SetEnumProperty(int property, int value, CS_Status* status) = 0;
|
||||
virtual std::vector<std::string> GetEnumPropertyChoices(
|
||||
int property, CS_Status* status) const = 0;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ USBCameraImpl::PropertyData::PropertyData(
|
||||
switch (ctrl.type) {
|
||||
case V4L2_CTRL_TYPE_INTEGER:
|
||||
case V4L2_CTRL_TYPE_INTEGER64:
|
||||
propType = CS_PROP_DOUBLE;
|
||||
propType = CS_PROP_INTEGER;
|
||||
break;
|
||||
case V4L2_CTRL_TYPE_BOOLEAN:
|
||||
propType = CS_PROP_BOOLEAN;
|
||||
@@ -87,7 +87,7 @@ USBCameraImpl::PropertyData::PropertyData(const struct v4l2_queryctrl& ctrl)
|
||||
switch (ctrl.type) {
|
||||
case V4L2_CTRL_TYPE_INTEGER:
|
||||
case V4L2_CTRL_TYPE_INTEGER64:
|
||||
propType = CS_PROP_DOUBLE;
|
||||
propType = CS_PROP_INTEGER;
|
||||
break;
|
||||
case V4L2_CTRL_TYPE_BOOLEAN:
|
||||
propType = CS_PROP_BOOLEAN;
|
||||
@@ -318,7 +318,7 @@ void USBCameraImpl::CacheProperties() const {
|
||||
m_properties_cached = true;
|
||||
}
|
||||
|
||||
int USBCameraImpl::GetProperty(llvm::StringRef name) const {
|
||||
int USBCameraImpl::GetPropertyIndex(llvm::StringRef name) const {
|
||||
if (!m_properties_cached) CacheProperties();
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_properties.lookup(name);
|
||||
@@ -332,8 +332,7 @@ llvm::ArrayRef<int> USBCameraImpl::EnumerateProperties(
|
||||
return vec;
|
||||
}
|
||||
|
||||
bool USBCameraImpl::GetPropertyTypeValueFd(int property,
|
||||
CS_PropertyType propType,
|
||||
bool USBCameraImpl::GetPropertyTypeValueFd(int property, int propType,
|
||||
unsigned* id, int* type, int* fd,
|
||||
CS_Status* status) const {
|
||||
// Get id and type from cached properties
|
||||
@@ -345,7 +344,7 @@ bool USBCameraImpl::GetPropertyTypeValueFd(int property,
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
return false;
|
||||
}
|
||||
if (it->getSecond().propType != propType) {
|
||||
if ((it->getSecond().propType & propType) == 0) {
|
||||
*status = CS_WRONG_PROPERTY_TYPE;
|
||||
return false;
|
||||
}
|
||||
@@ -382,42 +381,13 @@ llvm::StringRef USBCameraImpl::GetPropertyName(int property,
|
||||
return it->getSecond().name; // safe because we never modify it after caching
|
||||
}
|
||||
|
||||
bool USBCameraImpl::GetBooleanProperty(int property, CS_Status* status) const {
|
||||
int USBCameraImpl::GetProperty(int property, CS_Status* status) const {
|
||||
unsigned id;
|
||||
int type;
|
||||
int fd;
|
||||
if (!GetPropertyTypeValueFd(property, CS_PROP_BOOLEAN, &id, &type, &fd,
|
||||
status))
|
||||
return false;
|
||||
|
||||
int64_t value = 0;
|
||||
if (GetIntCtrlIoctl(fd, id, type, &value) < 0) {
|
||||
*status = CS_PROPERTY_READ_FAILED;
|
||||
return false;
|
||||
}
|
||||
return value != 0;
|
||||
}
|
||||
|
||||
void USBCameraImpl::SetBooleanProperty(int property, bool value,
|
||||
CS_Status* status) {
|
||||
unsigned id;
|
||||
int type;
|
||||
int fd;
|
||||
if (!GetPropertyTypeValueFd(property, CS_PROP_BOOLEAN, &id, &type, &fd,
|
||||
status))
|
||||
return;
|
||||
|
||||
if (SetIntCtrlIoctl(fd, id, type, value ? 1 : 0) < 0) {
|
||||
*status = CS_PROPERTY_WRITE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
double USBCameraImpl::GetDoubleProperty(int property, CS_Status* status) const {
|
||||
unsigned id;
|
||||
int type;
|
||||
int fd;
|
||||
if (!GetPropertyTypeValueFd(property, CS_PROP_DOUBLE, &id, &type, &fd,
|
||||
status))
|
||||
if (!GetPropertyTypeValueFd(property,
|
||||
CS_PROP_BOOLEAN | CS_PROP_INTEGER | CS_PROP_ENUM,
|
||||
&id, &type, &fd, status))
|
||||
return false;
|
||||
|
||||
int64_t value = 0;
|
||||
@@ -428,13 +398,13 @@ double USBCameraImpl::GetDoubleProperty(int property, CS_Status* status) const {
|
||||
return value;
|
||||
}
|
||||
|
||||
void USBCameraImpl::SetDoubleProperty(int property, double value,
|
||||
CS_Status* status) {
|
||||
void USBCameraImpl::SetProperty(int property, int value, CS_Status* status) {
|
||||
unsigned id;
|
||||
int type;
|
||||
int fd;
|
||||
if (!GetPropertyTypeValueFd(property, CS_PROP_DOUBLE, &id, &type, &fd,
|
||||
status))
|
||||
if (!GetPropertyTypeValueFd(property,
|
||||
CS_PROP_BOOLEAN | CS_PROP_INTEGER | CS_PROP_ENUM,
|
||||
&id, &type, &fd, status))
|
||||
return;
|
||||
|
||||
if (SetIntCtrlIoctl(fd, id, type, static_cast<int64_t>(value)) < 0) {
|
||||
@@ -442,7 +412,7 @@ void USBCameraImpl::SetDoubleProperty(int property, double value,
|
||||
}
|
||||
}
|
||||
|
||||
double USBCameraImpl::GetPropertyMin(int property, CS_Status* status) const {
|
||||
int USBCameraImpl::GetPropertyMin(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached) CacheProperties();
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto it = m_property_data.find(property);
|
||||
@@ -453,7 +423,7 @@ double USBCameraImpl::GetPropertyMin(int property, CS_Status* status) const {
|
||||
return it->getSecond().minimum;
|
||||
}
|
||||
|
||||
double USBCameraImpl::GetPropertyMax(int property, CS_Status* status) const {
|
||||
int USBCameraImpl::GetPropertyMax(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached) CacheProperties();
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto it = m_property_data.find(property);
|
||||
@@ -464,7 +434,7 @@ double USBCameraImpl::GetPropertyMax(int property, CS_Status* status) const {
|
||||
return it->getSecond().maximum;
|
||||
}
|
||||
|
||||
double USBCameraImpl::GetPropertyStep(int property, CS_Status* status) const {
|
||||
int USBCameraImpl::GetPropertyStep(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached) CacheProperties();
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto it = m_property_data.find(property);
|
||||
@@ -475,8 +445,7 @@ double USBCameraImpl::GetPropertyStep(int property, CS_Status* status) const {
|
||||
return it->getSecond().step;
|
||||
}
|
||||
|
||||
double USBCameraImpl::GetPropertyDefault(int property,
|
||||
CS_Status* status) const {
|
||||
int USBCameraImpl::GetPropertyDefault(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached) CacheProperties();
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto it = m_property_data.find(property);
|
||||
@@ -557,34 +526,6 @@ void USBCameraImpl::SetStringProperty(int property, llvm::StringRef value,
|
||||
}
|
||||
}
|
||||
|
||||
int USBCameraImpl::GetEnumProperty(int property, CS_Status* status) const {
|
||||
unsigned id;
|
||||
int type;
|
||||
int fd;
|
||||
if (!GetPropertyTypeValueFd(property, CS_PROP_ENUM, &id, &type, &fd, status))
|
||||
return false;
|
||||
|
||||
int64_t value = 0;
|
||||
if (GetIntCtrlIoctl(fd, id, type, &value) < 0) {
|
||||
*status = CS_PROPERTY_READ_FAILED;
|
||||
return false;
|
||||
}
|
||||
return static_cast<int>(value);
|
||||
}
|
||||
|
||||
void USBCameraImpl::SetEnumProperty(int property, int value,
|
||||
CS_Status* status) {
|
||||
unsigned id;
|
||||
int type;
|
||||
int fd;
|
||||
if (!GetPropertyTypeValueFd(property, CS_PROP_ENUM, &id, &type, &fd, status))
|
||||
return;
|
||||
|
||||
if (SetIntCtrlIoctl(fd, id, type, value) < 0) {
|
||||
*status = CS_PROPERTY_WRITE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> USBCameraImpl::GetEnumPropertyChoices(
|
||||
int property, CS_Status* status) const {
|
||||
unsigned id;
|
||||
|
||||
@@ -34,29 +34,24 @@ class USBCameraImpl : public SourceImpl {
|
||||
llvm::SmallVectorImpl<char>& buf) const override;
|
||||
|
||||
// Property functions
|
||||
int GetProperty(llvm::StringRef name) const override;
|
||||
int GetPropertyIndex(llvm::StringRef name) const override;
|
||||
llvm::ArrayRef<int> EnumerateProperties(
|
||||
llvm::SmallVectorImpl<int>& vec) const override;
|
||||
CS_PropertyType GetPropertyType(int property) const override;
|
||||
llvm::StringRef GetPropertyName(int property,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) const override;
|
||||
bool GetBooleanProperty(int property, CS_Status* status) const override;
|
||||
void SetBooleanProperty(int property, bool value, CS_Status* status) override;
|
||||
double GetDoubleProperty(int property, CS_Status* status) const override;
|
||||
void SetDoubleProperty(int property, double value,
|
||||
CS_Status* status) override;
|
||||
double GetPropertyMin(int property, CS_Status* status) const override;
|
||||
double GetPropertyMax(int property, CS_Status* status) const override;
|
||||
double GetPropertyStep(int property, CS_Status* status) const override;
|
||||
double GetPropertyDefault(int property, CS_Status* status) const override;
|
||||
int GetProperty(int property, CS_Status* status) const override;
|
||||
void SetProperty(int property, int value, CS_Status* status) override;
|
||||
int GetPropertyMin(int property, CS_Status* status) const override;
|
||||
int GetPropertyMax(int property, CS_Status* status) const override;
|
||||
int GetPropertyStep(int property, CS_Status* status) const override;
|
||||
int GetPropertyDefault(int property, CS_Status* status) const override;
|
||||
llvm::StringRef GetStringProperty(int property,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) const override;
|
||||
void SetStringProperty(int property, llvm::StringRef value,
|
||||
CS_Status* status) override;
|
||||
int GetEnumProperty(int property, CS_Status* status) const override;
|
||||
void SetEnumProperty(int property, int value, CS_Status* status) override;
|
||||
std::vector<std::string> GetEnumPropertyChoices(
|
||||
int property, CS_Status* status) const override;
|
||||
|
||||
@@ -75,10 +70,10 @@ class USBCameraImpl : public SourceImpl {
|
||||
unsigned id; // implementation-level id
|
||||
int type; // implementation type, not CS_PropertyType!
|
||||
CS_PropertyType propType;
|
||||
double minimum;
|
||||
double maximum;
|
||||
double step;
|
||||
double defaultValue;
|
||||
int minimum;
|
||||
int maximum;
|
||||
int step;
|
||||
int defaultValue;
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -88,9 +83,8 @@ class USBCameraImpl : public SourceImpl {
|
||||
|
||||
void CacheProperty(PropertyData&& prop) const;
|
||||
void CacheProperties() const;
|
||||
bool GetPropertyTypeValueFd(int property, CS_PropertyType propType,
|
||||
unsigned* id, int* type, int* fd,
|
||||
CS_Status* status) const;
|
||||
bool GetPropertyTypeValueFd(int property, int propType, unsigned* id,
|
||||
int* type, int* fd, CS_Status* status) const;
|
||||
|
||||
void CameraThreadMain();
|
||||
|
||||
|
||||
@@ -28,37 +28,27 @@ char* CS_GetPropertyName(CS_Property property, CS_Status* status) {
|
||||
return cs::ConvertToC(str);
|
||||
}
|
||||
|
||||
CS_Bool CS_GetBooleanProperty(CS_Property property, CS_Status* status) {
|
||||
return cs::GetBooleanProperty(property, status);
|
||||
int CS_GetProperty(CS_Property property, CS_Status* status) {
|
||||
return cs::GetProperty(property, status);
|
||||
}
|
||||
|
||||
void CS_SetBooleanProperty(CS_Property property, CS_Bool value,
|
||||
CS_Status* status) {
|
||||
return cs::SetBooleanProperty(property, value, status);
|
||||
void CS_SetProperty(CS_Property property, int value, CS_Status* status) {
|
||||
return cs::SetProperty(property, value, status);
|
||||
}
|
||||
|
||||
double CS_GetDoubleProperty(CS_Property property, CS_Status* status) {
|
||||
return cs::GetDoubleProperty(property, status);
|
||||
}
|
||||
|
||||
void CS_SetDoubleProperty(CS_Property property, double value,
|
||||
CS_Status* status) {
|
||||
return cs::SetDoubleProperty(property, value, status);
|
||||
}
|
||||
|
||||
double CS_GetPropertyMin(CS_Property property, CS_Status* status) {
|
||||
int CS_GetPropertyMin(CS_Property property, CS_Status* status) {
|
||||
return cs::GetPropertyMin(property, status);
|
||||
}
|
||||
|
||||
double CS_GetPropertyMax(CS_Property property, CS_Status* status) {
|
||||
int CS_GetPropertyMax(CS_Property property, CS_Status* status) {
|
||||
return cs::GetPropertyMax(property, status);
|
||||
}
|
||||
|
||||
double CS_GetPropertyStep(CS_Property property, CS_Status* status) {
|
||||
int CS_GetPropertyStep(CS_Property property, CS_Status* status) {
|
||||
return cs::GetPropertyStep(property, status);
|
||||
}
|
||||
|
||||
double CS_GetPropertyDefault(CS_Property property, CS_Status* status) {
|
||||
int CS_GetPropertyDefault(CS_Property property, CS_Status* status) {
|
||||
return cs::GetPropertyDefault(property, status);
|
||||
}
|
||||
|
||||
@@ -74,14 +64,6 @@ void CS_SetStringProperty(CS_Property property, const char* value,
|
||||
return cs::SetStringProperty(property, value, status);
|
||||
}
|
||||
|
||||
int CS_GetEnumProperty(CS_Property property, CS_Status* status) {
|
||||
return cs::GetEnumProperty(property, status);
|
||||
}
|
||||
|
||||
void CS_SetEnumProperty(CS_Property property, int value, CS_Status* status) {
|
||||
return cs::SetEnumProperty(property, value, status);
|
||||
}
|
||||
|
||||
char** CS_GetEnumPropertyChoices(CS_Property property, int* count,
|
||||
CS_Status* status) {
|
||||
auto choices = cs::GetEnumPropertyChoices(property, status);
|
||||
|
||||
@@ -63,56 +63,42 @@ llvm::StringRef GetPropertyName(CS_Property property,
|
||||
return source->GetPropertyName(propertyIndex, buf, status);
|
||||
}
|
||||
|
||||
bool GetBooleanProperty(CS_Property property, CS_Status* status) {
|
||||
int GetProperty(CS_Property property, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return false;
|
||||
return source->GetBooleanProperty(propertyIndex, status);
|
||||
return source->GetProperty(propertyIndex, status);
|
||||
}
|
||||
|
||||
void SetBooleanProperty(CS_Property property, bool value, CS_Status* status) {
|
||||
void SetProperty(CS_Property property, int value, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return;
|
||||
source->SetBooleanProperty(propertyIndex, value, status);
|
||||
source->SetProperty(propertyIndex, value, status);
|
||||
}
|
||||
|
||||
double GetDoubleProperty(CS_Property property, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return false;
|
||||
return source->GetDoubleProperty(propertyIndex, status);
|
||||
}
|
||||
|
||||
void SetDoubleProperty(CS_Property property, double value, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return;
|
||||
source->SetDoubleProperty(propertyIndex, value, status);
|
||||
}
|
||||
|
||||
double GetPropertyMin(CS_Property property, CS_Status* status) {
|
||||
int GetPropertyMin(CS_Property property, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return 0.0;
|
||||
return source->GetPropertyMin(propertyIndex, status);
|
||||
}
|
||||
|
||||
double GetPropertyMax(CS_Property property, CS_Status* status) {
|
||||
int GetPropertyMax(CS_Property property, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return 0.0;
|
||||
return source->GetPropertyMax(propertyIndex, status);
|
||||
}
|
||||
|
||||
double GetPropertyStep(CS_Property property, CS_Status* status) {
|
||||
int GetPropertyStep(CS_Property property, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return 0.0;
|
||||
return source->GetPropertyStep(propertyIndex, status);
|
||||
}
|
||||
|
||||
double GetPropertyDefault(CS_Property property, CS_Status* status) {
|
||||
int GetPropertyDefault(CS_Property property, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return 0.0;
|
||||
@@ -144,20 +130,6 @@ void SetStringProperty(CS_Property property, llvm::StringRef value,
|
||||
source->SetStringProperty(propertyIndex, value, status);
|
||||
}
|
||||
|
||||
int GetEnumProperty(CS_Property property, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return 0;
|
||||
return source->GetEnumProperty(propertyIndex, status);
|
||||
}
|
||||
|
||||
void SetEnumProperty(CS_Property property, int value, CS_Status* status) {
|
||||
int propertyIndex;
|
||||
auto source = GetPropertySource(property, &propertyIndex, status);
|
||||
if (!source) return;
|
||||
source->SetEnumProperty(propertyIndex, value, status);
|
||||
}
|
||||
|
||||
std::vector<std::string> GetEnumPropertyChoices(CS_Property property,
|
||||
CS_Status* status) {
|
||||
int propertyIndex;
|
||||
@@ -244,7 +216,7 @@ CS_Property GetSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
int property = data->source->GetProperty(name);
|
||||
int property = data->source->GetPropertyIndex(name);
|
||||
if (property < 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user