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

@@ -1264,18 +1264,13 @@ CS_Source CreateUsbCameraDev(const wpi::Twine& name, int dev,
CS_Source CreateUsbCameraPath(const wpi::Twine& name, const wpi::Twine& path,
CS_Status* status) {
auto& inst = Instance::GetInstance();
auto source = std::make_shared<UsbCameraImpl>(
name, inst.logger, inst.notifier, inst.telemetry, path);
auto handle = inst.sources.Allocate(CS_SOURCE_USB, source);
inst.notifier.NotifySource(name, handle, CS_SOURCE_CREATED);
// Start thread after the source created event to ensure other events
// come after it.
source->Start();
return handle;
return inst.CreateSource(CS_SOURCE_USB, std::make_shared<UsbCameraImpl>(
name, inst.logger, inst.notifier,
inst.telemetry, path));
}
std::string GetUsbCameraPath(CS_Source source, CS_Status* status) {
auto data = Instance::GetInstance().sources.Get(source);
auto data = Instance::GetInstance().GetSource(source);
if (!data || data->kind != CS_SOURCE_USB) {
*status = CS_INVALID_HANDLE;
return std::string{};