diff --git a/code/espurna/relay.cpp b/code/espurna/relay.cpp index ffc1452e..f0fe7d48 100644 --- a/code/espurna/relay.cpp +++ b/code/espurna/relay.cpp @@ -211,6 +211,10 @@ public: // Struct defaults to empty relay configuration, as we allow switches to exist without real GPIOs relay_t() = default; + relay_t(RelayProviderBasePtr&& provider_) : + provider(provider_.release()) + {} + relay_t(RelayProviderBase* provider_) : provider(provider_) {} @@ -1758,11 +1762,11 @@ std::unique_ptr _relayGpioProvider(unsigned char index, RelayType ); } -std::unique_ptr _relaySetupProvider(unsigned char index) { +RelayProviderBasePtr _relaySetupProvider(unsigned char index) { auto provider = getSetting({"relayProv", index}, _relayProvider(index)); auto type = getSetting({"relayType", index}, _relayType(index)); - std::unique_ptr result; + RelayProviderBasePtr result; switch (provider) { case RelayProvider::Dummy: @@ -1799,7 +1803,7 @@ void _relaySetupAdhoc() { if (!impl->setup()) { break; } - _relays.emplace_back(impl.release()); + _relays.emplace_back(std::move(impl)); } } @@ -1835,10 +1839,10 @@ void relaySetup() { } -bool relayAdd(std::unique_ptr&& provider) { +bool relayAdd(RelayProviderBasePtr&& provider) { if (provider && provider->setup()) { static bool scheduled { false }; - _relays.emplace_back(provider.release()); + _relays.emplace_back(std::move(provider)); if (!scheduled) { schedule_function([]() { _relayConfigure(); diff --git a/code/espurna/relay.h b/code/espurna/relay.h index f441b320..8d88005f 100644 --- a/code/espurna/relay.h +++ b/code/espurna/relay.h @@ -93,8 +93,9 @@ void relaySync(unsigned char id); void relaySave(bool persist); using RelayStatusCallback = void(*)(unsigned char id, bool status); +using RelayProviderBasePtr = std::unique_ptr; -bool relayAdd(std::unique_ptr&& provider); +bool relayAdd(RelayProviderBasePtr&& provider); void relaySetStatusNotify(RelayStatusCallback); void relaySetStatusChange(RelayStatusCallback);