Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/ControllerApp/Services/ControllerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public async Task<AddedDeviceResult> CommissionBleAsync(

public async Task<AddedDeviceResult> RecoverNodeAsync(ulong nodeId)
{
CommissionedNode node = await RequireController().RecoverNodeAsync(nodeId);
CommissionedNode node = await new MatterControllerRecovery(RequireController()).RecoverNodeAsync(nodeId);
return await RegisterCommissionedNodeAsync(node);
}

Expand Down Expand Up @@ -259,7 +259,7 @@ private static async Task<CommissionedNode> RecoverAfterDuplicateFabricAsync(
{
try
{
return await controller.RecoverNodeAsync(nodeId);
return await new MatterControllerRecovery(controller).RecoverNodeAsync(nodeId);
}
catch (Exception recoveryException)
{
Expand Down
7 changes: 6 additions & 1 deletion winrt/Matter.Windows.Controller.idl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ namespace Matter.Windows.Controller
Windows.Foundation.IAsyncOperation<CommissionedNode> CommissionOnNetworkAsync(OnNetworkCommissioningParameters parameters);
Windows.Foundation.IAsyncOperation<CommissionedNode> CommissionBleAsync(BleCommissioningParameters parameters);
Windows.Foundation.Collections.IVectorView<CommissionedNode> CommissionedNodes { get; };
Windows.Foundation.IAsyncOperation<CommissionedNode> RecoverNodeAsync(UInt64 nodeId);
Windows.Foundation.IAsyncAction RemoveNodeAsync(UInt64 nodeId);
Windows.Foundation.IAsyncOperation<AttributeValue> ReadAttributeAsync(UInt64 nodeId, AttributePath path);
Windows.Foundation.IAsyncAction WriteAttributeAsync(UInt64 nodeId, AttributePath path, Windows.Foundation.Collections.IPropertySet value);
Expand All @@ -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<CommissionedNode> RecoverNodeAsync(UInt64 nodeId);
};
}
3 changes: 2 additions & 1 deletion winrt/Matter.Windows.Controller.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions winrt/MatterControllerRecovery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#include "ProjectionTypes.h"
23 changes: 16 additions & 7 deletions winrt/Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2487,13 +2487,6 @@ Windows::Foundation::Collections::IVectorView<Controller::CommissionedNode> Matt
return single_threaded_vector(std::move(nodes)).GetView();
}

Windows::Foundation::IAsyncOperation<Controller::CommissionedNode> 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();
Expand Down Expand Up @@ -2625,6 +2618,22 @@ Controller::BasicInformationCluster MatterController::GetBasicInformationCluster
return winrt::make<BasicInformationCluster>(Runtime(), nodeId, endpointId);
}

Windows::Foundation::IAsyncOperation<Controller::CommissionedNode>
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<implementation::MatterController>(controller)->Runtime();
}

Windows::Foundation::IAsyncAction MatterController::CloseAsync()
{
std::shared_ptr<ControllerRuntime> runtime;
Expand Down
16 changes: 13 additions & 3 deletions winrt/ProjectionTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -334,7 +335,6 @@ struct MatterController : MatterControllerT<MatterController>
Windows::Foundation::IAsyncOperation<Controller::CommissionedNode>
CommissionBleAsync(Controller::BleCommissioningParameters parameters);
Windows::Foundation::Collections::IVectorView<Controller::CommissionedNode> CommissionedNodes();
Windows::Foundation::IAsyncOperation<Controller::CommissionedNode> RecoverNodeAsync(uint64_t nodeId);
Windows::Foundation::IAsyncAction RemoveNodeAsync(uint64_t nodeId);
Windows::Foundation::IAsyncOperation<Controller::AttributeValue> ReadAttributeAsync(uint64_t nodeId,
Controller::AttributePath path);
Expand All @@ -360,16 +360,24 @@ struct MatterController : MatterControllerT<MatterController>
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<ControllerRuntime> Runtime();

private:
std::mutex mRuntimeMutex;
std::shared_ptr<ControllerRuntime> mRuntime;
winrt::event<Windows::Foundation::TypedEventHandler<Controller::MatterController, Controller::CommissioningProgressEventArgs>>
mCommissioningProgress;
};

struct MatterControllerRecovery : MatterControllerRecoveryT<MatterControllerRecovery>
{
explicit MatterControllerRecovery(Controller::MatterController controller);
Windows::Foundation::IAsyncOperation<Controller::CommissionedNode> RecoverNodeAsync(uint64_t nodeId);

private:
std::shared_ptr<ControllerRuntime> mRuntime;
};

} // namespace winrt::Matter::Windows::Controller::implementation

namespace winrt::Matter::Windows::Controller::factory_implementation {
Expand All @@ -392,5 +400,7 @@ struct TimedInteractionOptions : TimedInteractionOptionsT<TimedInteractionOption
{};
struct MatterController : MatterControllerT<MatterController, implementation::MatterController>
{};
struct MatterControllerRecovery : MatterControllerRecoveryT<MatterControllerRecovery, implementation::MatterControllerRecovery>
{};

} // namespace winrt::Matter::Windows::Controller::factory_implementation