From a36b8a273d1687d088874636b1e5878680fbfda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Tue, 29 Jul 2025 17:26:44 +0200 Subject: [PATCH] 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. --- spa/plugins/libcamera/libcamera-manager.cpp | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-manager.cpp b/spa/plugins/libcamera/libcamera-manager.cpp index eda1442ee..67648105f 100644 --- a/spa/plugins/libcamera/libcamera-manager.cpp +++ b/spa/plugins/libcamera/libcamera-manager.cpp @@ -75,6 +75,17 @@ struct impl { spa_assert(std::begin(devices) <= &d && &d < std::end(devices)); return &d - std::begin(devices); } + +private: + void queue_hotplug_event(enum hotplug_event::type type, std::shared_ptr&& 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) @@ -210,22 +221,12 @@ void on_hotplug_event(void *data, std::uint64_t) void impl::addCamera(std::shared_ptr 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); + queue_hotplug_event(hotplug_event::type::add, std::move(camera)); } void impl::removeCamera(std::shared_ptr 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); + queue_hotplug_event(hotplug_event::type::remove, std::move(camera)); } void start_monitor(struct impl *impl)