@@ -43,14 +43,14 @@ constexpr uint32_t kDefaultChannelId = 1;
43
43
44
44
// Fabric Bridge Client
45
45
rpc::pw_rpc::nanopb::FabricBridge::Client fabricBridgeClient (rpc::client::GetDefaultRpcClient(), kDefaultChannelId);
46
- pw::rpc::NanopbUnaryReceiver<::pw_protobuf_Empty> addSynchronizedDeviceCall;
47
- pw::rpc::NanopbUnaryReceiver<::pw_protobuf_Empty> removeSynchronizedDeviceCall;
48
46
49
47
std::mutex responseMutex;
50
48
std::condition_variable responseCv;
51
49
bool responseReceived = false ;
52
50
CHIP_ERROR responseError = CHIP_NO_ERROR;
53
51
52
+ // By passing the `call` parameter into WaitForResponse we are explicitly trying to insure the caller takes into consideration that
53
+ // the lifetime of the `call` object when calling WaitForResponse
54
54
template <typename CallType>
55
55
CHIP_ERROR WaitForResponse (CallType & call)
56
56
{
@@ -117,52 +117,38 @@ CHIP_ERROR AddSynchronizedDevice(chip::NodeId nodeId)
117
117
{
118
118
ChipLogProgress (NotSpecified, " AddSynchronizedDevice" );
119
119
120
- if (addSynchronizedDeviceCall.active ())
121
- {
122
- ChipLogError (NotSpecified, " Add Synchronized Device operation is in progress\n " );
123
- return CHIP_ERROR_BUSY;
124
- }
125
-
126
120
chip_rpc_SynchronizedDevice device;
127
121
device.node_id = nodeId;
128
122
129
- // By assigning the returned call to the global 'addSynchronizedDeviceCall', the RPC
130
- // call is kept alive until it completes. When a response is received, it
131
- // will be logged by the handler function and the call will complete.
132
- addSynchronizedDeviceCall = fabricBridgeClient.AddSynchronizedDevice (device, OnAddDeviceResponseCompleted);
123
+ // The RPC call is kept alive until it completes. When a response is received, it will be logged by the handler
124
+ // function and the call will complete.
125
+ auto call = fabricBridgeClient.AddSynchronizedDevice (device, OnAddDeviceResponseCompleted);
133
126
134
- if (!addSynchronizedDeviceCall .active ())
127
+ if (!call .active ())
135
128
{
136
129
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
137
130
return CHIP_ERROR_INTERNAL;
138
131
}
139
132
140
- return WaitForResponse (addSynchronizedDeviceCall );
133
+ return WaitForResponse (call );
141
134
}
142
135
143
136
CHIP_ERROR RemoveSynchronizedDevice (chip::NodeId nodeId)
144
137
{
145
138
ChipLogProgress (NotSpecified, " RemoveSynchronizedDevice" );
146
139
147
- if (removeSynchronizedDeviceCall.active ())
148
- {
149
- ChipLogError (NotSpecified, " Remove Synchronized Device operation is in progress\n " );
150
- return CHIP_ERROR_BUSY;
151
- }
152
-
153
140
chip_rpc_SynchronizedDevice device;
154
141
device.node_id = nodeId;
155
142
156
- // By assigning the returned call to the global 'removeSynchronizedDeviceCall', the RPC
157
- // call is kept alive until it completes. When a response is received, it
158
- // will be logged by the handler function and the call will complete.
159
- removeSynchronizedDeviceCall = fabricBridgeClient.RemoveSynchronizedDevice (device, OnRemoveDeviceResponseCompleted);
143
+ // The RPC call is kept alive until it completes. When a response is received, it will be logged by the handler
144
+ // function and the call will complete.
145
+ auto call = fabricBridgeClient.RemoveSynchronizedDevice (device, OnRemoveDeviceResponseCompleted);
160
146
161
- if (!removeSynchronizedDeviceCall .active ())
147
+ if (!call .active ())
162
148
{
163
149
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
164
150
return CHIP_ERROR_INTERNAL;
165
151
}
166
152
167
- return WaitForResponse (removeSynchronizedDeviceCall );
153
+ return WaitForResponse (call );
168
154
}
0 commit comments