Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] Initial implementation of fabric-bridge for fabric sync #33284

Merged
merged 5 commits into from
May 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a maximum number of retries to exit the loop more reliably
  • Loading branch information
yufengwangca committed May 6, 2024
commit 19525fc757acbf78ffd3cf798a6799207d7426ae
15 changes: 9 additions & 6 deletions examples/fabric-bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,17 @@ Device * gDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const EmberAfDeviceType> & deviceTypeList,
const Span<DataVersion> & dataVersionStorage, chip::EndpointId parentEndpointId = chip::kInvalidEndpointId)
{
uint8_t index = 0;
uint8_t index = 0;
const int maxRetries = 10; // Set the maximum number of retries
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
{
if (nullptr == gDevices[index])
{
gDevices[index] = dev;
CHIP_ERROR err;
while (true)
int retryCount = 0;
while (retryCount < maxRetries)
{
// Todo: Update this to schedule the work rather than use this lock
DeviceLayer::StackLock lock;
dev->SetEndpointId(gCurrentEndpointId);
dev->SetParentEndpointId(parentEndpointId);
Expand All @@ -105,14 +106,17 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
}
if (err != CHIP_ERROR_ENDPOINT_EXISTS)
{
return -1;
return -1; // Return error as endpoint addition failed due to an error other than endpoint already exists
}
// Handle wrap condition
// Increment the endpoint ID and handle wrap condition
if (++gCurrentEndpointId < gFirstDynamicEndpointId)
{
gCurrentEndpointId = gFirstDynamicEndpointId;
}
retryCount++;
}
ChipLogError(DeviceLayer, "Failed to add dynamic endpoint after %d retries", maxRetries);
return -1; // Return error as all retries are exhausted
}
index++;
}
Expand All @@ -127,7 +131,6 @@ int RemoveDeviceEndpoint(Device * dev)
{
if (gDevices[index] == dev)
{
// Todo: Update this to schedule the work rather than use this lock
DeviceLayer::StackLock lock;
// Silence complaints about unused ep when progress logging
// disabled.
Expand Down
Loading