Skip to content

Commit

Permalink
Call DeviceReachableChanged when subscription fails (project-chip#36175)
Browse files Browse the repository at this point in the history
* Call DeviceReachableChanged when subscription fails

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
tehampson and restyled-commits authored Oct 22, 2024
1 parent 8d44e77 commit 44db0f6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
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);

0 comments on commit 44db0f6

Please sign in to comment.