mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Collapse boolean/double/enum properties into just integer.
This commit is contained in:
@@ -60,30 +60,24 @@ enum CS_StatusValue {
|
||||
|
||||
enum CS_PropertyType {
|
||||
CS_PROP_NONE = 0,
|
||||
CS_PROP_BOOLEAN,
|
||||
CS_PROP_DOUBLE,
|
||||
CS_PROP_STRING,
|
||||
CS_PROP_ENUM
|
||||
CS_PROP_BOOLEAN = 1,
|
||||
CS_PROP_INTEGER = 2,
|
||||
CS_PROP_STRING = 4,
|
||||
CS_PROP_ENUM = 8
|
||||
};
|
||||
|
||||
enum CS_PropertyType CS_GetPropertyType(CS_Property property,
|
||||
CS_Status* status);
|
||||
char* CS_GetPropertyName(CS_Property property, CS_Status* status);
|
||||
CS_Bool CS_GetBooleanProperty(CS_Property property, CS_Status* status);
|
||||
void CS_SetBooleanProperty(CS_Property property, CS_Bool value,
|
||||
CS_Status* status);
|
||||
double CS_GetDoubleProperty(CS_Property property, CS_Status* status);
|
||||
void CS_SetDoubleProperty(CS_Property property, double value,
|
||||
CS_Status* status);
|
||||
double CS_GetPropertyMin(CS_Property property, CS_Status* status);
|
||||
double CS_GetPropertyMax(CS_Property property, CS_Status* status);
|
||||
double CS_GetPropertyStep(CS_Property property, CS_Status* status);
|
||||
double CS_GetPropertyDefault(CS_Property property, CS_Status* status);
|
||||
int CS_GetProperty(CS_Property property, CS_Status* status);
|
||||
void CS_SetProperty(CS_Property property, int value, CS_Status* status);
|
||||
int CS_GetPropertyMin(CS_Property property, CS_Status* status);
|
||||
int CS_GetPropertyMax(CS_Property property, CS_Status* status);
|
||||
int CS_GetPropertyStep(CS_Property property, CS_Status* status);
|
||||
int CS_GetPropertyDefault(CS_Property property, CS_Status* status);
|
||||
char* CS_GetStringProperty(CS_Property property, CS_Status* status);
|
||||
void CS_SetStringProperty(CS_Property property, const char* value,
|
||||
CS_Status* status);
|
||||
int CS_GetEnumProperty(CS_Property property, CS_Status* status);
|
||||
void CS_SetEnumProperty(CS_Property property, int value, CS_Status* status);
|
||||
char** CS_GetEnumPropertyChoices(CS_Property property, int* count,
|
||||
CS_Status* status);
|
||||
|
||||
|
||||
@@ -51,22 +51,18 @@ std::string GetPropertyName(CS_Property property, CS_Status* status);
|
||||
llvm::StringRef GetPropertyName(CS_Property property,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status);
|
||||
bool GetBooleanProperty(CS_Property property, CS_Status* status);
|
||||
void SetBooleanProperty(CS_Property property, bool value, CS_Status* status);
|
||||
double GetDoubleProperty(CS_Property property, CS_Status* status);
|
||||
void SetDoubleProperty(CS_Property property, double value, CS_Status* status);
|
||||
double GetPropertyMin(CS_Property property, CS_Status* status);
|
||||
double GetPropertyMax(CS_Property property, CS_Status* status);
|
||||
double GetPropertyStep(CS_Property property, CS_Status* status);
|
||||
double GetPropertyDefault(CS_Property property, CS_Status* status);
|
||||
int GetProperty(CS_Property property, CS_Status* status);
|
||||
void SetProperty(CS_Property property, int value, CS_Status* status);
|
||||
int GetPropertyMin(CS_Property property, CS_Status* status);
|
||||
int GetPropertyMax(CS_Property property, CS_Status* status);
|
||||
int GetPropertyStep(CS_Property property, CS_Status* status);
|
||||
int GetPropertyDefault(CS_Property property, CS_Status* status);
|
||||
std::string GetStringProperty(CS_Property property, CS_Status* status);
|
||||
llvm::StringRef GetStringProperty(CS_Property property,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status);
|
||||
void SetStringProperty(CS_Property property, llvm::StringRef value,
|
||||
CS_Status* status);
|
||||
int GetEnumProperty(CS_Property property, CS_Status* status);
|
||||
void SetEnumProperty(CS_Property property, int value, CS_Status* status);
|
||||
std::vector<std::string> GetEnumPropertyChoices(CS_Property property,
|
||||
CS_Status* status);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class VideoProperty {
|
||||
enum Type {
|
||||
kNone = CS_PROP_NONE,
|
||||
kBoolean = CS_PROP_BOOLEAN,
|
||||
kDouble = CS_PROP_DOUBLE,
|
||||
kInteger = CS_PROP_INTEGER,
|
||||
kString = CS_PROP_STRING,
|
||||
kEnum = CS_PROP_ENUM
|
||||
};
|
||||
@@ -47,21 +47,16 @@ class VideoProperty {
|
||||
|
||||
// Type checkers
|
||||
bool IsBoolean() const { return m_type == kBoolean; }
|
||||
bool IsDouble() const { return m_type == kDouble; }
|
||||
bool IsInteger() const { return m_type == kInteger; }
|
||||
bool IsString() const { return m_type == kString; }
|
||||
bool IsEnum() const { return m_type == kEnum; }
|
||||
|
||||
// Boolean-specific functions
|
||||
bool GetBoolean() const;
|
||||
void SetBoolean(bool value);
|
||||
|
||||
// Double-specific functions
|
||||
double GetDouble() const;
|
||||
void SetDouble(double value);
|
||||
double GetMin() const;
|
||||
double GetMax() const;
|
||||
double GetStep() const;
|
||||
double GetDefault() const;
|
||||
int Get() const;
|
||||
void Set(int value);
|
||||
int GetMin() const;
|
||||
int GetMax() const;
|
||||
int GetStep() const;
|
||||
int GetDefault() const;
|
||||
|
||||
// String-specific functions
|
||||
std::string GetString() const;
|
||||
@@ -69,8 +64,6 @@ class VideoProperty {
|
||||
void SetString(llvm::StringRef value);
|
||||
|
||||
// Enum-specific functions
|
||||
int GetEnum() const;
|
||||
void SetEnum(int value);
|
||||
std::vector<std::string> GetChoices() const;
|
||||
|
||||
CS_Status GetLastStatus() const { return m_status; }
|
||||
|
||||
@@ -15,42 +15,32 @@ inline std::string VideoProperty::GetName() const {
|
||||
return GetPropertyName(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline bool VideoProperty::GetBoolean() const {
|
||||
inline int VideoProperty::Get() const {
|
||||
m_status = 0;
|
||||
return GetBooleanProperty(m_handle, &m_status);
|
||||
return GetProperty(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoProperty::SetBoolean(bool value) {
|
||||
inline void VideoProperty::Set(int value) {
|
||||
m_status = 0;
|
||||
SetBooleanProperty(m_handle, value, &m_status);
|
||||
SetProperty(m_handle, value, &m_status);
|
||||
}
|
||||
|
||||
inline double VideoProperty::GetDouble() const {
|
||||
m_status = 0;
|
||||
return GetDoubleProperty(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoProperty::SetDouble(double value) {
|
||||
m_status = 0;
|
||||
SetDoubleProperty(m_handle, value, &m_status);
|
||||
}
|
||||
|
||||
inline double VideoProperty::GetMin() const {
|
||||
inline int VideoProperty::GetMin() const {
|
||||
m_status = 0;
|
||||
return GetPropertyMin(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline double VideoProperty::GetMax() const {
|
||||
inline int VideoProperty::GetMax() const {
|
||||
m_status = 0;
|
||||
return GetPropertyMax(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline double VideoProperty::GetStep() const {
|
||||
inline int VideoProperty::GetStep() const {
|
||||
m_status = 0;
|
||||
return GetPropertyStep(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline double VideoProperty::GetDefault() const {
|
||||
inline int VideoProperty::GetDefault() const {
|
||||
m_status = 0;
|
||||
return GetPropertyDefault(m_handle, &m_status);
|
||||
}
|
||||
@@ -71,16 +61,6 @@ inline void VideoProperty::SetString(llvm::StringRef value) {
|
||||
SetStringProperty(m_handle, value, &m_status);
|
||||
}
|
||||
|
||||
inline int VideoProperty::GetEnum() const {
|
||||
m_status = 0;
|
||||
return GetEnumProperty(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoProperty::SetEnum(int value) {
|
||||
m_status = 0;
|
||||
SetEnumProperty(m_handle, value, &m_status);
|
||||
}
|
||||
|
||||
inline std::vector<std::string> VideoProperty::GetChoices() const {
|
||||
m_status = 0;
|
||||
return GetEnumPropertyChoices(m_handle, &m_status);
|
||||
|
||||
@@ -106,64 +106,37 @@ JNIEXPORT jstring JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyN
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getBooleanProperty
|
||||
* Signature: (I)Z
|
||||
* Method: getProperty
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getBooleanProperty
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getProperty
|
||||
(JNIEnv *env, jclass, jint property)
|
||||
{
|
||||
CS_Status status;
|
||||
auto val = cs::GetBooleanProperty(property, &status);
|
||||
auto val = cs::GetProperty(property, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: setBooleanProperty
|
||||
* Signature: (IZ)V
|
||||
* Method: setProperty
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setBooleanProperty
|
||||
(JNIEnv *env, jclass, jint property, jboolean value)
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setProperty
|
||||
(JNIEnv *env, jclass, jint property, jint value)
|
||||
{
|
||||
CS_Status status;
|
||||
cs::SetBooleanProperty(property, value, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getDoubleProperty
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getDoubleProperty
|
||||
(JNIEnv *env, jclass, jint property)
|
||||
{
|
||||
CS_Status status;
|
||||
auto val = cs::GetDoubleProperty(property, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: setDoubleProperty
|
||||
* Signature: (ID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setDoubleProperty
|
||||
(JNIEnv *env, jclass, jint property, jdouble value)
|
||||
{
|
||||
CS_Status status;
|
||||
cs::SetDoubleProperty(property, value, &status);
|
||||
cs::SetProperty(property, value, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getPropertyMin
|
||||
* Signature: (I)D
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyMin
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyMin
|
||||
(JNIEnv *env, jclass, jint property)
|
||||
{
|
||||
CS_Status status;
|
||||
@@ -175,9 +148,9 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyM
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getPropertyMax
|
||||
* Signature: (I)D
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyMax
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyMax
|
||||
(JNIEnv *env, jclass, jint property)
|
||||
{
|
||||
CS_Status status;
|
||||
@@ -189,9 +162,9 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyM
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getPropertyStep
|
||||
* Signature: (I)D
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyStep
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyStep
|
||||
(JNIEnv *env, jclass, jint property)
|
||||
{
|
||||
CS_Status status;
|
||||
@@ -203,9 +176,9 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyS
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getPropertyDefault
|
||||
* Signature: (I)D
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyDefault
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getPropertyDefault
|
||||
(JNIEnv *env, jclass, jint property)
|
||||
{
|
||||
CS_Status status;
|
||||
@@ -242,33 +215,6 @@ JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setStringProper
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getEnumProperty
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getEnumProperty
|
||||
(JNIEnv *env, jclass, jint property)
|
||||
{
|
||||
CS_Status status;
|
||||
auto val = cs::GetEnumProperty(property, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: setEnumProperty
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setEnumProperty
|
||||
(JNIEnv *env, jclass, jint property, jint value)
|
||||
{
|
||||
CS_Status status;
|
||||
cs::SetEnumProperty(property, value, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getEnumPropertyChoices
|
||||
|
||||
@@ -77,18 +77,14 @@ public class CameraServerJNI {
|
||||
//
|
||||
public static native int getPropertyType(int property);
|
||||
public static native String getPropertyName(int property);
|
||||
public static native boolean getBooleanProperty(int property);
|
||||
public static native void setBooleanProperty(int property, boolean value);
|
||||
public static native double getDoubleProperty(int property);
|
||||
public static native void setDoubleProperty(int property, double value);
|
||||
public static native double getPropertyMin(int property);
|
||||
public static native double getPropertyMax(int property);
|
||||
public static native double getPropertyStep(int property);
|
||||
public static native double getPropertyDefault(int property);
|
||||
public static native int getProperty(int property);
|
||||
public static native void setProperty(int property, int value);
|
||||
public static native int getPropertyMin(int property);
|
||||
public static native int getPropertyMax(int property);
|
||||
public static native int getPropertyStep(int property);
|
||||
public static native int getPropertyDefault(int property);
|
||||
public static native String getStringProperty(int property);
|
||||
public static native void setStringProperty(int property, String value);
|
||||
public static native int getEnumProperty(int property);
|
||||
public static native void setEnumProperty(int property, int value);
|
||||
public static native String[] getEnumPropertyChoices(int property);
|
||||
|
||||
//
|
||||
|
||||
@@ -9,7 +9,7 @@ package edu.wpi.cameraserver;
|
||||
|
||||
public class VideoProperty {
|
||||
public enum Type {
|
||||
kNone(0), kBoolean(1), kDouble(2), kString(3), kEnum(4);
|
||||
kNone(0), kBoolean(1), kInteger(2), kString(4), kEnum(8);
|
||||
private int value;
|
||||
|
||||
private Type(int value) {
|
||||
@@ -39,8 +39,8 @@ public class VideoProperty {
|
||||
return m_type == Type.kBoolean;
|
||||
}
|
||||
|
||||
public boolean isDouble() {
|
||||
return m_type == Type.kDouble;
|
||||
public boolean isInteger() {
|
||||
return m_type == Type.kInteger;
|
||||
}
|
||||
|
||||
public boolean isString() {
|
||||
@@ -51,37 +51,27 @@ public class VideoProperty {
|
||||
return m_type == Type.kEnum;
|
||||
}
|
||||
|
||||
// Boolean-specific functions
|
||||
public boolean getBoolean() {
|
||||
return CameraServerJNI.getBooleanProperty(m_handle);
|
||||
public int get() {
|
||||
return CameraServerJNI.getProperty(m_handle);
|
||||
}
|
||||
|
||||
public void setBoolean(boolean value) {
|
||||
CameraServerJNI.setBooleanProperty(m_handle, value);
|
||||
public void set(int value) {
|
||||
CameraServerJNI.setProperty(m_handle, value);
|
||||
}
|
||||
|
||||
// Double-specific functions
|
||||
public double getDouble() {
|
||||
return CameraServerJNI.getDoubleProperty(m_handle);
|
||||
}
|
||||
|
||||
public void setDouble(double value) {
|
||||
CameraServerJNI.setDoubleProperty(m_handle, value);
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
public int getMin() {
|
||||
return CameraServerJNI.getPropertyMin(m_handle);
|
||||
}
|
||||
|
||||
public double getMax() {
|
||||
public int getMax() {
|
||||
return CameraServerJNI.getPropertyMax(m_handle);
|
||||
}
|
||||
|
||||
public double getStep() {
|
||||
public int getStep() {
|
||||
return CameraServerJNI.getPropertyStep(m_handle);
|
||||
}
|
||||
|
||||
public double getDefault() {
|
||||
public int getDefault() {
|
||||
return CameraServerJNI.getPropertyDefault(m_handle);
|
||||
}
|
||||
|
||||
@@ -95,14 +85,6 @@ public class VideoProperty {
|
||||
}
|
||||
|
||||
// Enum-specific functions
|
||||
public int getEnum() {
|
||||
return CameraServerJNI.getEnumProperty(m_handle);
|
||||
}
|
||||
|
||||
public void setEnum(int value) {
|
||||
CameraServerJNI.setEnumProperty(m_handle, value);
|
||||
}
|
||||
|
||||
public String[] getChoices() {
|
||||
return CameraServerJNI.getEnumPropertyChoices(m_handle);
|
||||
}
|
||||
|
||||
@@ -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