diff --git a/examples/enum_usb/enum_usb.cpp b/examples/enum_usb/enum_usb.cpp index 52d85e4dc8..436fc4c8cd 100644 --- a/examples/enum_usb/enum_usb.cpp +++ b/examples/enum_usb/enum_usb.cpp @@ -15,7 +15,7 @@ int main() { llvm::outs() << "Properties:\n"; for (const auto& prop : camera.EnumerateProperties()) { llvm::outs() << " " << prop.GetName() << ": "; - switch (prop.GetType()) { + switch (prop.GetKind()) { case cs::VideoProperty::kBoolean: llvm::outs() << "value=" << prop.Get() << " default=" << prop.GetDefault(); diff --git a/include/cscore_c.h b/include/cscore_c.h index 4169c9bed4..f7c8d620ac 100644 --- a/include/cscore_c.h +++ b/include/cscore_c.h @@ -75,9 +75,9 @@ typedef struct CS_VideoMode { } CS_VideoMode; // -// Property types +// Property kinds // -enum CS_PropertyType { +enum CS_PropertyKind { CS_PROP_NONE = 0, CS_PROP_BOOLEAN = 1, CS_PROP_INTEGER = 2, @@ -86,9 +86,9 @@ enum CS_PropertyType { }; // -// Source types +// Source kinds // -enum CS_SourceType { +enum CS_SourceKind { CS_SOURCE_UNKNOWN = 0, CS_SOURCE_USB = 1, CS_SOURCE_HTTP = 2, @@ -96,18 +96,18 @@ enum CS_SourceType { }; // -// Sink types +// Sink kinds // -enum CS_SinkType { +enum CS_SinkKind { CS_SINK_UNKNOWN = 0, CS_SINK_MJPEG = 2, CS_SINK_CV = 4 }; // -// Listener event types +// Listener event kinds // -enum CS_EventType { +enum CS_EventKind { CS_SOURCE_CREATED = 0x0001, CS_SOURCE_DESTROYED = 0x0002, CS_SOURCE_CONNECTED = 0x0004, @@ -128,7 +128,7 @@ enum CS_EventType { // Listener event // struct CS_Event { - CS_EventType type; + CS_EventKind kind; // Valid for CS_SOURCE_* and CS_SINK_* respectively CS_Source source; @@ -142,7 +142,7 @@ struct CS_Event { // Fields for CS_SOURCE_PROPERTY_* events CS_Property property; - CS_PropertyType propertyType; + CS_PropertyKind propertyKind; int value; const char* valueStr; }; @@ -150,7 +150,7 @@ struct CS_Event { // // Property Functions // -enum CS_PropertyType CS_GetPropertyType(CS_Property property, +enum CS_PropertyKind CS_GetPropertyKind(CS_Property property, CS_Status* status); char* CS_GetPropertyName(CS_Property property, CS_Status* status); int CS_GetProperty(CS_Property property, CS_Status* status); @@ -179,7 +179,7 @@ CS_Source CS_CreateCvSource(const char* name, const CS_VideoMode* mode, // // Source Functions // -CS_SourceType CS_GetSourceType(CS_Source source, CS_Status* status); +CS_SourceKind CS_GetSourceKind(CS_Source source, CS_Status* status); char* CS_GetSourceName(CS_Source source, CS_Status* status); char* CS_GetSourceDescription(CS_Source source, CS_Status* status); uint64_t CS_GetSourceLastFrameTime(CS_Source source, CS_Status* status); @@ -220,7 +220,7 @@ void CS_SetSourceConnected(CS_Source source, CS_Bool connected, void CS_SetSourceDescription(CS_Source source, const char* description, CS_Status* status); CS_Property CS_CreateSourceProperty(CS_Source source, const char* name, - enum CS_PropertyType type, int minimum, + enum CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, CS_Status* status); void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, @@ -240,7 +240,7 @@ CS_Sink CS_CreateCvSinkCallback(const char* name, void* data, // // Sink Functions // -CS_SinkType CS_GetSinkType(CS_Sink sink, CS_Status* status); +CS_SinkKind CS_GetSinkKind(CS_Sink sink, CS_Status* status); char* CS_GetSinkName(CS_Sink sink, CS_Status* status); char* CS_GetSinkDescription(CS_Sink sink, CS_Status* status); void CS_SetSinkSource(CS_Sink sink, CS_Source source, CS_Status* status); diff --git a/include/cscore_cpp.h b/include/cscore_cpp.h index ded67268c9..f301cb3d3c 100644 --- a/include/cscore_cpp.h +++ b/include/cscore_cpp.h @@ -67,7 +67,7 @@ struct VideoMode : public CS_VideoMode { /// Listener event struct RawEvent { - enum Type { + enum Kind { kSourceCreated = CS_SOURCE_CREATED, kSourceDestroyed = CS_SOURCE_DESTROYED, kSourceConnected = CS_SOURCE_CONNECTED, @@ -85,31 +85,31 @@ struct RawEvent { }; RawEvent() = default; - RawEvent(llvm::StringRef name_, CS_Handle handle_, RawEvent::Type type_) - : type{type_}, name{name_} { - if (type_ == kSinkCreated || type_ == kSinkDestroyed || - type_ == kSinkEnabled || type_ == kSinkDisabled) + RawEvent(llvm::StringRef name_, CS_Handle handle_, RawEvent::Kind kind_) + : kind{kind_}, name{name_} { + if (kind_ == kSinkCreated || kind_ == kSinkDestroyed || + kind_ == kSinkEnabled || kind_ == kSinkDisabled) sinkHandle = handle_; else sourceHandle = handle_; } RawEvent(llvm::StringRef name_, CS_Source source_, const VideoMode& mode_) - : type{kSourceVideoModeChanged}, + : kind{kSourceVideoModeChanged}, sourceHandle{source_}, name{name_}, mode{mode_} {} - RawEvent(llvm::StringRef name_, CS_Source source_, RawEvent::Type type_, - CS_Property property_, CS_PropertyType propertyType_, int value_, + RawEvent(llvm::StringRef name_, CS_Source source_, RawEvent::Kind kind_, + CS_Property property_, CS_PropertyKind propertyKind_, int value_, llvm::StringRef valueStr_) - : type{type_}, + : kind{kind_}, sourceHandle{source_}, name{name_}, propertyHandle{property_}, - propertyType{propertyType_}, + propertyKind{propertyKind_}, value{value_}, valueStr{valueStr_} {} - Type type; + Kind kind; // Valid for kSource* and kSink* respectively CS_Source sourceHandle = CS_INVALID_HANDLE; @@ -123,7 +123,7 @@ struct RawEvent { // Fields for kSourceProperty* events CS_Property propertyHandle; - CS_PropertyType propertyType; + CS_PropertyKind propertyKind; int value; std::string valueStr; }; @@ -131,7 +131,7 @@ struct RawEvent { // // Property Functions // -CS_PropertyType GetPropertyType(CS_Property property, CS_Status* status); +CS_PropertyKind GetPropertyKind(CS_Property property, CS_Status* status); std::string GetPropertyName(CS_Property property, CS_Status* status); llvm::StringRef GetPropertyName(CS_Property property, llvm::SmallVectorImpl& buf, @@ -165,7 +165,7 @@ CS_Source CreateCvSource(llvm::StringRef name, const VideoMode& mode, // // Source Functions // -CS_SourceType GetSourceType(CS_Source source, CS_Status* status); +CS_SourceKind GetSourceKind(CS_Source source, CS_Status* status); std::string GetSourceName(CS_Source source, CS_Status* status); llvm::StringRef GetSourceName(CS_Source source, llvm::SmallVectorImpl& buf, @@ -206,7 +206,7 @@ void SetSourceConnected(CS_Source source, bool connected, CS_Status* status); void SetSourceDescription(CS_Source source, llvm::StringRef description, CS_Status* status); CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name, - CS_PropertyType type, int minimum, int maximum, + CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, CS_Status* status); void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, @@ -226,7 +226,7 @@ CS_Sink CreateCvSinkCallback(llvm::StringRef name, // // Sink Functions // -CS_SinkType GetSinkType(CS_Sink sink, CS_Status* status); +CS_SinkKind GetSinkKind(CS_Sink sink, CS_Status* status); std::string GetSinkName(CS_Sink sink, CS_Status* status); llvm::StringRef GetSinkName(CS_Sink sink, llvm::SmallVectorImpl& buf, CS_Status* status); diff --git a/include/cscore_oo.h b/include/cscore_oo.h index c14b44a95b..71c7b66a99 100644 --- a/include/cscore_oo.h +++ b/include/cscore_oo.h @@ -29,7 +29,7 @@ class VideoProperty { friend class VideoSource; public: - enum Type { + enum Kind { kNone = CS_PROP_NONE, kBoolean = CS_PROP_BOOLEAN, kInteger = CS_PROP_INTEGER, @@ -37,19 +37,19 @@ class VideoProperty { kEnum = CS_PROP_ENUM }; - VideoProperty() : m_handle(0), m_type(kNone) {} + VideoProperty() : m_handle(0), m_kind(kNone) {} std::string GetName() const; - Type GetType() const { return m_type; } + Kind GetKind() const { return m_kind; } - explicit operator bool() const { return m_type != kNone; } + explicit operator bool() const { return m_kind != kNone; } - // Type checkers - bool IsBoolean() const { return m_type == kBoolean; } - bool IsInteger() const { return m_type == kInteger; } - bool IsString() const { return m_type == kString; } - bool IsEnum() const { return m_type == kEnum; } + // Kind checkers + bool IsBoolean() const { return m_kind == kBoolean; } + bool IsInteger() const { return m_kind == kInteger; } + bool IsString() const { return m_kind == kString; } + bool IsEnum() const { return m_kind == kEnum; } int Get() const; void Set(int value); @@ -70,11 +70,11 @@ class VideoProperty { private: explicit VideoProperty(CS_Property handle); - VideoProperty(CS_Property handle, Type type); + VideoProperty(CS_Property handle, Kind kind); mutable CS_Status m_status; CS_Property m_handle; - Type m_type; + Kind m_kind; }; /// A source for video that provides a sequence of frames. @@ -83,7 +83,7 @@ class VideoSource { friend class VideoSink; public: - enum Type { + enum Kind { kUnknown = CS_SOURCE_UNKNOWN, kUSB = CS_SOURCE_USB, kHTTP = CS_SOURCE_HTTP, @@ -106,14 +106,14 @@ class VideoSource { bool operator!=(const VideoSource& other) const { return !(*this == other); } - /// Get the type of the source. - Type GetType() const; + /// Get the kind of the source. + Kind GetKind() const; /// Get the name of the source. The name is an arbitrary identifier /// provided when the source is created, and should be unique. std::string GetName() const; - /// Get the source description. This is source-type specific. + /// Get the source description. This is source-kind specific. std::string GetDescription() const; /// Get the last time a frame was captured. @@ -124,7 +124,7 @@ class VideoSource { /// Get a property. /// @param name Property name - /// @return Property contents (of type Property::kNone if no property with + /// @return Property contents (of kind Property::kNone if no property with /// the given name exists) VideoProperty GetProperty(llvm::StringRef name); @@ -253,14 +253,14 @@ class CvSource : public VideoSource { /// Create a property. /// @param name Property name - /// @param type Property type + /// @param kind Property kind /// @param minimum Minimum value /// @param maximum Maximum value /// @param step Step value /// @param defaultValue Default value /// @param value Current value /// @return Property - VideoProperty CreateProperty(llvm::StringRef name, VideoProperty::Type type, + VideoProperty CreateProperty(llvm::StringRef name, VideoProperty::Kind kind, int minimum, int maximum, int step, int defaultValue, int value); @@ -277,7 +277,7 @@ class VideoSink { friend class VideoSource; public: - enum Type { + enum Kind { kUnknown = CS_SINK_UNKNOWN, kMJPEG = CS_SINK_MJPEG, kCv = CS_SINK_CV @@ -299,14 +299,14 @@ class VideoSink { bool operator!=(const VideoSink& other) const { return !(*this == other); } - /// Get the type of the sink. - Type GetType() const; + /// Get the kind of the sink. + Kind GetKind() const; /// Get the name of the sink. The name is an arbitrary identifier /// provided when the sink is created, and should be unique. std::string GetName() const; - /// Get the sink description. This is sink-type specific. + /// Get the sink description. This is sink-kind specific. std::string GetDescription() const; /// Configure which source should provide frames to this sink. Each sink @@ -321,7 +321,7 @@ class VideoSink { /// Get a property of the associated source. /// @param name Property name - /// @return Property (type Property::kNone if no property with + /// @return Property (kind Property::kNone if no property with /// the given name exists or no source connected) VideoProperty GetSourceProperty(llvm::StringRef name); @@ -419,7 +419,7 @@ class VideoListener { /// Create an event listener. /// @param callback Callback function - /// @param eventMask Bitmask of VideoEvent::Type values + /// @param eventMask Bitmask of VideoEvent::Kind values /// @param immediateNotify Whether callback should be immediately called with /// a representative set of events for the current library state. VideoListener(std::function callback, diff --git a/include/cscore_oo.inl b/include/cscore_oo.inl index b3c52e125a..1a40bfd0c8 100644 --- a/include/cscore_oo.inl +++ b/include/cscore_oo.inl @@ -69,10 +69,10 @@ inline std::vector VideoProperty::GetChoices() const { inline VideoProperty::VideoProperty(CS_Property handle) : m_handle(handle) { m_status = 0; if (handle == 0) - m_type = kNone; + m_kind = kNone; else - m_type = - static_cast(static_cast(GetPropertyType(handle, &m_status))); + m_kind = + static_cast(static_cast(GetPropertyKind(handle, &m_status))); } inline VideoSource::VideoSource(const VideoSource& source) @@ -93,9 +93,9 @@ inline VideoSource::~VideoSource() { if (m_handle != 0) ReleaseSource(m_handle, &m_status); } -inline VideoSource::Type VideoSource::GetType() const { +inline VideoSource::Kind VideoSource::GetKind() const { m_status = 0; - return static_cast(GetSourceType(m_handle, &m_status)); + return static_cast(GetSourceKind(m_handle, &m_status)); } inline std::string VideoSource::GetName() const { @@ -208,13 +208,13 @@ inline void CvSource::SetDescription(llvm::StringRef description) { } inline VideoProperty CvSource::CreateProperty(llvm::StringRef name, - VideoProperty::Type type, + VideoProperty::Kind kind, int minimum, int maximum, int step, int defaultValue, int value) { m_status = 0; return VideoProperty{CreateSourceProperty( - m_handle, name, static_cast(static_cast(type)), + m_handle, name, static_cast(static_cast(kind)), minimum, maximum, step, defaultValue, value, &m_status)}; } @@ -241,9 +241,9 @@ inline VideoSink::~VideoSink() { if (m_handle != 0) ReleaseSink(m_handle, &m_status); } -inline VideoSink::Type VideoSink::GetType() const { +inline VideoSink::Kind VideoSink::GetKind() const { m_status = 0; - return static_cast(GetSinkType(m_handle, &m_status)); + return static_cast(GetSinkKind(m_handle, &m_status)); } inline std::string VideoSink::GetName() const { @@ -320,7 +320,7 @@ inline VideoSink VideoEvent::GetSink() const { inline VideoProperty VideoEvent::GetProperty() const { return VideoProperty{propertyHandle, - static_cast(propertyType)}; + static_cast(propertyKind)}; } inline VideoListener::VideoListener( diff --git a/java/lib/CameraServerJNI.cpp b/java/lib/CameraServerJNI.cpp index e9065ef906..267155b108 100644 --- a/java/lib/CameraServerJNI.cpp +++ b/java/lib/CameraServerJNI.cpp @@ -164,7 +164,7 @@ static jobject MakeJObject(JNIEnv *env, const cs::RawEvent &event) { return env->NewObject( videoEventCls, constructor, - static_cast(event.type), + static_cast(event.kind), static_cast(event.sourceHandle), static_cast(event.sinkHandle), name.obj(), @@ -173,7 +173,7 @@ static jobject MakeJObject(JNIEnv *env, const cs::RawEvent &event) { static_cast(event.mode.height), static_cast(event.mode.fps), static_cast(event.propertyHandle), - static_cast(event.propertyType), + static_cast(event.propertyKind), static_cast(event.value), valueStr.obj()); } @@ -182,14 +182,14 @@ extern "C" { /* * Class: edu_wpi_cscore_CameraServerJNI - * Method: getPropertyType + * Method: getPropertyKind * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getPropertyType +JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getPropertyKind (JNIEnv *env, jclass, jint property) { CS_Status status = 0; - auto val = cs::GetPropertyType(property, &status); + auto val = cs::GetPropertyKind(property, &status); CheckStatus(env, status); return val; } @@ -400,14 +400,14 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createCvSource /* * Class: edu_wpi_cscore_CameraServerJNI - * Method: getSourceType + * Method: getSourceKind * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSourceType +JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSourceKind (JNIEnv *env, jclass, jint source) { CS_Status status = 0; - auto val = cs::GetSourceType(source, &status); + auto val = cs::GetSourceKind(source, &status); CheckStatus(env, status); return val; } @@ -697,11 +697,11 @@ JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourceDescription * Signature: (ILjava/lang/String;IIIIII)I */ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createSourceProperty - (JNIEnv *env, jclass, jint source, jstring name, jint type, jint minimum, jint maximum, jint step, jint defaultValue, jint value) + (JNIEnv *env, jclass, jint source, jstring name, jint kind, jint minimum, jint maximum, jint step, jint defaultValue, jint value) { CS_Status status = 0; auto val = cs::CreateSourceProperty( - source, JStringRef{env, name}, static_cast(type), + source, JStringRef{env, name}, static_cast(kind), minimum, maximum, step, defaultValue, value, &status); CheckStatus(env, status); return val; @@ -763,14 +763,14 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createCvSink /* * Class: edu_wpi_cscore_CameraServerJNI - * Method: getSinkType + * Method: getSinkKind * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSinkType +JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSinkKind (JNIEnv *env, jclass, jint sink) { CS_Status status = 0; - auto val = cs::GetSinkType(sink, &status); + auto val = cs::GetSinkKind(sink, &status); CheckStatus(env, status); return val; } diff --git a/java/src/edu/wpi/cscore/CameraServerJNI.java b/java/src/edu/wpi/cscore/CameraServerJNI.java index 1a717506f2..4625e02b52 100644 --- a/java/src/edu/wpi/cscore/CameraServerJNI.java +++ b/java/src/edu/wpi/cscore/CameraServerJNI.java @@ -87,7 +87,7 @@ public class CameraServerJNI { // // Property Functions // - public static native int getPropertyType(int property); + public static native int getPropertyKind(int property); public static native String getPropertyName(int property); public static native int getProperty(int property); public static native void setProperty(int property, int value); @@ -110,7 +110,7 @@ public class CameraServerJNI { // // Source Functions // - public static native int getSourceType(int source); + public static native int getSourceKind(int source); public static native String getSourceName(int source); public static native String getSourceDescription(int source); public static native long getSourceLastFrameTime(int source); @@ -134,7 +134,7 @@ public class CameraServerJNI { public static native void notifySourceError(int source, String msg); public static native void setSourceConnected(int source, boolean connected); public static native void setSourceDescription(int source, String description); - public static native int createSourceProperty(int source, String name, int type, int minimum, int maximum, int step, int defaultValue, int value); + public static native int createSourceProperty(int source, String name, int kind, int minimum, int maximum, int step, int defaultValue, int value); public static native void setSourceEnumPropertyChoices(int source, int property, String[] choices); // @@ -148,7 +148,7 @@ public class CameraServerJNI { // // Sink Functions // - public static native int getSinkType(int sink); + public static native int getSinkKind(int sink); public static native String getSinkName(int sink); public static native String getSinkDescription(int sink); public static native void setSinkSource(int sink, int source); diff --git a/java/src/edu/wpi/cscore/CvSource.java b/java/src/edu/wpi/cscore/CvSource.java index 6334104d35..9cb5f07d92 100644 --- a/java/src/edu/wpi/cscore/CvSource.java +++ b/java/src/edu/wpi/cscore/CvSource.java @@ -54,21 +54,21 @@ public class CvSource extends VideoSource { /// Create a property. /// @param name Property name - /// @param type Property type + /// @param kind Property kind /// @param minimum Minimum value /// @param maximum Maximum value /// @param step Step value /// @param defaultValue Default value /// @param value Current value /// @return Property - public VideoProperty createProperty(String name, VideoProperty.Type type, int minimum, int maximum, int step, int defaultValue, int value) { + public VideoProperty createProperty(String name, VideoProperty.Kind kind, int minimum, int maximum, int step, int defaultValue, int value) { return new VideoProperty( - CameraServerJNI.createSourceProperty(m_handle, name, type.getValue(), minimum, maximum, step, defaultValue, value)); + CameraServerJNI.createSourceProperty(m_handle, name, kind.getValue(), minimum, maximum, step, defaultValue, value)); } /// Create a property with a change callback. /// @param name Property name - /// @param type Property type + /// @param kind Property kind /// @param minimum Minimum value /// @param maximum Maximum value /// @param step Step value @@ -77,7 +77,7 @@ public class CvSource extends VideoSource { /// @param onChange Callback to call when the property value changes /// @return Property //public VideoProperty createProperty( - // String name, VideoProperty.Type type, int minimum, int maximum, int step, int defaultValue, int value, + // String name, VideoProperty.Kind kind, int minimum, int maximum, int step, int defaultValue, int value, // std::function // onChange); diff --git a/java/src/edu/wpi/cscore/VideoEvent.java b/java/src/edu/wpi/cscore/VideoEvent.java index cc30d4f566..8239171bfb 100644 --- a/java/src/edu/wpi/cscore/VideoEvent.java +++ b/java/src/edu/wpi/cscore/VideoEvent.java @@ -9,7 +9,7 @@ package edu.wpi.cscore; /// Video event public class VideoEvent { - public enum Type { + public enum Kind { kSourceCreated(0x0001), kSourceDestroyed(0x0002), kSourceConnected(0x0004), @@ -27,7 +27,7 @@ public class VideoEvent { private int value; - private Type(int value) { + private Kind(int value) { this.value = value; } @@ -35,23 +35,23 @@ public class VideoEvent { return value; } } - private static final Type[] m_typeValues = Type.values(); + private static final Kind[] m_kindValues = Kind.values(); - VideoEvent(int type, int source, int sink, String name, int pixelFormat, - int width, int height, int fps, int property, int propertyType, + VideoEvent(int kind, int source, int sink, String name, int pixelFormat, + int width, int height, int fps, int property, int propertyKind, int value, String valueStr) { - this.type = m_typeValues[type]; + this.kind = m_kindValues[kind]; this.sourceHandle = source; this.sinkHandle = sink; this.name = name; this.mode = new VideoMode(pixelFormat, width, height, fps); this.propertyHandle = property; - this.propertyType = VideoProperty.m_typeValues[propertyType]; + this.propertyKind = VideoProperty.m_kindValues[propertyKind]; this.value = value; this.valueStr = valueStr; } - public Type type; + public Kind kind; // Valid for kSource* and kSink* respectively private int sourceHandle; @@ -65,7 +65,7 @@ public class VideoEvent { // Fields for kSourceProperty* events private int propertyHandle; - public VideoProperty.Type propertyType; + public VideoProperty.Kind propertyKind; public int value; public String valueStr; @@ -78,7 +78,7 @@ public class VideoEvent { } public VideoProperty getProperty() { - return new VideoProperty(propertyHandle, propertyType); + return new VideoProperty(propertyHandle, propertyKind); } } diff --git a/java/src/edu/wpi/cscore/VideoProperty.java b/java/src/edu/wpi/cscore/VideoProperty.java index 40533fa9b7..096f7abdc3 100644 --- a/java/src/edu/wpi/cscore/VideoProperty.java +++ b/java/src/edu/wpi/cscore/VideoProperty.java @@ -8,11 +8,11 @@ package edu.wpi.cscore; public class VideoProperty { - public enum Type { + public enum Kind { kNone(0), kBoolean(1), kInteger(2), kString(4), kEnum(8); private int value; - private Type(int value) { + private Kind(int value) { this.value = value; } @@ -20,35 +20,35 @@ public class VideoProperty { return value; } } - static final Type[] m_typeValues = Type.values(); + static final Kind[] m_kindValues = Kind.values(); public String getName() { return CameraServerJNI.getPropertyName(m_handle); } - public Type getType() { - return m_type; + public Kind getKind() { + return m_kind; } public boolean isValid() { - return m_type != Type.kNone; + return m_kind != Kind.kNone; } - // Type checkers + // Kind checkers public boolean isBoolean() { - return m_type == Type.kBoolean; + return m_kind == Kind.kBoolean; } public boolean isInteger() { - return m_type == Type.kInteger; + return m_kind == Kind.kInteger; } public boolean isString() { - return m_type == Type.kString; + return m_kind == Kind.kString; } public boolean isEnum() { - return m_type == Type.kEnum; + return m_kind == Kind.kEnum; } public int get() { @@ -91,14 +91,14 @@ public class VideoProperty { VideoProperty(int handle) { m_handle = handle; - m_type = m_typeValues[CameraServerJNI.getPropertyType(handle)]; + m_kind = m_kindValues[CameraServerJNI.getPropertyKind(handle)]; } - VideoProperty(int handle, Type type) { + VideoProperty(int handle, Kind kind) { m_handle = handle; - m_type = type; + m_kind = kind; } int m_handle; - private Type m_type; + private Kind m_kind; } diff --git a/java/src/edu/wpi/cscore/VideoSink.java b/java/src/edu/wpi/cscore/VideoSink.java index e9d3c698d3..6fa353c868 100644 --- a/java/src/edu/wpi/cscore/VideoSink.java +++ b/java/src/edu/wpi/cscore/VideoSink.java @@ -11,11 +11,11 @@ package edu.wpi.cscore; /// consist of multiple images (e.g. from a stereo or depth camera); these /// are called channels. public class VideoSink { - public enum Type { + public enum Kind { kUnknown(0), kMJPEG(2), kCv(4); private int value; - private Type(int value) { + private Kind(int value) { this.value = value; } @@ -23,7 +23,7 @@ public class VideoSink { return value; } } - static final Type[] m_typeValues = Type.values(); + static final Kind[] m_kindValues = Kind.values(); protected VideoSink(int handle) { m_handle = handle; @@ -56,9 +56,9 @@ public class VideoSink { return m_handle; } - /// Get the type of the sink. - public Type getType() { - return m_typeValues[CameraServerJNI.getSinkType(m_handle)]; + /// Get the kind of the sink. + public Kind getKind() { + return m_kindValues[CameraServerJNI.getSinkKind(m_handle)]; } /// Get the name of the sink. The name is an arbitrary identifier @@ -67,7 +67,7 @@ public class VideoSink { return CameraServerJNI.getSinkName(m_handle); } - /// Get the sink description. This is sink-type specific. + /// Get the sink description. This is sink-kind specific. public String getDescription() { return CameraServerJNI.getSinkDescription(m_handle); } @@ -90,7 +90,7 @@ public class VideoSink { /// Get a property of the associated source. /// @param name Property name - /// @return Property (type Property::kNone if no property with + /// @return Property (kind Property::kNone if no property with /// the given name exists or no source connected) public VideoProperty getSourceProperty(String name) { return new VideoProperty( diff --git a/java/src/edu/wpi/cscore/VideoSource.java b/java/src/edu/wpi/cscore/VideoSource.java index 9bcb166f83..f8682222d9 100644 --- a/java/src/edu/wpi/cscore/VideoSource.java +++ b/java/src/edu/wpi/cscore/VideoSource.java @@ -11,11 +11,11 @@ package edu.wpi.cscore; /// consist of multiple images (e.g. from a stereo or depth camera); these /// are called channels. public class VideoSource { - public enum Type { + public enum Kind { kUnknown(0), kUSB(1), kHTTP(2), kCv(4); private int value; - private Type(int value) { + private Kind(int value) { this.value = value; } @@ -23,7 +23,7 @@ public class VideoSource { return value; } } - static final Type[] m_typeValues = Type.values(); + static final Kind[] m_kindValues = Kind.values(); protected VideoSource(int handle) { m_handle = handle; @@ -56,9 +56,9 @@ public class VideoSource { return m_handle; } - /// Get the type of the source. - public Type getType() { - return m_typeValues[CameraServerJNI.getSourceType(m_handle)]; + /// Get the kind of the source. + public Kind getKind() { + return m_kindValues[CameraServerJNI.getSourceKind(m_handle)]; } /// Get the name of the source. The name is an arbitrary identifier @@ -67,7 +67,7 @@ public class VideoSource { return CameraServerJNI.getSourceName(m_handle); } - /// Get the source description. This is source-type specific. + /// Get the source description. This is source-kind specific. public String getDescription() { return CameraServerJNI.getSourceDescription(m_handle); } @@ -84,7 +84,7 @@ public class VideoSource { /// Get a property. /// @param name Property name - /// @return Property contents (of type Property::kNone if no property with + /// @return Property contents (of kind Property::kNone if no property with /// the given name exists) public VideoProperty getProperty(String name) { return new VideoProperty(CameraServerJNI.getSourceProperty(m_handle, name)); diff --git a/src/CvSinkImpl.cpp b/src/CvSinkImpl.cpp index 4fd4315e8a..e2639fc122 100644 --- a/src/CvSinkImpl.cpp +++ b/src/CvSinkImpl.cpp @@ -110,7 +110,7 @@ CS_Sink CreateCvSinkCallback(llvm::StringRef name, void SetSinkDescription(CS_Sink sink, llvm::StringRef description, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); - if (!data || data->type != CS_SINK_CV) { + if (!data || data->kind != CS_SINK_CV) { *status = CS_INVALID_HANDLE; return; } @@ -119,7 +119,7 @@ void SetSinkDescription(CS_Sink sink, llvm::StringRef description, uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat& image, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); - if (!data || data->type != CS_SINK_CV) { + if (!data || data->kind != CS_SINK_CV) { *status = CS_INVALID_HANDLE; return 0; } @@ -128,7 +128,7 @@ uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat& image, CS_Status* status) { std::string GetSinkError(CS_Sink sink, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); - if (!data || data->type != CS_SINK_CV) { + if (!data || data->kind != CS_SINK_CV) { *status = CS_INVALID_HANDLE; return std::string{}; } @@ -138,7 +138,7 @@ std::string GetSinkError(CS_Sink sink, CS_Status* status) { llvm::StringRef GetSinkError(CS_Sink sink, llvm::SmallVectorImpl& buf, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); - if (!data || data->type != CS_SINK_CV) { + if (!data || data->kind != CS_SINK_CV) { *status = CS_INVALID_HANDLE; return llvm::StringRef{}; } @@ -147,7 +147,7 @@ llvm::StringRef GetSinkError(CS_Sink sink, llvm::SmallVectorImpl& buf, void SetSinkEnabled(CS_Sink sink, bool enabled, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); - if (!data || data->type != CS_SINK_CV) { + if (!data || data->kind != CS_SINK_CV) { *status = CS_INVALID_HANDLE; return; } diff --git a/src/CvSourceImpl.cpp b/src/CvSourceImpl.cpp index 5832ceae06..3ebde6ea0d 100644 --- a/src/CvSourceImpl.cpp +++ b/src/CvSourceImpl.cpp @@ -49,7 +49,7 @@ void CvSourceImpl::SetProperty(int property, int value, CS_Status* status) { *status = CS_INVALID_PROPERTY; return; } - if ((prop->propType & (CS_PROP_BOOLEAN | CS_PROP_INTEGER | CS_PROP_ENUM)) == + if ((prop->propKind & (CS_PROP_BOOLEAN | CS_PROP_INTEGER | CS_PROP_ENUM)) == 0) { *status = CS_WRONG_PROPERTY_TYPE; return; @@ -65,7 +65,7 @@ void CvSourceImpl::SetStringProperty(int property, llvm::StringRef value, *status = CS_INVALID_PROPERTY; return; } - if (prop->propType != CS_PROP_STRING) { + if (prop->propKind != CS_PROP_STRING) { *status = CS_WRONG_PROPERTY_TYPE; return; } @@ -106,7 +106,7 @@ void CvSourceImpl::NotifyError(llvm::StringRef msg) { void CvSourceImpl::SetConnected(bool connected) { m_connected = connected; } CS_Property CvSourceImpl::CreateProperty(llvm::StringRef name, - CS_PropertyType type, int minimum, + CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value) { std::unique_lock lock(m_mutex); @@ -115,11 +115,11 @@ CS_Property CvSourceImpl::CreateProperty(llvm::StringRef name, // create a new index ndx = m_propertyData.size() + 1; m_propertyData.emplace_back(llvm::make_unique( - name, type, minimum, maximum, step, defaultValue, value)); + name, kind, minimum, maximum, step, defaultValue, value)); } else { // update all but value auto prop = GetProperty(ndx); - prop->propType = type; + prop->propKind = kind; prop->minimum = minimum; prop->maximum = maximum; prop->step = step; @@ -129,7 +129,7 @@ CS_Property CvSourceImpl::CreateProperty(llvm::StringRef name, } CS_Property CvSourceImpl::CreateProperty( - llvm::StringRef name, CS_PropertyType type, int minimum, int maximum, + llvm::StringRef name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, std::function onChange) { // TODO @@ -145,7 +145,7 @@ void CvSourceImpl::SetEnumPropertyChoices(CS_Property property, *status = CS_INVALID_PROPERTY; return; } - if (prop->propType != CS_PROP_ENUM) { + if (prop->propKind != CS_PROP_ENUM) { *status = CS_WRONG_PROPERTY_TYPE; return; } @@ -162,7 +162,7 @@ CS_Source CreateCvSource(llvm::StringRef name, const VideoMode& mode, void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status) { auto data = Sources::GetInstance().Get(source); - if (!data || data->type != CS_SOURCE_CV) { + if (!data || data->kind != CS_SOURCE_CV) { *status = CS_INVALID_HANDLE; return; } @@ -172,7 +172,7 @@ void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status) { void NotifySourceError(CS_Source source, llvm::StringRef msg, CS_Status* status) { auto data = Sources::GetInstance().Get(source); - if (!data || data->type != CS_SOURCE_CV) { + if (!data || data->kind != CS_SOURCE_CV) { *status = CS_INVALID_HANDLE; return; } @@ -181,7 +181,7 @@ void NotifySourceError(CS_Source source, llvm::StringRef msg, void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) { auto data = Sources::GetInstance().Get(source); - if (!data || data->type != CS_SOURCE_CV) { + if (!data || data->kind != CS_SOURCE_CV) { *status = CS_INVALID_HANDLE; return; } @@ -191,7 +191,7 @@ void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) { void SetSourceDescription(CS_Source source, llvm::StringRef description, CS_Status* status) { auto data = Sources::GetInstance().Get(source); - if (!data || data->type != CS_SOURCE_CV) { + if (!data || data->kind != CS_SOURCE_CV) { *status = CS_INVALID_HANDLE; return; } @@ -199,29 +199,29 @@ void SetSourceDescription(CS_Source source, llvm::StringRef description, } CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name, - CS_PropertyType type, int minimum, int maximum, + CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, CS_Status* status) { auto data = Sources::GetInstance().Get(source); - if (!data || data->type != CS_SOURCE_CV) { + if (!data || data->kind != CS_SOURCE_CV) { *status = CS_INVALID_HANDLE; return -1; } return static_cast(*data->source) - .CreateProperty(name, type, minimum, maximum, step, defaultValue, value); + .CreateProperty(name, kind, minimum, maximum, step, defaultValue, value); } CS_Property CreateSourcePropertyCallback( - CS_Source source, llvm::StringRef name, CS_PropertyType type, int minimum, + CS_Source source, llvm::StringRef name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, std::function onChange, CS_Status* status) { auto data = Sources::GetInstance().Get(source); - if (!data || data->type != CS_SOURCE_CV) { + if (!data || data->kind != CS_SOURCE_CV) { *status = CS_INVALID_HANDLE; return -1; } return static_cast(*data->source) - .CreateProperty(name, type, minimum, maximum, step, defaultValue, value, + .CreateProperty(name, kind, minimum, maximum, step, defaultValue, value, onChange); } @@ -229,7 +229,7 @@ void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, llvm::ArrayRef choices, CS_Status* status) { auto data = Sources::GetInstance().Get(source); - if (!data || data->type != CS_SOURCE_CV) { + if (!data || data->kind != CS_SOURCE_CV) { *status = CS_INVALID_HANDLE; return; } @@ -269,19 +269,19 @@ void CS_SetSourceDescription(CS_Source source, const char* description, } CS_Property CS_CreateSourceProperty(CS_Source source, const char* name, - enum CS_PropertyType type, int minimum, + enum CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, CS_Status* status) { - return cs::CreateSourceProperty(source, name, type, minimum, maximum, step, + return cs::CreateSourceProperty(source, name, kind, minimum, maximum, step, defaultValue, value, status); } CS_Property CS_CreateSourcePropertyCallback( - CS_Source source, const char* name, enum CS_PropertyType type, int minimum, + CS_Source source, const char* name, enum CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, void* data, void (*onChange)(void* data, CS_Property property), CS_Status* status) { return cs::CreateSourcePropertyCallback( - source, name, type, minimum, maximum, step, defaultValue, value, + source, name, kind, minimum, maximum, step, defaultValue, value, [=](CS_Property property) { onChange(data, property); }, status); } diff --git a/src/CvSourceImpl.h b/src/CvSourceImpl.h index bb64a0809b..1bff13f246 100644 --- a/src/CvSourceImpl.h +++ b/src/CvSourceImpl.h @@ -37,11 +37,11 @@ class CvSourceImpl : public SourceImpl { void PutFrame(cv::Mat& image); void NotifyError(llvm::StringRef msg); void SetConnected(bool connected); - CS_Property CreateProperty(llvm::StringRef name, CS_PropertyType type, + CS_Property CreateProperty(llvm::StringRef name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value); CS_Property CreateProperty( - llvm::StringRef name, CS_PropertyType type, int minimum, int maximum, + llvm::StringRef name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, std::function onChange); void SetEnumPropertyChoices(CS_Property property, @@ -54,9 +54,9 @@ class CvSourceImpl : public SourceImpl { class PropertyData : public PropertyBase { public: PropertyData() = default; - PropertyData(llvm::StringRef name_, CS_PropertyType type_, int minimum_, + PropertyData(llvm::StringRef name_, CS_PropertyKind kind_, int minimum_, int maximum_, int step_, int defaultValue_, int value_) - : PropertyBase{name_, type_, minimum_, maximum_, + : PropertyBase{name_, kind_, minimum_, maximum_, step_, defaultValue_, value_} {} ~PropertyData() override = default; diff --git a/src/Handle.h b/src/Handle.h index fe50b8af2b..5d2149bc7e 100644 --- a/src/Handle.h +++ b/src/Handle.h @@ -71,10 +71,10 @@ class Handle { }; struct SourceData { - SourceData(CS_SourceType type_, std::shared_ptr source_) - : type{type_}, refCount{0}, source{source_} {} + SourceData(CS_SourceKind kind_, std::shared_ptr source_) + : kind{kind_}, refCount{0}, source{source_} {} - CS_SourceType type; + CS_SourceKind kind; std::atomic_int refCount; std::shared_ptr source; }; @@ -83,10 +83,10 @@ typedef StaticUnlimitedHandleResource Sources; struct SinkData { - explicit SinkData(CS_SinkType type_, std::shared_ptr sink_) - : type{type_}, refCount{0}, sourceHandle{0}, sink{sink_} {} + explicit SinkData(CS_SinkKind kind_, std::shared_ptr sink_) + : kind{kind_}, refCount{0}, sourceHandle{0}, sink{sink_} {} - CS_SinkType type; + CS_SinkKind kind; std::atomic_int refCount; std::atomic sourceHandle; std::shared_ptr sink; diff --git a/src/MJPEGServerImpl.cpp b/src/MJPEGServerImpl.cpp index 426d45b5a2..69cc3a004a 100644 --- a/src/MJPEGServerImpl.cpp +++ b/src/MJPEGServerImpl.cpp @@ -295,8 +295,8 @@ bool MJPEGServerImpl::ConnThread::ProcessCommand(llvm::raw_ostream& os, } CS_Status status = 0; - auto type = source.GetPropertyType(prop); - switch (type) { + auto kind = source.GetPropertyKind(prop); + switch (kind) { case CS_PROP_BOOLEAN: case CS_PROP_INTEGER: case CS_PROP_ENUM: { @@ -349,17 +349,17 @@ void MJPEGServerImpl::ConnThread::SendJSON(llvm::raw_ostream& os, os << "{"; llvm::SmallString<128> name_buf; auto name = source.GetPropertyName(prop, name_buf, &status); - auto type = source.GetPropertyType(prop); + auto kind = source.GetPropertyKind(prop); os << "\n\"name\": \"" << name << '"'; os << ",\n\"id\": \"" << prop << '"'; - os << ",\n\"type\": \"" << type << '"'; + os << ",\n\"type\": \"" << kind << '"'; os << ",\n\"min\": \"" << source.GetPropertyMin(prop, &status) << '"'; os << ",\n\"max\": \"" << source.GetPropertyMax(prop, &status) << '"'; os << ",\n\"step\": \"" << source.GetPropertyStep(prop, &status) << '"'; os << ",\n\"default\": \"" << source.GetPropertyDefault(prop, &status) << '"'; os << ",\n\"value\": \""; - switch (type) { + switch (kind) { case CS_PROP_BOOLEAN: case CS_PROP_INTEGER: case CS_PROP_ENUM: @@ -379,7 +379,7 @@ void MJPEGServerImpl::ConnThread::SendJSON(llvm::raw_ostream& os, // os << ",\n\"group\": \"" << param->group << '"'; // append the menu object to the menu typecontrols - if (source.GetPropertyType(prop) == CS_PROP_ENUM) { + if (source.GetPropertyKind(prop) == CS_PROP_ENUM) { os << ",\n\"menu\": {"; auto choices = source.GetEnumPropertyChoices(prop, &status); int j = 0; @@ -535,27 +535,27 @@ void MJPEGServerImpl::ConnThread::ProcessRequest() { return; } - enum { kCommand, kStream, kGetSettings } type; + enum { kCommand, kStream, kGetSettings } kind; llvm::StringRef parameters; size_t pos; - // Determine request type. Most of these are for mjpgstreamer + // Determine request kind. Most of these are for mjpgstreamer // compatibility. if ((pos = buf.find("POST /stream")) != llvm::StringRef::npos) { - type = kStream; + kind = kStream; parameters = buf.substr(buf.find('?', pos + 12)).substr(1); } else if ((pos = buf.find("GET /?action=stream")) != llvm::StringRef::npos) { - type = kStream; + kind = kStream; parameters = buf.substr(buf.find('&', pos + 19)).substr(1); } else if (buf.find("GET /input") != llvm::StringRef::npos && buf.find(".json") != llvm::StringRef::npos) { - type = kGetSettings; + kind = kGetSettings; } else if (buf.find("GET /output") != llvm::StringRef::npos && buf.find(".json") != llvm::StringRef::npos) { - type = kGetSettings; + kind = kGetSettings; } else if ((pos = buf.find("GET /?action=command")) != llvm::StringRef::npos) { - type = kCommand; + kind = kCommand; parameters = buf.substr(buf.find('&', pos + 20)).substr(1); } else { DEBUG("HTTP request resource not found"); @@ -578,7 +578,7 @@ void MJPEGServerImpl::ConnThread::ProcessRequest() { } while (!buf2.startswith("\r\n")); // Send response - switch (type) { + switch (kind) { case kStream: if (auto source = GetSource()) { DEBUG("request for stream " << source->GetName()); diff --git a/src/Notifier.cpp b/src/Notifier.cpp index 09ceed7b21..52985c1839 100644 --- a/src/Notifier.cpp +++ b/src/Notifier.cpp @@ -120,7 +120,7 @@ void Notifier::Thread::Main() { if (!m_listeners[i]) continue; // removed // Event type must be within requested set for this listener. - if ((item.type & m_listeners[i].eventMask) == 0) continue; + if ((item.kind & m_listeners[i].eventMask) == 0) continue; // make a copy of the callback so we can safely release the mutex auto callback = m_listeners[i].callback; @@ -151,10 +151,10 @@ void Notifier::RemoveListener(int uid) { } void Notifier::NotifySource(llvm::StringRef name, CS_Source source, - RawEvent::Type type) { + RawEvent::Kind kind) { auto thr = m_owner.GetThread(); if (!thr) return; - thr->m_notifications.emplace(name, source, type); + thr->m_notifications.emplace(name, source, kind); thr->m_cond.notify_one(); } @@ -167,21 +167,21 @@ void Notifier::NotifySourceVideoMode(llvm::StringRef name, CS_Source source, } void Notifier::NotifySourceProperty(llvm::StringRef name, CS_Source source, - RawEvent::Type type, int property, - CS_PropertyType propertyType, int value, + RawEvent::Kind kind, int property, + CS_PropertyKind propertyKind, int value, llvm::StringRef valueStr) { auto thr = m_owner.GetThread(); if (!thr) return; - thr->m_notifications.emplace(name, source, type, + thr->m_notifications.emplace(name, source, kind, Handle{source, property, Handle::kProperty}, - propertyType, value, valueStr); + propertyKind, value, valueStr); thr->m_cond.notify_one(); } void Notifier::NotifySink(llvm::StringRef name, CS_Sink sink, - RawEvent::Type type) { + RawEvent::Kind kind) { auto thr = m_owner.GetThread(); if (!thr) return; - thr->m_notifications.emplace(name, sink, type); + thr->m_notifications.emplace(name, sink, kind); thr->m_cond.notify_one(); } diff --git a/src/Notifier.h b/src/Notifier.h index 0ae38cbea0..7e240f00ca 100644 --- a/src/Notifier.h +++ b/src/Notifier.h @@ -40,14 +40,14 @@ class Notifier { // Notification events void NotifySource(llvm::StringRef name, CS_Source source, - RawEvent::Type type); + RawEvent::Kind kind); void NotifySourceVideoMode(llvm::StringRef name, CS_Source source, const VideoMode& mode); void NotifySourceProperty(llvm::StringRef name, CS_Source source, - RawEvent::Type type, int property, - CS_PropertyType propertyType, int value, + RawEvent::Kind kind, int property, + CS_PropertyKind propertyKind, int value, llvm::StringRef valueStr); - void NotifySink(llvm::StringRef name, CS_Sink sink, RawEvent::Type type); + void NotifySink(llvm::StringRef name, CS_Sink sink, RawEvent::Kind kind); private: Notifier(); diff --git a/src/SourceImpl.cpp b/src/SourceImpl.cpp index 3b512b8252..3bc2c596d2 100644 --- a/src/SourceImpl.cpp +++ b/src/SourceImpl.cpp @@ -93,13 +93,13 @@ llvm::ArrayRef SourceImpl::EnumerateProperties( return vec; } -CS_PropertyType SourceImpl::GetPropertyType(int property) const { +CS_PropertyKind SourceImpl::GetPropertyKind(int property) const { CS_Status status = 0; if (!m_properties_cached && !CacheProperties(&status)) return CS_PROP_NONE; std::lock_guard lock(m_mutex); auto prop = GetProperty(property); if (!prop) return CS_PROP_NONE; - return prop->propType; + return prop->propKind; } llvm::StringRef SourceImpl::GetPropertyName(int property, @@ -125,7 +125,7 @@ int SourceImpl::GetProperty(int property, CS_Status* status) const { *status = CS_INVALID_PROPERTY; return 0; } - if ((prop->propType & (CS_PROP_BOOLEAN | CS_PROP_INTEGER | CS_PROP_ENUM)) == + if ((prop->propKind & (CS_PROP_BOOLEAN | CS_PROP_INTEGER | CS_PROP_ENUM)) == 0) { *status = CS_WRONG_PROPERTY_TYPE; return 0; @@ -187,7 +187,7 @@ llvm::StringRef SourceImpl::GetStringProperty( *status = CS_INVALID_PROPERTY; return llvm::StringRef{}; } - if (prop->propType != CS_PROP_STRING) { + if (prop->propKind != CS_PROP_STRING) { *status = CS_WRONG_PROPERTY_TYPE; return llvm::StringRef{}; } @@ -206,7 +206,7 @@ std::vector SourceImpl::GetEnumPropertyChoices( *status = CS_INVALID_PROPERTY; return std::vector{}; } - if (prop->propType != CS_PROP_ENUM) { + if (prop->propKind != CS_PROP_ENUM) { *status = CS_WRONG_PROPERTY_TYPE; return std::vector{}; } diff --git a/src/SourceImpl.h b/src/SourceImpl.h index a22ae6447f..7a8ec05165 100644 --- a/src/SourceImpl.h +++ b/src/SourceImpl.h @@ -84,7 +84,7 @@ class SourceImpl { int GetPropertyIndex(llvm::StringRef name) const; llvm::ArrayRef EnumerateProperties(llvm::SmallVectorImpl& vec, CS_Status* status) const; - CS_PropertyType GetPropertyType(int property) const; + CS_PropertyKind GetPropertyKind(int property) const; llvm::StringRef GetPropertyName(int property, llvm::SmallVectorImpl& buf, CS_Status* status) const; @@ -138,10 +138,10 @@ class SourceImpl { class PropertyBase { public: PropertyBase() = default; - PropertyBase(llvm::StringRef name_, CS_PropertyType type_, int minimum_, + PropertyBase(llvm::StringRef name_, CS_PropertyKind kind_, int minimum_, int maximum_, int step_, int defaultValue_, int value_) : name{name_}, - propType{type_}, + propKind{kind_}, minimum{minimum_}, maximum{maximum_}, step{step_}, @@ -152,7 +152,7 @@ class SourceImpl { PropertyBase& operator=(const PropertyBase& oth) = delete; std::string name; - CS_PropertyType propType{CS_PROP_NONE}; + CS_PropertyKind propKind{CS_PROP_NONE}; int minimum; int maximum; int step; diff --git a/src/USBCameraImpl.cpp b/src/USBCameraImpl.cpp index 63f76f3a29..1445610f78 100644 --- a/src/USBCameraImpl.cpp +++ b/src/USBCameraImpl.cpp @@ -91,21 +91,21 @@ USBCameraImpl::PropertyData::PropertyData( ctrl.step, ctrl.default_value, 0), id(ctrl.id & V4L2_CTRL_ID_MASK), type(ctrl.type) { - // propType + // propKind switch (ctrl.type) { case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_INTEGER64: - propType = CS_PROP_INTEGER; + propKind = CS_PROP_INTEGER; break; case V4L2_CTRL_TYPE_BOOLEAN: - propType = CS_PROP_BOOLEAN; + propKind = CS_PROP_BOOLEAN; break; case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_MENU: - propType = CS_PROP_ENUM; + propKind = CS_PROP_ENUM; break; case V4L2_CTRL_TYPE_STRING: - propType = CS_PROP_STRING; + propKind = CS_PROP_STRING; break; default: return; // others unsupported @@ -124,21 +124,21 @@ USBCameraImpl::PropertyData::PropertyData(const struct v4l2_queryctrl& ctrl) ctrl.step, ctrl.default_value, 0), id(ctrl.id & V4L2_CTRL_ID_MASK), type(ctrl.type) { - // propType + // propKind switch (ctrl.type) { case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_INTEGER64: - propType = CS_PROP_INTEGER; + propKind = CS_PROP_INTEGER; break; case V4L2_CTRL_TYPE_BOOLEAN: - propType = CS_PROP_BOOLEAN; + propKind = CS_PROP_BOOLEAN; break; case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_MENU: - propType = CS_PROP_ENUM; + propKind = CS_PROP_ENUM; break; case V4L2_CTRL_TYPE_STRING: - propType = CS_PROP_STRING; + propKind = CS_PROP_STRING; break; default: return; // others unsupported @@ -198,7 +198,7 @@ static std::unique_ptr ExtCtrlIoctl(int fd, } // Cache enum property choices - if (prop->propType == CS_PROP_ENUM) { + if (prop->propKind == CS_PROP_ENUM) { prop->enumChoices.resize(prop->maximum + 1); v4l2_querymenu qmenu; std::memset(&qmenu, 0, sizeof(qmenu)); @@ -726,12 +726,12 @@ void USBCameraImpl::DeviceProcessCommands() { auto msg = std::move(m_commands.back()); m_commands.pop_back(); - if (msg->type == Message::kCmdSetMode || - msg->type == Message::kCmdSetPixelFormat || - msg->type == Message::kCmdSetResolution || - msg->type == Message::kCmdSetFPS) { + if (msg->kind == Message::kCmdSetMode || + msg->kind == Message::kCmdSetPixelFormat || + msg->kind == Message::kCmdSetResolution || + msg->kind == Message::kCmdSetFPS) { VideoMode newMode; - if (msg->type == Message::kCmdSetMode) { + if (msg->kind == Message::kCmdSetMode) { newMode.pixelFormat = msg->data[0]; newMode.width = msg->data[1]; newMode.height = msg->data[2]; @@ -739,16 +739,16 @@ void USBCameraImpl::DeviceProcessCommands() { m_modeSetPixelFormat = true; m_modeSetResolution = true; m_modeSetFPS = true; - } else if (msg->type == Message::kCmdSetPixelFormat) { + } else if (msg->kind == Message::kCmdSetPixelFormat) { newMode = m_mode; newMode.pixelFormat = msg->data[0]; m_modeSetPixelFormat = true; - } else if (msg->type == Message::kCmdSetResolution) { + } else if (msg->kind == Message::kCmdSetResolution) { newMode = m_mode; newMode.width = msg->data[0]; newMode.height = msg->data[1]; m_modeSetResolution = true; - } else if (msg->type == Message::kCmdSetFPS) { + } else if (msg->kind == Message::kCmdSetFPS) { newMode = m_mode; newMode.fps = msg->data[0]; m_modeSetFPS = true; @@ -774,25 +774,25 @@ void USBCameraImpl::DeviceProcessCommands() { DeviceSetFPS(); lock.lock(); } - } else if (msg->type == Message::kCmdSetProperty || - msg->type == Message::kCmdSetPropertyStr) { + } else if (msg->kind == Message::kCmdSetProperty || + msg->kind == Message::kCmdSetPropertyStr) { int property = msg->data[0]; // Look up auto prop = static_cast(GetProperty(property)); if (!prop) { - msg->type = Message::kError; + msg->kind = Message::kError; msg->data[0] = CS_INVALID_PROPERTY; goto done; } - // Check type match - if ((msg->type == Message::kCmdSetPropertyStr && - prop->propType != CS_PROP_STRING) || - (msg->type == Message::kCmdSetProperty && - (prop->propType & + // Check kind match + if ((msg->kind == Message::kCmdSetPropertyStr && + prop->propKind != CS_PROP_STRING) || + (msg->kind == Message::kCmdSetProperty && + (prop->propKind & (CS_PROP_BOOLEAN | CS_PROP_INTEGER | CS_PROP_ENUM)) == 0)) { - msg->type = Message::kError; + msg->kind = Message::kError; msg->data[0] = CS_WRONG_PROPERTY_TYPE; goto done; } @@ -808,7 +808,7 @@ void USBCameraImpl::DeviceProcessCommands() { // Set the property value on the device lock.unlock(); - if (msg->type == Message::kCmdSetPropertyStr) + if (msg->kind == Message::kCmdSetPropertyStr) rv = SetStringCtrlIoctl(fd, id, maximum, msg->dataStr); else rv = @@ -816,7 +816,7 @@ void USBCameraImpl::DeviceProcessCommands() { lock.lock(); if (rv < 0) { - msg->type = Message::kError; + msg->kind = Message::kError; msg->data[0] = CS_PROPERTY_WRITE_FAILED; goto done; } @@ -825,14 +825,14 @@ void USBCameraImpl::DeviceProcessCommands() { // Cache the set value. We need to re-get the pointer due to // releasing the lock. prop = static_cast(GetProperty(property)); - if (msg->type == Message::kCmdSetPropertyStr) + if (msg->kind == Message::kCmdSetPropertyStr) prop->valueStr = msg->dataStr; else prop->value = msg->data[1]; prop->valueSet = true; - msg->type = Message::kOk; - } else if (msg->type == Message::kNumSinksChanged || - msg->type == Message::kNumSinksEnabledChanged) { + msg->kind = Message::kOk; + } else if (msg->kind == Message::kNumSinksChanged || + msg->kind == Message::kNumSinksEnabledChanged) { // These are send-only messages, so recycle here. DestroyMessage needs // the mutex, so unlock it. We don't actually do anything directly // based on these messages (instead we check in the main loop), but @@ -841,7 +841,7 @@ void USBCameraImpl::DeviceProcessCommands() { DestroyMessage(std::move(msg)); lock.lock(); } else { - msg->type = Message::kNone; + msg->kind = Message::kNone; } done: @@ -1128,7 +1128,7 @@ bool USBCameraImpl::DeviceGetProperty(PropertyData* prop) { if (fd < 0) return true; int rv = 0; - switch (prop->propType) { + switch (prop->propKind) { case CS_PROP_BOOLEAN: case CS_PROP_INTEGER: case CS_PROP_ENUM: @@ -1155,7 +1155,7 @@ bool USBCameraImpl::DeviceSetProperty(std::unique_lock& lock, unsigned id = prop.id; int rv = 0; - switch (prop.propType) { + switch (prop.propKind) { case CS_PROP_BOOLEAN: case CS_PROP_INTEGER: case CS_PROP_ENUM: @@ -1264,7 +1264,7 @@ void USBCameraImpl::SetProperty(int property, int value, CS_Status* status) { msg->data[1] = value; msg = std::move(SendAndWait(std::move(msg))); if (!msg) return; - if (msg->type == Message::kError) *status = msg->data[0]; + if (msg->kind == Message::kError) *status = msg->data[0]; DestroyMessage(std::move(msg)); } @@ -1275,7 +1275,7 @@ void USBCameraImpl::SetStringProperty(int property, llvm::StringRef value, msg->dataStr = value; msg = std::move(SendAndWait(std::move(msg))); if (!msg) return; - if (msg->type == Message::kError) *status = msg->data[0]; + if (msg->kind == Message::kError) *status = msg->data[0]; DestroyMessage(std::move(msg)); } @@ -1288,7 +1288,7 @@ bool USBCameraImpl::SetVideoMode(const VideoMode& mode, CS_Status* status) { msg = std::move(SendAndWait(std::move(msg))); if (!msg) return false; bool rv = true; - if (msg->type == Message::kError) { + if (msg->kind == Message::kError) { *status = msg->data[0]; rv = false; } @@ -1303,7 +1303,7 @@ bool USBCameraImpl::SetPixelFormat(VideoMode::PixelFormat pixelFormat, msg = std::move(SendAndWait(std::move(msg))); if (!msg) return false; bool rv = true; - if (msg->type == Message::kError) { + if (msg->kind == Message::kError) { *status = msg->data[0]; rv = false; } @@ -1318,7 +1318,7 @@ bool USBCameraImpl::SetResolution(int width, int height, CS_Status* status) { msg = std::move(SendAndWait(std::move(msg))); if (!msg) return false; bool rv = true; - if (msg->type == Message::kError) { + if (msg->kind == Message::kError) { *status = msg->data[0]; rv = false; } @@ -1332,7 +1332,7 @@ bool USBCameraImpl::SetFPS(int fps, CS_Status* status) { msg = std::move(SendAndWait(std::move(msg))); if (!msg) return false; bool rv = true; - if (msg->type == Message::kError) { + if (msg->kind == Message::kError) { *status = msg->data[0]; rv = false; } diff --git a/src/USBCameraImpl.h b/src/USBCameraImpl.h index 1db5237e5a..1dc0423fc9 100644 --- a/src/USBCameraImpl.h +++ b/src/USBCameraImpl.h @@ -59,12 +59,12 @@ class USBCameraImpl : public SourceImpl { #endif unsigned id; // implementation-level id - int type; // implementation type, not CS_PropertyType! + int type; // implementation type, not CS_PropertyKind! }; // Messages passed to/from camera thread struct Message { - enum Type { + enum Kind { kNone = 0, kCmdSetMode, kCmdSetPixelFormat, @@ -79,9 +79,9 @@ class USBCameraImpl : public SourceImpl { kError }; - Message(Type type_) : type(type_) {} + Message(Kind kind_) : kind(kind_) {} - Type type; + Kind kind; int data[4]; std::string dataStr; }; @@ -94,12 +94,12 @@ class USBCameraImpl : public SourceImpl { private: // Message pool access - std::unique_ptr CreateMessage(Message::Type type) const { + std::unique_ptr CreateMessage(Message::Kind kind) const { std::lock_guard lock(m_mutex); - if (m_messagePool.empty()) return llvm::make_unique(type); + if (m_messagePool.empty()) return llvm::make_unique(kind); auto rv = std::move(m_messagePool.back()); m_messagePool.pop_back(); - rv->type = type; + rv->kind = kind; return rv; } void DestroyMessage(std::unique_ptr message) const { diff --git a/src/cscore_c.cpp b/src/cscore_c.cpp index 626d35213d..981d951e0d 100644 --- a/src/cscore_c.cpp +++ b/src/cscore_c.cpp @@ -18,8 +18,8 @@ extern "C" { -CS_PropertyType CS_GetPropertyType(CS_Property property, CS_Status* status) { - return cs::GetPropertyType(property, status); +CS_PropertyKind CS_GetPropertyKind(CS_Property property, CS_Status* status) { + return cs::GetPropertyKind(property, status); } char* CS_GetPropertyName(CS_Property property, CS_Status* status) { @@ -80,8 +80,8 @@ CS_Source CS_CreateHTTPCamera(const char* name, const char* url, return cs::CreateHTTPCamera(name, url, status); } -CS_SourceType CS_GetSourceType(CS_Source source, CS_Status* status) { - return cs::GetSourceType(source, status); +CS_SourceKind CS_GetSourceKind(CS_Source source, CS_Status* status) { + return cs::GetSourceKind(source, status); } char* CS_GetSourceName(CS_Source source, CS_Status* status) { @@ -191,8 +191,8 @@ void CS_ReleaseSource(CS_Source source, CS_Status* status) { return cs::ReleaseSource(source, status); } -CS_SinkType CS_GetSinkType(CS_Sink sink, CS_Status* status) { - return cs::GetSinkType(sink, status); +CS_SinkKind CS_GetSinkKind(CS_Sink sink, CS_Status* status) { + return cs::GetSinkKind(sink, status); } char* CS_GetSinkName(CS_Sink sink, CS_Status* status) { @@ -245,13 +245,13 @@ CS_Listener CS_AddListener(void* data, return cs::AddListener( [=](const cs::RawEvent& rawEvent) { CS_Event event; - event.type = static_cast(static_cast(rawEvent.type)); + event.kind = static_cast(static_cast(rawEvent.kind)); event.source = rawEvent.sourceHandle; event.sink = rawEvent.sinkHandle; event.name = rawEvent.name.c_str(); event.mode = rawEvent.mode; event.property = rawEvent.propertyHandle; - event.propertyType = rawEvent.propertyType; + event.propertyKind = rawEvent.propertyKind; event.value = rawEvent.value; event.valueStr = rawEvent.valueStr.c_str(); callback(data, &event); diff --git a/src/cscore_cpp.cpp b/src/cscore_cpp.cpp index 754fff8de8..21b7003787 100644 --- a/src/cscore_cpp.cpp +++ b/src/cscore_cpp.cpp @@ -40,11 +40,11 @@ namespace cs { // Property Functions // -CS_PropertyType GetPropertyType(CS_Property property, CS_Status* status) { +CS_PropertyKind GetPropertyKind(CS_Property property, CS_Status* status) { int propertyIndex; auto source = GetPropertySource(property, &propertyIndex, status); if (!source) return CS_PROP_NONE; - return source->GetPropertyType(propertyIndex); + return source->GetPropertyKind(propertyIndex); } std::string GetPropertyName(CS_Property property, CS_Status* status) { @@ -152,13 +152,13 @@ CS_Source CreateHTTPCamera(llvm::StringRef name, llvm::StringRef url, // Source Functions // -CS_SourceType GetSourceType(CS_Source source, CS_Status* status) { +CS_SourceKind GetSourceKind(CS_Source source, CS_Status* status) { auto data = Sources::GetInstance().Get(source); if (!data) { *status = CS_INVALID_HANDLE; return CS_SOURCE_UNKNOWN; } - return data->type; + return data->kind; } std::string GetSourceName(CS_Source source, CS_Status* status) { @@ -348,13 +348,13 @@ void ReleaseSource(CS_Source source, CS_Status* status) { // Sink Functions // -CS_SinkType GetSinkType(CS_Sink sink, CS_Status* status) { +CS_SinkKind GetSinkKind(CS_Sink sink, CS_Status* status) { auto data = Sinks::GetInstance().Get(sink); if (!data) { *status = CS_INVALID_HANDLE; return CS_SINK_UNKNOWN; } - return data->type; + return data->kind; } std::string GetSinkName(CS_Sink sink, CS_Status* status) {