mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
Add methods to get property name and enumerate properties.
Also add method to remove property by handle.
This commit is contained in:
@@ -31,6 +31,13 @@ CS_PropertyType CS_GetPropertyType(CS_Property property, CS_Status* status) {
|
||||
return cs::GetPropertyType(property, status);
|
||||
}
|
||||
|
||||
char* CS_GetPropertyName(CS_Property property, CS_Status* status) {
|
||||
llvm::SmallString<128> str;
|
||||
cs::GetPropertyName(property, str, status);
|
||||
if (*status != 0) return nullptr;
|
||||
return ConvertToC(str);
|
||||
}
|
||||
|
||||
CS_Bool CS_GetBooleanProperty(CS_Property property, CS_Status* status) {
|
||||
return cs::GetBooleanProperty(property, status);
|
||||
}
|
||||
@@ -137,6 +144,17 @@ CS_Bool CS_IsSourceConnected(CS_Source source, CS_Status* status) {
|
||||
return cs::IsSourceConnected(source, status);
|
||||
}
|
||||
|
||||
CS_Property* EnumerateSourceProperties(CS_Source source, int* count,
|
||||
CS_Status* status) {
|
||||
llvm::SmallVector<CS_Property, 32> vec;
|
||||
cs::EnumerateSourceProperties(source, vec, status);
|
||||
CS_Property* out =
|
||||
static_cast<CS_Property*>(std::malloc(vec.size() * sizeof(CS_Property)));
|
||||
*count = vec.size();
|
||||
std::copy(vec.begin(), vec.end(), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
CS_Source CS_CopySource(CS_Source source, CS_Status* status) {
|
||||
return cs::CopySource(source, status);
|
||||
}
|
||||
@@ -177,24 +195,20 @@ CS_Property CS_CreateSourceProperty(CS_Source source, const char* name,
|
||||
|
||||
CS_Property CS_CreateSourcePropertyCallback(
|
||||
CS_Source source, const char* name, enum CS_PropertyType type, void* data,
|
||||
void (*onChange)(void* data, const char* name, CS_Property property),
|
||||
void (*onChange)(void* data, CS_Property property),
|
||||
CS_Status* status) {
|
||||
return cs::CreateSourcePropertyCallback(
|
||||
source, name, type,
|
||||
[=](llvm::StringRef name, CS_Property property) {
|
||||
// avoid the copy if possible
|
||||
if (name[name.size()] == '\0') {
|
||||
onChange(data, name.data(), property);
|
||||
} else {
|
||||
llvm::SmallString<128> copy{name};
|
||||
onChange(data, copy.c_str(), property);
|
||||
}
|
||||
},
|
||||
status);
|
||||
[=](CS_Property property) { onChange(data, property); }, status);
|
||||
}
|
||||
|
||||
void CS_RemoveSourceProperty(CS_Source source, const char* name,
|
||||
void CS_RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status) {
|
||||
return cs::RemoveSourceProperty(source, property, status);
|
||||
}
|
||||
|
||||
void CS_RemoveSourcePropertyByName(CS_Source source, const char* name,
|
||||
CS_Status* status) {
|
||||
return cs::RemoveSourceProperty(source, name, status);
|
||||
}
|
||||
|
||||
@@ -386,4 +400,8 @@ void CS_FreeEnumPropertyChoices(char** choices, int count) {
|
||||
std::free(choices);
|
||||
}
|
||||
|
||||
void CS_FreeEnumeratedProperties(CS_Property* properties, int count) {
|
||||
std::free(properties);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -21,6 +21,15 @@ CS_PropertyType GetPropertyType(CS_Property property, CS_Status* status) {
|
||||
return CS_PROP_NONE; // TODO
|
||||
}
|
||||
|
||||
std::string GetPropertyName(CS_Property property, CS_Status* status) {
|
||||
return ""; // TODO
|
||||
}
|
||||
|
||||
void GetPropertyName(CS_Property property, llvm::SmallVectorImpl<char>& name,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
bool GetBooleanProperty(CS_Property property, CS_Status* status) {
|
||||
return false; // TODO
|
||||
}
|
||||
@@ -138,6 +147,12 @@ bool IsSourceConnected(CS_Source source, CS_Status* status) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
void EnumerateSourceProperties(CS_Source source,
|
||||
llvm::SmallVectorImpl<CS_Property>& properties,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
CS_Source CopySource(CS_Source source, CS_Status* status) {
|
||||
return source; // TODO
|
||||
}
|
||||
@@ -179,11 +194,15 @@ CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
|
||||
CS_Property CreateSourcePropertyCallback(
|
||||
CS_Source source, llvm::StringRef name, CS_PropertyType type,
|
||||
std::function<void(llvm::StringRef name, CS_Property property)> onChange,
|
||||
CS_Status* status) {
|
||||
std::function<void(CS_Property property)> onChange, CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
void RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void RemoveSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
|
||||
@@ -9,9 +9,20 @@
|
||||
|
||||
using namespace cs;
|
||||
|
||||
std::vector<VideoProperty> VideoSource::EnumerateProperties() const {
|
||||
std::vector<VideoProperty> properties;
|
||||
llvm::SmallVector<CS_Property, 32> handles;
|
||||
CS_Status status = 0;
|
||||
EnumerateSourceProperties(m_handle, handles, &status);
|
||||
properties.reserve(handles.size());
|
||||
for (int handle : handles)
|
||||
properties.emplace_back(VideoProperty{handle});
|
||||
return properties;
|
||||
}
|
||||
|
||||
std::vector<VideoSource> VideoSource::EnumerateSources() {
|
||||
std::vector<VideoSource> sources;
|
||||
llvm::SmallVector<int, 16> handles;
|
||||
llvm::SmallVector<CS_Source, 16> handles;
|
||||
CS_Status status = 0;
|
||||
::cs::EnumerateSources(handles, &status);
|
||||
sources.reserve(handles.size());
|
||||
@@ -22,7 +33,7 @@ std::vector<VideoSource> VideoSource::EnumerateSources() {
|
||||
|
||||
std::vector<VideoSink> VideoSink::EnumerateSinks() {
|
||||
std::vector<VideoSink> sinks;
|
||||
llvm::SmallVector<int, 16> handles;
|
||||
llvm::SmallVector<CS_Sink, 16> handles;
|
||||
CS_Status status = 0;
|
||||
::cs::EnumerateSinks(handles, &status);
|
||||
sinks.reserve(handles.size());
|
||||
|
||||
Reference in New Issue
Block a user