From d7d3f5c7bd698b69c55aec17314bd5ea41264e16 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Tue, 2 Jul 2024 17:21:30 +0000 Subject: [PATCH 1/2] Use shared_ptr instead of unique_ptr for WpaEventHandler. --- src/linux/wpa-controller/Hostapd.cxx | 2 +- src/linux/wpa-controller/include/Wpa/Hostapd.hxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linux/wpa-controller/Hostapd.cxx b/src/linux/wpa-controller/Hostapd.cxx index f38414b1..1a89969c 100644 --- a/src/linux/wpa-controller/Hostapd.cxx +++ b/src/linux/wpa-controller/Hostapd.cxx @@ -43,7 +43,7 @@ Hostapd::Hostapd(std::string_view interfaceName) : throw HostapdException("Failed to create hostapd event handler control socket connection"); } - auto eventHandler{ std::make_unique(std::move(controlSocketConnection), WpaType::Hostapd) }; + auto eventHandler{ std::make_shared(std::move(controlSocketConnection), WpaType::Hostapd) }; if (!eventHandler) { throw HostapdException("Failed to create hostapd event handler"); } diff --git a/src/linux/wpa-controller/include/Wpa/Hostapd.hxx b/src/linux/wpa-controller/include/Wpa/Hostapd.hxx index 6c2e542d..4c964c5e 100644 --- a/src/linux/wpa-controller/include/Wpa/Hostapd.hxx +++ b/src/linux/wpa-controller/include/Wpa/Hostapd.hxx @@ -271,7 +271,7 @@ private: WpaController m_controller; std::unique_ptr m_eventHandlerControlSocketConnection{ nullptr }; std::shared_ptr m_eventListenerProxy; - std::unique_ptr m_eventHandler{ nullptr }; + std::shared_ptr m_eventHandler{ nullptr }; WpaEventListenerRegistrationToken m_eventHandlerRegistrationToken{}; }; } // namespace Wpa From 09502ddb8fcd3a96cec6b4d1c3b12e911fa66e89 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Tue, 2 Jul 2024 17:24:14 +0000 Subject: [PATCH 2/2] Expose WpaEventHandler from IHostapd interface. --- src/linux/wpa-controller/Hostapd.cxx | 6 ++++++ src/linux/wpa-controller/include/Wpa/Hostapd.hxx | 8 ++++++++ src/linux/wpa-controller/include/Wpa/IHostapd.hxx | 11 ++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/linux/wpa-controller/Hostapd.cxx b/src/linux/wpa-controller/Hostapd.cxx index 1a89969c..c8bbad8b 100644 --- a/src/linux/wpa-controller/Hostapd.cxx +++ b/src/linux/wpa-controller/Hostapd.cxx @@ -64,6 +64,12 @@ Hostapd::GetInterface() return m_interface; } +std::shared_ptr +Hostapd::GetEventHandler() const noexcept +{ + return m_eventHandler; +} + void Hostapd::Ping() { diff --git a/src/linux/wpa-controller/include/Wpa/Hostapd.hxx b/src/linux/wpa-controller/include/Wpa/Hostapd.hxx index 4c964c5e..5d1c3794 100644 --- a/src/linux/wpa-controller/include/Wpa/Hostapd.hxx +++ b/src/linux/wpa-controller/include/Wpa/Hostapd.hxx @@ -93,6 +93,14 @@ struct Hostapd : std::string_view GetInterface() override; + /** + * @brief Obtain the event handler for the interface. + * + * @return std::shared_ptr + */ + std::shared_ptr + GetEventHandler() const noexcept override; + /** * @brief Get the status for the interface. * diff --git a/src/linux/wpa-controller/include/Wpa/IHostapd.hxx b/src/linux/wpa-controller/include/Wpa/IHostapd.hxx index f69112af..ea8b143a 100644 --- a/src/linux/wpa-controller/include/Wpa/IHostapd.hxx +++ b/src/linux/wpa-controller/include/Wpa/IHostapd.hxx @@ -12,6 +12,7 @@ #include #include +#include namespace Wpa { @@ -90,6 +91,14 @@ struct IHostapd virtual std::string_view GetInterface() = 0; + /** + * @brief Obtain the event handler for the interface. + * + * @return std::shared_ptr + */ + virtual std::shared_ptr + GetEventHandler() const noexcept = 0; + /** * @brief Get the status for the interface. * @@ -217,7 +226,7 @@ struct IHostapd * @brief Add RADIUS server endpoints to the interface. This may contain multiple endpoints of various types. The * first endpoint configuration for each type is used as the primary server, and any following are used as fallbacks * in case the primary server is unreachable. - * + * * @param endpointConfigurations The endpoint configurations to add. * @param enforceConfigurationChange When to enforce the configuration change. A value of 'Now' will trigger a * configuration reload.