Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call DeviceReachableChanged when subscription fails #36175

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
21 changes: 20 additions & 1 deletion examples/fabric-admin/device_manager/DeviceSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ void DeviceSubscription::OnDone(ReadClient * apReadClient)

void DeviceSubscription::OnError(CHIP_ERROR error)
{
#if defined(PW_RPC_ENABLED)
if (error == CHIP_ERROR_TIMEOUT && mState == State::SubscriptionStarted)
{
chip_rpc_ReachabilityChanged reachabilityChanged;
reachabilityChanged.has_id = true;
reachabilityChanged.id = mCurrentAdministratorCommissioningAttributes.id;
reachabilityChanged.reachability = false;
DeviceReachableChanged(reachabilityChanged);
}
#endif
ChipLogProgress(NotSpecified, "Error subscribing: %" CHIP_ERROR_FORMAT, error.Format());
}

Expand Down Expand Up @@ -198,7 +208,16 @@ void DeviceSubscription::OnDeviceConnectionFailure(const ScopedNodeId & peerId,
{
VerifyOrDie(mState == State::Connecting || mState == State::Stopping);
ChipLogError(NotSpecified, "DeviceSubscription failed to connect to " ChipLogFormatX64, ChipLogValueX64(peerId.GetNodeId()));
// TODO(#35333) Figure out how we should recover if we fail to connect and mState == State::Connecting.
#if defined(PW_RPC_ENABLED)
if (mState == State::Connecting)
{
chip_rpc_ReachabilityChanged reachabilityChanged;
reachabilityChanged.has_id = true;
reachabilityChanged.id = mCurrentAdministratorCommissioningAttributes.id;
reachabilityChanged.reachability = false;
DeviceReachableChanged(reachabilityChanged);
}
#endif

// After calling mOnDoneCallback we are indicating that `this` is deleted and we shouldn't do anything else with
// DeviceSubscription.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,16 @@ void DeviceSynchronizer::SynchronizationCompleteAddDevice()
if (!mCurrentDeviceData.is_icd)
{
VerifyOrDie(mController);
// TODO(#35333) Figure out how we should recover in this circumstance.
ScopedNodeId scopedNodeId(mNodeId, mController->GetFabricIndex());
CHIP_ERROR err = DeviceSubscriptionManager::Instance().StartSubscription(*mController, scopedNodeId);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed start subscription to NodeId:" ChipLogFormatX64, ChipLogValueX64(mNodeId));
chip_rpc_ReachabilityChanged reachabilityChanged;
reachabilityChanged.has_id = true;
reachabilityChanged.id = mCurrentDeviceData.id;
reachabilityChanged.reachability = false;
DeviceReachableChanged(reachabilityChanged);
}
}
#endif
Expand Down
22 changes: 22 additions & 0 deletions examples/fabric-admin/rpc/RpcClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,25 @@ CHIP_ERROR AdminCommissioningAttributeChanged(const chip_rpc_AdministratorCommis

return WaitForResponse(call);
}

CHIP_ERROR DeviceReachableChanged(const chip_rpc_ReachabilityChanged & data)
{
ChipLogProgress(NotSpecified, "DeviceReachableChanged");
// TODO(#35333): When there is some sort of device manager in fabric-admin that handles all the devices we
// are currently connected to (and not just device on the remote bridge), we should notify that manager
// so that it can properly handle any sort of reconnection logic. This can either be done here when
// `data.reachability == false`, or more control can be given wherever DeviceReachableChanged is currently
// called

// The RPC call is kept alive until it completes. When a response is received, it will be logged by the handler
// function and the call will complete.
auto call = fabricBridgeClient.DeviceReachableChanged(data, RpcCompletedWithEmptyResponse);

if (!call.active())
{
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
return CHIP_ERROR_INTERNAL;
}

return WaitForResponse(call);
}
11 changes: 11 additions & 0 deletions examples/fabric-admin/rpc/RpcClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,14 @@ CHIP_ERROR ActiveChanged(chip::ScopedNodeId scopedNodeId, uint32_t promisedActiv
* - CHIP_ERROR_INTERNAL: An internal error occurred while activating the RPC call.
*/
CHIP_ERROR AdminCommissioningAttributeChanged(const chip_rpc_AdministratorCommissioningChanged & data);

/**
* @brief Notify that reachachability of the bridged device has changed
*
* @param data information regarding change in reachability of the bridged device.
* @return CHIP_ERROR An error code indicating the success or failure of the operation.
* - CHIP_NO_ERROR: The RPC command was successfully processed.
* - CHIP_ERROR_BUSY: Another operation is currently in progress.
* - CHIP_ERROR_INTERNAL: An internal error occurred while activating the RPC call.
*/
CHIP_ERROR DeviceReachableChanged(const chip_rpc_ReachabilityChanged & data);
Loading