Skip to content

Commit 69dfccb

Browse files
authored
Merge branch 'master' into feature/app-install-flow-public
2 parents f964d0a + 1cd70c1 commit 69dfccb

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
lines changed

examples/fabric-admin/rpc/RpcClient.cpp

+12-26
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ constexpr uint32_t kDefaultChannelId = 1;
4343

4444
// Fabric Bridge Client
4545
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;
4846

4947
std::mutex responseMutex;
5048
std::condition_variable responseCv;
5149
bool responseReceived = false;
5250
CHIP_ERROR responseError = CHIP_NO_ERROR;
5351

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
5454
template <typename CallType>
5555
CHIP_ERROR WaitForResponse(CallType & call)
5656
{
@@ -117,52 +117,38 @@ CHIP_ERROR AddSynchronizedDevice(chip::NodeId nodeId)
117117
{
118118
ChipLogProgress(NotSpecified, "AddSynchronizedDevice");
119119

120-
if (addSynchronizedDeviceCall.active())
121-
{
122-
ChipLogError(NotSpecified, "Add Synchronized Device operation is in progress\n");
123-
return CHIP_ERROR_BUSY;
124-
}
125-
126120
chip_rpc_SynchronizedDevice device;
127121
device.node_id = nodeId;
128122

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);
133126

134-
if (!addSynchronizedDeviceCall.active())
127+
if (!call.active())
135128
{
136129
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
137130
return CHIP_ERROR_INTERNAL;
138131
}
139132

140-
return WaitForResponse(addSynchronizedDeviceCall);
133+
return WaitForResponse(call);
141134
}
142135

143136
CHIP_ERROR RemoveSynchronizedDevice(chip::NodeId nodeId)
144137
{
145138
ChipLogProgress(NotSpecified, "RemoveSynchronizedDevice");
146139

147-
if (removeSynchronizedDeviceCall.active())
148-
{
149-
ChipLogError(NotSpecified, "Remove Synchronized Device operation is in progress\n");
150-
return CHIP_ERROR_BUSY;
151-
}
152-
153140
chip_rpc_SynchronizedDevice device;
154141
device.node_id = nodeId;
155142

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);
160146

161-
if (!removeSynchronizedDeviceCall.active())
147+
if (!call.active())
162148
{
163149
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
164150
return CHIP_ERROR_INTERNAL;
165151
}
166152

167-
return WaitForResponse(removeSynchronizedDeviceCall);
153+
return WaitForResponse(call);
168154
}

examples/fabric-bridge-app/linux/RpcClient.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ constexpr uint32_t kDefaultChannelId = 1;
4343

4444
// Fabric Admin Client
4545
rpc::pw_rpc::nanopb::FabricAdmin::Client fabricAdminClient(rpc::client::GetDefaultRpcClient(), kDefaultChannelId);
46-
pw::rpc::NanopbUnaryReceiver<::chip_rpc_OperationStatus> openCommissioningWindowCall;
4746

4847
std::mutex responseMutex;
4948
std::condition_variable responseCv;
5049
bool responseReceived = false;
5150
CHIP_ERROR responseError = CHIP_NO_ERROR;
5251

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
5354
template <typename CallType>
5455
CHIP_ERROR WaitForResponse(CallType & call)
5556
{
@@ -98,23 +99,18 @@ CHIP_ERROR OpenCommissioningWindow(NodeId nodeId)
9899
{
99100
ChipLogProgress(NotSpecified, "OpenCommissioningWindow with Node Id 0x:" ChipLogFormatX64, ChipLogValueX64(nodeId));
100101

101-
if (openCommissioningWindowCall.active())
102-
{
103-
ChipLogError(NotSpecified, "OpenCommissioningWindow is in progress\n");
104-
return CHIP_ERROR_BUSY;
105-
}
106-
107102
chip_rpc_DeviceInfo device;
108103
device.node_id = nodeId;
109104

110-
// The RPC will remain active as long as `openCommissioningWindowCall` is alive.
111-
openCommissioningWindowCall = fabricAdminClient.OpenCommissioningWindow(device, OnOpenCommissioningWindowCompleted);
105+
// The RPC call is kept alive until it completes. When a response is received, it will be logged by the handler
106+
// function and the call will complete.
107+
auto call = fabricAdminClient.OpenCommissioningWindow(device, OnOpenCommissioningWindowCompleted);
112108

113-
if (!openCommissioningWindowCall.active())
109+
if (!call.active())
114110
{
115111
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
116112
return CHIP_ERROR_INTERNAL;
117113
}
118114

119-
return WaitForResponse(openCommissioningWindowCall);
115+
return WaitForResponse(call);
120116
}

0 commit comments

Comments
 (0)