Skip to content

Commit 1eba8db

Browse files
yufengwangcarestyled-commits
authored andcommitted
[Fabric-Admin] Fix compile errors when RPC is disabled (project-chip#35639)
* Fix compile error when RPC is disabled * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent a60ab18 commit 1eba8db

5 files changed

+59
-13
lines changed

examples/fabric-admin/device_manager/DeviceSubscription.cpp

+19-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
*/
1818

1919
#include "DeviceSubscription.h"
20+
21+
#if defined(PW_RPC_ENABLED)
2022
#include "rpc/RpcClient.h"
23+
#endif
2124

2225
#include <app/InteractionModelEngine.h>
2326
#include <app/server/Server.h>
@@ -61,29 +64,35 @@ void DeviceSubscription::OnAttributeData(const ConcreteDataAttributePath & path,
6164
CHIP_ERROR err = data->Get(windowStatus);
6265
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(NotSpecified, "Failed to read WindowStatus"));
6366
VerifyOrReturn(windowStatus != Clusters::AdministratorCommissioning::CommissioningWindowStatusEnum::kUnknownEnumValue);
67+
#if defined(PW_RPC_ENABLED)
6468
mCurrentAdministratorCommissioningAttributes.window_status = static_cast<uint32_t>(windowStatus);
65-
mChangeDetected = true;
69+
#endif
70+
mChangeDetected = true;
6671
break;
6772
}
6873
case Clusters::AdministratorCommissioning::Attributes::AdminFabricIndex::Id: {
74+
#if defined(PW_RPC_ENABLED)
6975
FabricIndex fabricIndex;
7076
CHIP_ERROR err = data->Get(fabricIndex);
7177
mCurrentAdministratorCommissioningAttributes.has_opener_fabric_index = err == CHIP_NO_ERROR;
7278
if (mCurrentAdministratorCommissioningAttributes.has_opener_fabric_index)
7379
{
7480
mCurrentAdministratorCommissioningAttributes.opener_fabric_index = static_cast<uint32_t>(fabricIndex);
7581
}
82+
#endif
7683
mChangeDetected = true;
7784
break;
7885
}
7986
case Clusters::AdministratorCommissioning::Attributes::AdminVendorId::Id: {
87+
#if defined(PW_RPC_ENABLED)
8088
chip::VendorId vendorId;
8189
CHIP_ERROR err = data->Get(vendorId);
8290
mCurrentAdministratorCommissioningAttributes.has_opener_vendor_id = err == CHIP_NO_ERROR;
8391
if (mCurrentAdministratorCommissioningAttributes.has_opener_vendor_id)
8492
{
8593
mCurrentAdministratorCommissioningAttributes.opener_vendor_id = static_cast<uint32_t>(vendorId);
8694
}
95+
#endif
8796
mChangeDetected = true;
8897
break;
8998
}
@@ -111,7 +120,7 @@ void DeviceSubscription::OnDone(ReadClient * apReadClient)
111120
// After calling mOnDoneCallback we are indicating that `this` is deleted and we shouldn't do anything else with
112121
// DeviceSubscription.
113122
MoveToState(State::AwaitingDestruction);
114-
mOnDoneCallback(mCurrentAdministratorCommissioningAttributes.node_id);
123+
mOnDoneCallback(mNodeId);
115124
}
116125

117126
void DeviceSubscription::OnError(CHIP_ERROR error)
@@ -126,7 +135,7 @@ void DeviceSubscription::OnDeviceConnected(Messaging::ExchangeManager & exchange
126135
// After calling mOnDoneCallback we are indicating that `this` is deleted and we shouldn't do anything else with
127136
// DeviceSubscription.
128137
MoveToState(State::AwaitingDestruction);
129-
mOnDoneCallback(mCurrentAdministratorCommissioningAttributes.node_id);
138+
mOnDoneCallback(mNodeId);
130139
return;
131140
}
132141
VerifyOrDie(mState == State::Connecting);
@@ -151,7 +160,7 @@ void DeviceSubscription::OnDeviceConnected(Messaging::ExchangeManager & exchange
151160
// After calling mOnDoneCallback we are indicating that `this` is deleted and we shouldn't do anything else with
152161
// DeviceSubscription.
153162
MoveToState(State::AwaitingDestruction);
154-
mOnDoneCallback(mCurrentAdministratorCommissioningAttributes.node_id);
163+
mOnDoneCallback(mNodeId);
155164
return;
156165
}
157166
MoveToState(State::SubscriptionStarted);
@@ -194,7 +203,7 @@ void DeviceSubscription::OnDeviceConnectionFailure(const ScopedNodeId & peerId,
194203
// After calling mOnDoneCallback we are indicating that `this` is deleted and we shouldn't do anything else with
195204
// DeviceSubscription.
196205
MoveToState(State::AwaitingDestruction);
197-
mOnDoneCallback(mCurrentAdministratorCommissioningAttributes.node_id);
206+
mOnDoneCallback(mNodeId);
198207
}
199208

200209
CHIP_ERROR DeviceSubscription::StartSubscription(OnDoneCallback onDoneCallback, Controller::DeviceController & controller,
@@ -203,10 +212,14 @@ CHIP_ERROR DeviceSubscription::StartSubscription(OnDoneCallback onDoneCallback,
203212
assertChipStackLockedByCurrentThread();
204213
VerifyOrDie(mState == State::Idle);
205214

215+
mNodeId = nodeId;
216+
217+
#if defined(PW_RPC_ENABLED)
206218
mCurrentAdministratorCommissioningAttributes = chip_rpc_AdministratorCommissioningChanged_init_default;
207219
mCurrentAdministratorCommissioningAttributes.node_id = nodeId;
208220
mCurrentAdministratorCommissioningAttributes.window_status =
209221
static_cast<uint32_t>(Clusters::AdministratorCommissioning::CommissioningWindowStatusEnum::kWindowNotOpen);
222+
#endif
210223

211224
mOnDoneCallback = onDoneCallback;
212225
MoveToState(State::Connecting);
@@ -243,5 +256,5 @@ void DeviceSubscription::StopSubscription()
243256
// After calling mOnDoneCallback we are indicating that `this` is deleted and we shouldn't do anything else with
244257
// DeviceSubscription.
245258
MoveToState(State::AwaitingDestruction);
246-
mOnDoneCallback(mCurrentAdministratorCommissioningAttributes.node_id);
259+
mOnDoneCallback(mNodeId);
247260
}

examples/fabric-admin/device_manager/DeviceSubscription.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@
2323

2424
#include <memory>
2525

26+
#if defined(PW_RPC_ENABLED)
2627
#include "fabric_bridge_service/fabric_bridge_service.pb.h"
2728
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
29+
#endif
2830

2931
class DeviceSubscriptionManager;
3032

3133
/// Attribute subscription to attributes that are important to keep track and send to fabric-bridge
3234
/// via RPC when change has been identified.
3335
///
3436
/// An instance of DeviceSubscription is intended to be used only once. Once a DeviceSubscription is
35-
/// terminal, either from an error or from subscriptions getting shut down, we expect the instance
37+
/// terminated, either from an error or from subscriptions getting shut down, we expect the instance
3638
/// to be deleted. Any new subscription should instantiate another instance of DeviceSubscription.
3739
class DeviceSubscription : public chip::app::ReadClient::Callback
3840
{
@@ -78,13 +80,18 @@ class DeviceSubscription : public chip::app::ReadClient::Callback
7880
void MoveToState(const State aTargetState);
7981
const char * GetStateStr() const;
8082

83+
chip::NodeId mNodeId = chip::kUndefinedNodeId;
84+
8185
OnDoneCallback mOnDoneCallback;
8286
std::unique_ptr<chip::app::ReadClient> mClient;
8387

8488
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
8589
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
8690

91+
#if defined(PW_RPC_ENABLED)
8792
chip_rpc_AdministratorCommissioningChanged mCurrentAdministratorCommissioningAttributes;
93+
#endif
94+
8895
bool mChangeDetected = false;
8996
State mState = State::Idle;
9097
};

examples/fabric-admin/device_manager/DeviceSubscriptionManager.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
*/
1818

1919
#include "DeviceSubscriptionManager.h"
20+
21+
#if defined(PW_RPC_ENABLED)
2022
#include "rpc/RpcClient.h"
23+
#endif
2124

2225
#include <app/InteractionModelEngine.h>
2326
#include <app/server/Server.h>

examples/fabric-admin/device_manager/DeviceSynchronization.cpp

+23-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
#include "DeviceSynchronization.h"
2020

2121
#include "DeviceSubscriptionManager.h"
22+
23+
#if defined(PW_RPC_ENABLED)
2224
#include "rpc/RpcClient.h"
25+
#endif
2326

2427
#include <app/InteractionModelEngine.h>
2528
#include <app/server/Server.h>
@@ -44,6 +47,7 @@ void OnDeviceConnectionFailureWrapper(void * context, const ScopedNodeId & peerI
4447
reinterpret_cast<DeviceSynchronizer *>(context)->OnDeviceConnectionFailure(peerId, error);
4548
}
4649

50+
#if defined(PW_RPC_ENABLED)
4751
bool SuccessOrLog(CHIP_ERROR err, const char * name)
4852
{
4953
if (err == CHIP_NO_ERROR)
@@ -55,6 +59,7 @@ bool SuccessOrLog(CHIP_ERROR err, const char * name)
5559

5660
return false;
5761
}
62+
#endif
5863

5964
} // namespace
6065

@@ -82,6 +87,7 @@ void DeviceSynchronizer::OnAttributeData(const ConcreteDataAttributePath & path,
8287

8388
switch (path.mAttributeId)
8489
{
90+
#if defined(PW_RPC_ENABLED)
8591
case Clusters::BasicInformation::Attributes::UniqueID::Id:
8692
mCurrentDeviceData.has_unique_id =
8793
SuccessOrLog(data->GetString(mCurrentDeviceData.unique_id, sizeof(mCurrentDeviceData.unique_id)), "UniqueId");
@@ -120,6 +126,7 @@ void DeviceSynchronizer::OnAttributeData(const ConcreteDataAttributePath & path,
120126
data->GetString(mCurrentDeviceData.software_version_string, sizeof(mCurrentDeviceData.software_version_string)),
121127
"SoftwareVersionString");
122128
break;
129+
#endif // #if defined(PW_RPC_ENABLED)
123130
default:
124131
break;
125132
}
@@ -134,7 +141,7 @@ void DeviceSynchronizer::OnReportEnd()
134141
void DeviceSynchronizer::OnDone(chip::app::ReadClient * apReadClient)
135142
{
136143
#if defined(PW_RPC_ENABLED)
137-
if (mState == State::ReceivedResponse && !DeviceMgr().IsCurrentBridgeDevice(mCurrentDeviceData.node_id))
144+
if (mState == State::ReceivedResponse && !DeviceMgr().IsCurrentBridgeDevice(mNodeId))
138145
{
139146
GetUniqueId();
140147
if (mState == State::GettingUid)
@@ -197,10 +204,14 @@ void DeviceSynchronizer::StartDeviceSynchronization(chip::Controller::DeviceCont
197204
return;
198205
}
199206

207+
mNodeId = nodeId;
208+
209+
#if defined(PW_RPC_ENABLED)
200210
mCurrentDeviceData = chip_rpc_SynchronizedDevice_init_default;
201211
mCurrentDeviceData.node_id = nodeId;
202212
mCurrentDeviceData.has_is_icd = true;
203213
mCurrentDeviceData.is_icd = deviceIsIcd;
214+
#endif
204215

205216
ReturnOnFailure(controller->GetConnectedDevice(nodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback));
206217
mController = controller;
@@ -212,10 +223,12 @@ void DeviceSynchronizer::GetUniqueId()
212223
VerifyOrDie(mState == State::ReceivedResponse);
213224
VerifyOrDie(mController);
214225

226+
#if defined(PW_RPC_ENABLED)
215227
// If we have a UniqueId we can return leaving state in ReceivedResponse.
216228
VerifyOrReturn(!mCurrentDeviceData.has_unique_id, ChipLogDetail(NotSpecified, "We already have UniqueId"));
229+
#endif
217230

218-
auto * device = DeviceMgr().FindDeviceByNode(mCurrentDeviceData.node_id);
231+
auto * device = DeviceMgr().FindDeviceByNode(mNodeId);
219232
// If there is no associated remote Fabric Sync Aggregator there is no other place for us to try
220233
// getting the UniqueId from and can return leaving the state in ReceivedResponse.
221234
VerifyOrReturn(device, ChipLogDetail(NotSpecified, "No remote Fabric Sync Aggregator to get UniqueId from"));
@@ -231,8 +244,10 @@ void DeviceSynchronizer::GetUniqueId()
231244
[this](std::optional<CharSpan> aUniqueId) {
232245
if (aUniqueId.has_value())
233246
{
247+
#if defined(PW_RPC_ENABLED)
234248
this->mCurrentDeviceData.has_unique_id = true;
235249
memcpy(this->mCurrentDeviceData.unique_id, aUniqueId.value().data(), aUniqueId.value().size());
250+
#endif
236251
}
237252
else
238253
{
@@ -255,19 +270,22 @@ void DeviceSynchronizer::GetUniqueId()
255270
void DeviceSynchronizer::SynchronizationCompleteAddDevice()
256271
{
257272
VerifyOrDie(mState == State::ReceivedResponse || mState == State::GettingUid);
273+
274+
#if defined(PW_RPC_ENABLED)
258275
AddSynchronizedDevice(mCurrentDeviceData);
259276
// TODO(#35077) Figure out how we should reflect CADMIN values of ICD.
260277
if (!mCurrentDeviceData.is_icd)
261278
{
262279
VerifyOrDie(mController);
263280
// TODO(#35333) Figure out how we should recover in this circumstance.
264-
CHIP_ERROR err = DeviceSubscriptionManager::Instance().StartSubscription(*mController, mCurrentDeviceData.node_id);
281+
CHIP_ERROR err = DeviceSubscriptionManager::Instance().StartSubscription(*mController, mNodeId);
265282
if (err != CHIP_NO_ERROR)
266283
{
267-
ChipLogError(NotSpecified, "Failed start subscription to NodeId:" ChipLogFormatX64,
268-
ChipLogValueX64(mCurrentDeviceData.node_id));
284+
ChipLogError(NotSpecified, "Failed start subscription to NodeId:" ChipLogFormatX64, ChipLogValueX64(mNodeId));
269285
}
270286
}
287+
#endif
288+
271289
MoveToState(State::Idle);
272290
}
273291

examples/fabric-admin/device_manager/DeviceSynchronization.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
#include <memory>
2727

28+
#if defined(PW_RPC_ENABLED)
2829
#include "fabric_bridge_service/fabric_bridge_service.pb.h"
2930
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
31+
#endif
3032

3133
/// Ensures that device data is synchronized to the remote fabric bridge.
3234
///
@@ -92,6 +94,9 @@ class DeviceSynchronizer : public chip::app::ReadClient::Callback
9294
// mController is expected to remain valid throughout the entire device synchronization process (i.e. when
9395
// mState != Idle).
9496
chip::Controller::DeviceController * mController = nullptr;
95-
chip_rpc_SynchronizedDevice mCurrentDeviceData = chip_rpc_SynchronizedDevice_init_default;
97+
chip::NodeId mNodeId = chip::kUndefinedNodeId;
98+
#if defined(PW_RPC_ENABLED)
99+
chip_rpc_SynchronizedDevice mCurrentDeviceData = chip_rpc_SynchronizedDevice_init_default;
100+
#endif
96101
UniqueIdGetter mUniqueIdGetter;
97102
};

0 commit comments

Comments
 (0)