cscore: Refactor sink and source creation

Also make sources and sinks members of Instance private, with appropriate
accessor functions.
This commit is contained in:
Peter Johnson
2018-11-06 19:42:39 -08:00
parent 81d10bc656
commit 0abae17653
13 changed files with 185 additions and 137 deletions

View File

@@ -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);
}