Skip to content

Commit c158260

Browse files
authored
[Fabric-Bridge] Don't track device changes for synced devices (#33769)
* Don't track device change status for synced devices * Address review comments
1 parent 5ee4ef6 commit c158260

File tree

5 files changed

+41
-44
lines changed

5 files changed

+41
-44
lines changed

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

+8-23
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525

2626
using namespace chip::app::Clusters::Actions;
2727

28-
Device::Device(const char * szDeviceName, std::string szLocation)
28+
Device::Device(chip::NodeId nodeId, const char * name)
2929
{
30-
chip::Platform::CopyString(mName, szDeviceName);
31-
mLocation = szLocation;
30+
chip::Platform::CopyString(mName, name);
3231
mReachable = false;
3332
mEndpointId = 0;
3433
}
@@ -38,37 +37,23 @@ bool Device::IsReachable()
3837
return mReachable;
3938
}
4039

41-
void Device::SetReachable(bool aReachable)
40+
void Device::SetReachable(bool reachable)
4241
{
43-
bool changed = (mReachable != aReachable);
42+
mReachable = reachable;
4443

45-
mReachable = aReachable;
46-
47-
if (aReachable)
44+
if (reachable)
4845
{
4946
ChipLogProgress(NotSpecified, "Device[%s]: ONLINE", mName);
5047
}
5148
else
5249
{
5350
ChipLogProgress(NotSpecified, "Device[%s]: OFFLINE", mName);
5451
}
55-
56-
if (changed)
57-
{
58-
HandleDeviceChange(this, kChanged_Reachable);
59-
}
6052
}
6153

62-
void Device::SetName(const char * szName)
54+
void Device::SetName(const char * name)
6355
{
64-
bool changed = (strncmp(mName, szName, sizeof(mName)) != 0);
56+
ChipLogProgress(NotSpecified, "Device[%s]: New Name=\"%s\"", mName, name);
6557

66-
ChipLogProgress(NotSpecified, "Device[%s]: New Name=\"%s\"", mName, szName);
67-
68-
chip::Platform::CopyString(mName, szName);
69-
70-
if (changed)
71-
{
72-
HandleDeviceChange(this, kChanged_Name);
73-
}
58+
chip::Platform::CopyString(mName, name);
7459
}

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ using namespace chip::DeviceLayer;
4444
using namespace chip::app::Clusters;
4545

4646
namespace {
47+
4748
constexpr uint8_t kMaxRetries = 10;
49+
4850
} // namespace
4951

50-
DeviceManager::DeviceManager()
52+
// Define the static member
53+
DeviceManager DeviceManager::sInstance;
54+
55+
void DeviceManager::Init()
5156
{
5257
memset(mDevices, 0, sizeof(mDevices));
5358
mFirstDynamicEndpointId = static_cast<chip::EndpointId>(

examples/fabric-bridge-app/linux/include/Device.h

+5-15
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,13 @@ class Device
3232
public:
3333
static const int kDeviceNameSize = 32;
3434

35-
enum Changed_t
36-
{
37-
kChanged_Reachable = 1u << 0,
38-
kChanged_Location = 1u << 1,
39-
kChanged_Name = 1u << 2,
40-
kChanged_Last = kChanged_Name,
41-
} Changed;
42-
43-
Device(const char * szDeviceName, std::string szLocation);
35+
Device(chip::NodeId nodeId, const char * name);
4436
virtual ~Device() {}
4537

4638
bool IsReachable();
47-
void SetReachable(bool aReachable);
48-
void SetName(const char * szDeviceName);
49-
void SetLocation(std::string szLocation);
39+
void SetReachable(bool reachable);
40+
void SetName(const char * name);
41+
void SetLocation(std::string location) { mLocation = location; };
5042
inline void SetEndpointId(chip::EndpointId id) { mEndpointId = id; };
5143
inline chip::EndpointId GetEndpointId() { return mEndpointId; };
5244
inline void SetParentEndpointId(chip::EndpointId id) { mParentEndpointId = id; };
@@ -56,13 +48,11 @@ class Device
5648
inline std::string GetZone() { return mZone; };
5749
inline void SetZone(std::string zone) { mZone = zone; };
5850

59-
private:
60-
virtual void HandleDeviceChange(Device * device, Device::Changed_t changeMask) = 0;
61-
6251
protected:
6352
bool mReachable;
6453
char mName[kDeviceNameSize];
6554
std::string mLocation;
55+
chip::NodeId mNodeId;
6656
chip::EndpointId mEndpointId;
6757
chip::EndpointId mParentEndpointId;
6858
std::string mZone;

examples/fabric-bridge-app/linux/include/DeviceManager.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
class DeviceManager
2626
{
2727
public:
28-
DeviceManager();
28+
DeviceManager() = default;
29+
30+
void Init();
2931

3032
/**
3133
* @brief Adds a device to a dynamic endpoint.
@@ -62,7 +64,22 @@ class DeviceManager
6264
Device * GetDevice(uint16_t index) const;
6365

6466
private:
67+
friend DeviceManager & DeviceMgr();
68+
69+
static DeviceManager sInstance;
70+
6571
chip::EndpointId mCurrentEndpointId;
6672
chip::EndpointId mFirstDynamicEndpointId;
6773
Device * mDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
6874
};
75+
76+
/**
77+
* Returns the public interface of the DeviceManager singleton object.
78+
*
79+
* Applications should use this to access features of the DeviceManager
80+
* object.
81+
*/
82+
inline DeviceManager & DeviceMgr()
83+
{
84+
return DeviceManager::sInstance;
85+
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ void AttemptRpcClientConnect(System::Layer * systemLayer, void * appState)
9797
}
9898
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
9999

100-
DeviceManager gDeviceManager;
101-
102100
} // namespace
103101

104102
void ApplicationInit()
@@ -111,6 +109,8 @@ void ApplicationInit()
111109
// Start a thread for bridge polling
112110
std::thread pollingThread(BridgePollingThread);
113111
pollingThread.detach();
112+
113+
DeviceMgr().Init();
114114
}
115115

116116
void ApplicationShutdown() {}
@@ -135,7 +135,7 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
135135
uint16_t endpointIndex = emberAfGetDynamicIndexFromEndpoint(endpoint);
136136
AttributeId attributeId = attributeMetadata->attributeId;
137137

138-
Device * dev = gDeviceManager.GetDevice(endpointIndex);
138+
Device * dev = DeviceMgr().GetDevice(endpointIndex);
139139
if (dev != nullptr && clusterId == app::Clusters::BridgedDeviceBasicInformation::Id)
140140
{
141141
using namespace app::Clusters::BridgedDeviceBasicInformation::Attributes;
@@ -179,7 +179,7 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi
179179
uint16_t endpointIndex = emberAfGetDynamicIndexFromEndpoint(endpoint);
180180
Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Failure;
181181

182-
Device * dev = gDeviceManager.GetDevice(endpointIndex);
182+
Device * dev = DeviceMgr().GetDevice(endpointIndex);
183183
if (dev != nullptr && dev->IsReachable())
184184
{
185185
ChipLogProgress(NotSpecified, "emberAfExternalAttributeWriteCallback: ep=%d, clusterId=%d", endpoint, clusterId);

0 commit comments

Comments
 (0)