@@ -41,6 +41,7 @@ constexpr uint32_t kDefaultChannelId = 1;
41
41
// Fabric Bridge Client
42
42
rpc::pw_rpc::nanopb::FabricBridge::Client fabricBridgeClient (rpc::client::GetDefaultRpcClient(), kDefaultChannelId);
43
43
pw::rpc::NanopbUnaryReceiver<::pw_protobuf_Empty> addSynchronizedDeviceCall;
44
+ pw::rpc::NanopbUnaryReceiver<::pw_protobuf_Empty> removeSynchronizedDeviceCall;
44
45
45
46
// Callback function to be called when the RPC response is received
46
47
void OnAddDeviceResponseCompleted (const pw_protobuf_Empty & response, pw::Status status)
@@ -55,6 +56,19 @@ void OnAddDeviceResponseCompleted(const pw_protobuf_Empty & response, pw::Status
55
56
}
56
57
}
57
58
59
+ // Callback function to be called when the RPC response is received
60
+ void OnRemoveDeviceResponseCompleted (const pw_protobuf_Empty & response, pw::Status status)
61
+ {
62
+ if (status.ok ())
63
+ {
64
+ ChipLogProgress (NotSpecified, " RemoveSynchronizedDevice RPC call succeeded!" );
65
+ }
66
+ else
67
+ {
68
+ ChipLogProgress (NotSpecified, " RemoveSynchronizedDevice RPC call failed with status: %d" , status.code ());
69
+ }
70
+ }
71
+
58
72
} // namespace
59
73
60
74
CHIP_ERROR InitRpcClient (uint16_t rpcServerPort)
@@ -76,11 +90,41 @@ CHIP_ERROR AddSynchronizedDevice(chip::NodeId nodeId)
76
90
chip_rpc_SynchronizedDevice device;
77
91
device.node_id = nodeId;
78
92
79
- // The RPC will remain active as long as `addSynchronizedDeviceCall` is alive.
93
+ // By assigning the returned call to the global 'addSynchronizedDeviceCall', the RPC
94
+ // call is kept alive until it completes. When a response is received, it
95
+ // will be logged by the handler function and the call will complete.
80
96
addSynchronizedDeviceCall = fabricBridgeClient.AddSynchronizedDevice (device, OnAddDeviceResponseCompleted);
81
97
82
98
if (!addSynchronizedDeviceCall.active ())
83
99
{
100
+ // The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
101
+ return CHIP_ERROR_INTERNAL;
102
+ }
103
+
104
+ return CHIP_NO_ERROR;
105
+ }
106
+
107
+ CHIP_ERROR RemoveSynchronizedDevice (chip::NodeId nodeId)
108
+ {
109
+ ChipLogProgress (NotSpecified, " RemoveSynchronizedDevice" );
110
+
111
+ if (removeSynchronizedDeviceCall.active ())
112
+ {
113
+ ChipLogError (NotSpecified, " Remove Synchronized Device operation is in progress\n " );
114
+ return CHIP_ERROR_BUSY;
115
+ }
116
+
117
+ chip_rpc_SynchronizedDevice device;
118
+ device.node_id = nodeId;
119
+
120
+ // By assigning the returned call to the global 'removeSynchronizedDeviceCall', the RPC
121
+ // call is kept alive until it completes. When a response is received, it
122
+ // will be logged by the handler function and the call will complete.
123
+ removeSynchronizedDeviceCall = fabricBridgeClient.RemoveSynchronizedDevice (device, OnRemoveDeviceResponseCompleted);
124
+
125
+ if (!removeSynchronizedDeviceCall.active ())
126
+ {
127
+ // The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
84
128
return CHIP_ERROR_INTERNAL;
85
129
}
86
130
0 commit comments