Skip to content

Commit

Permalink
Fix iterator initialization for AdapterIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Feb 29, 2024
1 parent a054e7a commit b6137b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/platform/Linux/bluez/AdapterIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ CHIP_ERROR AdapterIterator::Initialize()
VerifyOrReturnError(mManager, CHIP_ERROR_INTERNAL,
ChipLogError(DeviceLayer, "Failed to get D-Bus object manager for listing adapters: %s", error->message));

mObjectList = BluezObjectList(mManager.get());
mIterator = mObjectList.begin();
mObjectList.Init(mManager.get());
mIterator = mObjectList.begin();

return CHIP_NO_ERROR;
}
Expand Down
22 changes: 14 additions & 8 deletions src/platform/Linux/bluez/BluezObjectList.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ namespace Internal {
class BluezObjectList
{
public:
explicit BluezObjectList(GDBusObjectManager * manager) { Initialize(manager); }
BluezObjectList() = default;
explicit BluezObjectList(GDBusObjectManager * manager) { Init(manager); }

~BluezObjectList() { g_list_free_full(mObjectList, g_object_unref); }

BluezObjectIterator begin() const { return BluezObjectIterator(mObjectList); }
static BluezObjectIterator end() { return BluezObjectIterator(); }
~BluezObjectList()
{
if (mObjectList != nullptr)
g_list_free_full(mObjectList, g_object_unref);
}

protected:
void Initialize(GDBusObjectManager * manager)
CHIP_ERROR Init(GDBusObjectManager * manager)
{
VerifyOrReturn(manager != nullptr, ChipLogError(DeviceLayer, "Manager is NULL in %s", __func__));
VerifyOrReturnError(manager != nullptr, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(DeviceLayer, "Manager is NULL in %s", __func__));
mObjectList = g_dbus_object_manager_get_objects(manager);
return CHIP_NO_ERROR;
}

BluezObjectIterator begin() const { return BluezObjectIterator(mObjectList); }
static BluezObjectIterator end() { return BluezObjectIterator(); }

private:
GList * mObjectList = nullptr;
};
Expand Down

0 comments on commit b6137b5

Please sign in to comment.