mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
cscore: Refactor sink and source creation
Also make sources and sinks members of Instance private, with appropriate accessor functions.
This commit is contained in:
@@ -53,12 +53,36 @@ void Instance::SetDefaultLogger() { logger.SetLogger(def_log_func); }
|
||||
|
||||
std::pair<CS_Source, std::shared_ptr<SourceData>> Instance::FindSource(
|
||||
const SourceImpl& source) {
|
||||
return sources.FindIf(
|
||||
return m_sources.FindIf(
|
||||
[&](const SourceData& data) { return data.source.get() == &source; });
|
||||
}
|
||||
|
||||
std::pair<CS_Sink, std::shared_ptr<SinkData>> Instance::FindSink(
|
||||
const SinkImpl& sink) {
|
||||
return sinks.FindIf(
|
||||
return m_sinks.FindIf(
|
||||
[&](const SinkData& data) { return data.sink.get() == &sink; });
|
||||
}
|
||||
|
||||
CS_Source Instance::CreateSource(CS_SourceKind kind,
|
||||
std::shared_ptr<SourceImpl> source) {
|
||||
auto handle = m_sources.Allocate(kind, source);
|
||||
notifier.NotifySource(source->GetName(), handle, CS_SOURCE_CREATED);
|
||||
source->Start();
|
||||
return handle;
|
||||
}
|
||||
|
||||
CS_Sink Instance::CreateSink(CS_SinkKind kind, std::shared_ptr<SinkImpl> sink) {
|
||||
auto handle = m_sinks.Allocate(kind, sink);
|
||||
notifier.NotifySink(sink->GetName(), handle, CS_SINK_CREATED);
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Instance::DestroySource(CS_Source handle) {
|
||||
if (auto data = m_sources.Free(handle))
|
||||
notifier.NotifySource(data->source->GetName(), handle, CS_SOURCE_DESTROYED);
|
||||
}
|
||||
|
||||
void Instance::DestroySink(CS_Sink handle) {
|
||||
if (auto data = m_sinks.Free(handle))
|
||||
notifier.NotifySink(data->sink->GetName(), handle, CS_SINK_DESTROYED);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user