Skip to content

Commit 44db0f6

Browse files
Call DeviceReachableChanged when subscription fails (project-chip#36175)
* Call DeviceReachableChanged when subscription fails * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 8d44e77 commit 44db0f6

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

examples/fabric-admin/device_manager/DeviceSubscription.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ void DeviceSubscription::OnDone(ReadClient * apReadClient)
125125

126126
void DeviceSubscription::OnError(CHIP_ERROR error)
127127
{
128+
#if defined(PW_RPC_ENABLED)
129+
if (error == CHIP_ERROR_TIMEOUT && mState == State::SubscriptionStarted)
130+
{
131+
chip_rpc_ReachabilityChanged reachabilityChanged;
132+
reachabilityChanged.has_id = true;
133+
reachabilityChanged.id = mCurrentAdministratorCommissioningAttributes.id;
134+
reachabilityChanged.reachability = false;
135+
DeviceReachableChanged(reachabilityChanged);
136+
}
137+
#endif
128138
ChipLogProgress(NotSpecified, "Error subscribing: %" CHIP_ERROR_FORMAT, error.Format());
129139
}
130140

@@ -198,7 +208,16 @@ void DeviceSubscription::OnDeviceConnectionFailure(const ScopedNodeId & peerId,
198208
{
199209
VerifyOrDie(mState == State::Connecting || mState == State::Stopping);
200210
ChipLogError(NotSpecified, "DeviceSubscription failed to connect to " ChipLogFormatX64, ChipLogValueX64(peerId.GetNodeId()));
201-
// TODO(#35333) Figure out how we should recover if we fail to connect and mState == State::Connecting.
211+
#if defined(PW_RPC_ENABLED)
212+
if (mState == State::Connecting)
213+
{
214+
chip_rpc_ReachabilityChanged reachabilityChanged;
215+
reachabilityChanged.has_id = true;
216+
reachabilityChanged.id = mCurrentAdministratorCommissioningAttributes.id;
217+
reachabilityChanged.reachability = false;
218+
DeviceReachableChanged(reachabilityChanged);
219+
}
220+
#endif
202221

203222
// After calling mOnDoneCallback we are indicating that `this` is deleted and we shouldn't do anything else with
204223
// DeviceSubscription.

examples/fabric-admin/device_manager/DeviceSynchronization.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,16 @@ void DeviceSynchronizer::SynchronizationCompleteAddDevice()
277277
if (!mCurrentDeviceData.is_icd)
278278
{
279279
VerifyOrDie(mController);
280-
// TODO(#35333) Figure out how we should recover in this circumstance.
281280
ScopedNodeId scopedNodeId(mNodeId, mController->GetFabricIndex());
282281
CHIP_ERROR err = DeviceSubscriptionManager::Instance().StartSubscription(*mController, scopedNodeId);
283282
if (err != CHIP_NO_ERROR)
284283
{
285284
ChipLogError(NotSpecified, "Failed start subscription to NodeId:" ChipLogFormatX64, ChipLogValueX64(mNodeId));
285+
chip_rpc_ReachabilityChanged reachabilityChanged;
286+
reachabilityChanged.has_id = true;
287+
reachabilityChanged.id = mCurrentDeviceData.id;
288+
reachabilityChanged.reachability = false;
289+
DeviceReachableChanged(reachabilityChanged);
286290
}
287291
}
288292
#endif

examples/fabric-admin/rpc/RpcClient.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,25 @@ CHIP_ERROR AdminCommissioningAttributeChanged(const chip_rpc_AdministratorCommis
205205

206206
return WaitForResponse(call);
207207
}
208+
209+
CHIP_ERROR DeviceReachableChanged(const chip_rpc_ReachabilityChanged & data)
210+
{
211+
ChipLogProgress(NotSpecified, "DeviceReachableChanged");
212+
// TODO(#35333): When there is some sort of device manager in fabric-admin that handles all the devices we
213+
// are currently connected to (and not just device on the remote bridge), we should notify that manager
214+
// so that it can properly handle any sort of reconnection logic. This can either be done here when
215+
// `data.reachability == false`, or more control can be given wherever DeviceReachableChanged is currently
216+
// called
217+
218+
// The RPC call is kept alive until it completes. When a response is received, it will be logged by the handler
219+
// function and the call will complete.
220+
auto call = fabricBridgeClient.DeviceReachableChanged(data, RpcCompletedWithEmptyResponse);
221+
222+
if (!call.active())
223+
{
224+
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
225+
return CHIP_ERROR_INTERNAL;
226+
}
227+
228+
return WaitForResponse(call);
229+
}

examples/fabric-admin/rpc/RpcClient.h

+11
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,14 @@ CHIP_ERROR ActiveChanged(chip::ScopedNodeId scopedNodeId, uint32_t promisedActiv
8888
* - CHIP_ERROR_INTERNAL: An internal error occurred while activating the RPC call.
8989
*/
9090
CHIP_ERROR AdminCommissioningAttributeChanged(const chip_rpc_AdministratorCommissioningChanged & data);
91+
92+
/**
93+
* @brief Notify that reachachability of the bridged device has changed
94+
*
95+
* @param data information regarding change in reachability of the bridged device.
96+
* @return CHIP_ERROR An error code indicating the success or failure of the operation.
97+
* - CHIP_NO_ERROR: The RPC command was successfully processed.
98+
* - CHIP_ERROR_BUSY: Another operation is currently in progress.
99+
* - CHIP_ERROR_INTERNAL: An internal error occurred while activating the RPC call.
100+
*/
101+
CHIP_ERROR DeviceReachableChanged(const chip_rpc_ReachabilityChanged & data);

0 commit comments

Comments
 (0)