diff --git a/matterforwindows b/matterforwindows index f97cf2f..3e4936e 160000 --- a/matterforwindows +++ b/matterforwindows @@ -1 +1 @@ -Subproject commit f97cf2f95f4e4289f20963f17d6e5d212dfec199 +Subproject commit 3e4936e176f380de0f098284a3edca9c94945447 diff --git a/samples/ControllerApp/Services/ControllerSession.cs b/samples/ControllerApp/Services/ControllerSession.cs index 00309d3..ee828ac 100644 --- a/samples/ControllerApp/Services/ControllerSession.cs +++ b/samples/ControllerApp/Services/ControllerSession.cs @@ -120,7 +120,7 @@ public async Task CommissionBleAsync( public async Task RecoverNodeAsync(ulong nodeId) { - CommissionedNode node = await RequireController().RecoverNodeAsync(nodeId); + CommissionedNode node = await new MatterControllerRecovery(RequireController()).RecoverNodeAsync(nodeId); return await RegisterCommissionedNodeAsync(node); } @@ -259,7 +259,7 @@ private static async Task RecoverAfterDuplicateFabricAsync( { try { - return await controller.RecoverNodeAsync(nodeId); + return await new MatterControllerRecovery(controller).RecoverNodeAsync(nodeId); } catch (Exception recoveryException) { diff --git a/winrt/Matter.Windows.Controller.idl b/winrt/Matter.Windows.Controller.idl index a50228b..6fd2be6 100644 --- a/winrt/Matter.Windows.Controller.idl +++ b/winrt/Matter.Windows.Controller.idl @@ -165,7 +165,6 @@ namespace Matter.Windows.Controller Windows.Foundation.IAsyncOperation CommissionOnNetworkAsync(OnNetworkCommissioningParameters parameters); Windows.Foundation.IAsyncOperation CommissionBleAsync(BleCommissioningParameters parameters); Windows.Foundation.Collections.IVectorView CommissionedNodes { get; }; - Windows.Foundation.IAsyncOperation RecoverNodeAsync(UInt64 nodeId); Windows.Foundation.IAsyncAction RemoveNodeAsync(UInt64 nodeId); Windows.Foundation.IAsyncOperation ReadAttributeAsync(UInt64 nodeId, AttributePath path); Windows.Foundation.IAsyncAction WriteAttributeAsync(UInt64 nodeId, AttributePath path, Windows.Foundation.Collections.IPropertySet value); @@ -180,4 +179,10 @@ namespace Matter.Windows.Controller BasicInformationCluster GetBasicInformationCluster(UInt64 nodeId, UInt16 endpointId); Windows.Foundation.IAsyncAction CloseAsync(); }; + + runtimeclass MatterControllerRecovery + { + MatterControllerRecovery(MatterController controller); + Windows.Foundation.IAsyncOperation RecoverNodeAsync(UInt64 nodeId); + }; } diff --git a/winrt/Matter.Windows.Controller.xml b/winrt/Matter.Windows.Controller.xml index bfdbb15..ce5d078 100644 --- a/winrt/Matter.Windows.Controller.xml +++ b/winrt/Matter.Windows.Controller.xml @@ -258,7 +258,8 @@ Commissions a device over Bluetooth LE.BLE commissioning parameters.The persisted commissioned node. Gets a snapshot of nodes persisted by this controller. - Verifies an existing operational node on the current fabric and restores it to the persisted node index.The node identifier previously assigned on this fabric.The recovered commissioned node. + Creates node recovery operations for a controller.The controller whose fabric contains the node. + Verifies an existing operational node on the current fabric and restores it to the persisted node index.The node identifier previously assigned on this fabric.The recovered commissioned node. Starts removing a node from the fabric and persisted node index.The node identifier.An asynchronous action. Reads and recursively decodes a Matter attribute.The node identifier.The attribute path.The decoded attribute value. Encodes and writes a generic Matter attribute value.The node identifier.The attribute path.The generic TLV property-set representation.An asynchronous action. diff --git a/winrt/MatterControllerRecovery.h b/winrt/MatterControllerRecovery.h new file mode 100644 index 0000000..5b5ae34 --- /dev/null +++ b/winrt/MatterControllerRecovery.h @@ -0,0 +1,2 @@ +#pragma once +#include "ProjectionTypes.h" diff --git a/winrt/Projection.cpp b/winrt/Projection.cpp index 1b63b1d..c6ebafb 100644 --- a/winrt/Projection.cpp +++ b/winrt/Projection.cpp @@ -2487,13 +2487,6 @@ Windows::Foundation::Collections::IVectorView Matt return single_threaded_vector(std::move(nodes)).GetView(); } -Windows::Foundation::IAsyncOperation MatterController::RecoverNodeAsync(uint64_t nodeId) -{ - auto runtime = Runtime(); - co_await resume_background(); - co_return runtime->RecoverNode(nodeId); -} - Windows::Foundation::IAsyncAction MatterController::RemoveNodeAsync(uint64_t nodeId) { auto runtime = Runtime(); @@ -2625,6 +2618,22 @@ Controller::BasicInformationCluster MatterController::GetBasicInformationCluster return winrt::make(Runtime(), nodeId, endpointId); } +Windows::Foundation::IAsyncOperation +MatterControllerRecovery::RecoverNodeAsync(uint64_t nodeId) +{ + co_await resume_background(); + co_return mRuntime->RecoverNode(nodeId); +} + +MatterControllerRecovery::MatterControllerRecovery(Controller::MatterController controller) +{ + if (!controller) + { + throw hresult_invalid_argument(L"controller cannot be null."); + } + mRuntime = get_self(controller)->Runtime(); +} + Windows::Foundation::IAsyncAction MatterController::CloseAsync() { std::shared_ptr runtime; diff --git a/winrt/ProjectionTypes.h b/winrt/ProjectionTypes.h index e694084..53401af 100644 --- a/winrt/ProjectionTypes.h +++ b/winrt/ProjectionTypes.h @@ -21,6 +21,7 @@ #include "EventValue.g.h" #include "LevelControlCluster.g.h" #include "MatterController.g.h" +#include "MatterControllerRecovery.g.h" #include "OnNetworkCommissioningParameters.g.h" #include "OnOffCluster.g.h" #include "TimedInteractionOptions.g.h" @@ -334,7 +335,6 @@ struct MatterController : MatterControllerT Windows::Foundation::IAsyncOperation CommissionBleAsync(Controller::BleCommissioningParameters parameters); Windows::Foundation::Collections::IVectorView CommissionedNodes(); - Windows::Foundation::IAsyncOperation RecoverNodeAsync(uint64_t nodeId); Windows::Foundation::IAsyncAction RemoveNodeAsync(uint64_t nodeId); Windows::Foundation::IAsyncOperation ReadAttributeAsync(uint64_t nodeId, Controller::AttributePath path); @@ -360,16 +360,24 @@ struct MatterController : MatterControllerT Controller::LevelControlCluster GetLevelControlCluster(uint64_t nodeId, uint16_t endpointId); Controller::BasicInformationCluster GetBasicInformationCluster(uint64_t nodeId, uint16_t endpointId); Windows::Foundation::IAsyncAction CloseAsync(); - -private: std::shared_ptr Runtime(); +private: std::mutex mRuntimeMutex; std::shared_ptr mRuntime; winrt::event> mCommissioningProgress; }; +struct MatterControllerRecovery : MatterControllerRecoveryT +{ + explicit MatterControllerRecovery(Controller::MatterController controller); + Windows::Foundation::IAsyncOperation RecoverNodeAsync(uint64_t nodeId); + +private: + std::shared_ptr mRuntime; +}; + } // namespace winrt::Matter::Windows::Controller::implementation namespace winrt::Matter::Windows::Controller::factory_implementation { @@ -392,5 +400,7 @@ struct TimedInteractionOptions : TimedInteractionOptionsT {}; +struct MatterControllerRecovery : MatterControllerRecoveryT +{}; } // namespace winrt::Matter::Windows::Controller::factory_implementation