spa: libcamera: manager: factor out hotplug event submission

The `impl::{add,remove}Camera` functions do the same thing except
for one value, the type of the hotplug event. Add a private method
to `impl` that implements the common parts.

(cherry picked from commit a36b8a273d)
This commit is contained in:
Barnabás Pőcze 2025-07-29 17:26:44 +02:00 committed by Robert Mader
parent 19d9bb7219
commit 4847bb3faf

View file

@ -75,6 +75,17 @@ struct impl {
spa_assert(std::begin(devices) <= &d && &d < std::end(devices)); spa_assert(std::begin(devices) <= &d && &d < std::end(devices));
return &d - std::begin(devices); return &d - std::begin(devices);
} }
private:
void queue_hotplug_event(enum hotplug_event::type type, std::shared_ptr<libcamera::Camera>&& camera)
{
{
std::lock_guard guard(hotplug_events_lock);
hotplug_events.push({ type, std::move(camera) });
}
spa_loop_utils_signal_event(loop_utils, hotplug_event_source);
}
}; };
struct device *add_device(struct impl *impl, std::shared_ptr<Camera> camera) struct device *add_device(struct impl *impl, std::shared_ptr<Camera> camera)
@ -210,22 +221,12 @@ void on_hotplug_event(void *data, std::uint64_t)
void impl::addCamera(std::shared_ptr<Camera> camera) void impl::addCamera(std::shared_ptr<Camera> camera)
{ {
{ queue_hotplug_event(hotplug_event::type::add, std::move(camera));
std::unique_lock guard(hotplug_events_lock);
hotplug_events.push({ hotplug_event::type::add, std::move(camera) });
}
spa_loop_utils_signal_event(loop_utils, hotplug_event_source);
} }
void impl::removeCamera(std::shared_ptr<Camera> camera) void impl::removeCamera(std::shared_ptr<Camera> camera)
{ {
{ queue_hotplug_event(hotplug_event::type::remove, std::move(camera));
std::unique_lock guard(hotplug_events_lock);
hotplug_events.push({ hotplug_event::type::remove, std::move(camera) });
}
spa_loop_utils_signal_event(loop_utils, hotplug_event_source);
} }
void start_monitor(struct impl *impl) void start_monitor(struct impl *impl)