Skip to content

Commit

Permalink
Fix badly used MakeUniquePointerReceiver in gdbus fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DamMicSzm committed Sep 27, 2023
1 parent 5cdad62 commit ea7df3a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 39 deletions.
14 changes: 7 additions & 7 deletions src/platform/Linux/bluez/AdapterIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool AdapterIterator::Advance()
while (mCurrentListItem != nullptr)
{
GAutoPtr<BluezAdapter1> adapter(bluez_object_get_adapter1(BLUEZ_OBJECT(mCurrentListItem->data)));
if (MakeUniquePointerReceiver(adapter).Get() == nullptr)
if (adapter.get() == nullptr)
{
mCurrentListItem = mCurrentListItem->next;
continue;
Expand All @@ -93,7 +93,7 @@ bool AdapterIterator::Advance()
// PATH is of the for BLUEZ_PATH / hci<nr>, i.e. like
// '/org/bluez/hci0'
// Index represents the number after hci
const char * path = g_dbus_proxy_get_object_path(G_DBUS_PROXY(MakeUniquePointerReceiver(adapter).Get()));
const char * path = g_dbus_proxy_get_object_path(G_DBUS_PROXY(adapter.get()));
unsigned index = 0;

if (sscanf(path, BLUEZ_PATH "/hci%u", &index) != 1)
Expand All @@ -109,11 +109,11 @@ bool AdapterIterator::Advance()
}

mCurrent.index = index;
mCurrent.address = bluez_adapter1_get_address(MakeUniquePointerReceiver(adapter).Get());
mCurrent.alias = bluez_adapter1_get_alias(MakeUniquePointerReceiver(adapter).Get());
mCurrent.name = bluez_adapter1_get_name(MakeUniquePointerReceiver(adapter).Get());
mCurrent.powered = bluez_adapter1_get_powered(MakeUniquePointerReceiver(adapter).Get());
mCurrent.adapter = MakeUniquePointerReceiver(adapter).Get();
mCurrent.address = bluez_adapter1_get_address(adapter.get());
mCurrent.alias = bluez_adapter1_get_alias(adapter.get());
mCurrent.name = bluez_adapter1_get_name(adapter.get());
mCurrent.powered = bluez_adapter1_get_powered(adapter.get());
mCurrent.adapter = adapter.get();

mCurrentListItem = mCurrentListItem->next;

Expand Down
1 change: 0 additions & 1 deletion src/platform/Linux/bluez/AdapterIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <gio/gio.h>

#include "lib/core/CHIPError.h"
#include <platform/GLibTypeDeleter.h>

#include "Types.h"

Expand Down
6 changes: 3 additions & 3 deletions src/platform/Linux/bluez/ChipDeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ CHIP_ERROR ChipDeviceScanner::MainLoopStopScan(ChipDeviceScanner * self)
void ChipDeviceScanner::SignalObjectAdded(GDBusObjectManager * manager, GDBusObject * object, ChipDeviceScanner * self)
{
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(BLUEZ_OBJECT(object)));
VerifyOrReturn(MakeUniquePointerReceiver(device).Get() != nullptr);
VerifyOrReturn(device.get() != nullptr);

self->ReportDevice(*MakeUniquePointerReceiver(device).Get());
}
Expand All @@ -234,7 +234,7 @@ void ChipDeviceScanner::SignalInterfaceChanged(GDBusObjectManagerClient * manage
const gchar * const * aInvalidatedProps, ChipDeviceScanner * self)
{
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(BLUEZ_OBJECT(object)));
VerifyOrReturn(MakeUniquePointerReceiver(device).Get() != nullptr);
VerifyOrReturn(device.get() != nullptr);

self->ReportDevice(*MakeUniquePointerReceiver(device).Get());
}
Expand Down Expand Up @@ -292,7 +292,7 @@ CHIP_ERROR ChipDeviceScanner::MainLoopStartScan(ChipDeviceScanner * self)
for (BluezObject & object : BluezObjectList(self->mManager))
{
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(&object));
if (MakeUniquePointerReceiver(device).Get() != nullptr)
if (device.get() != nullptr)
{
self->RemoveDevice(*MakeUniquePointerReceiver(device).Get());
}
Expand Down
50 changes: 22 additions & 28 deletions src/platform/Linux/bluez/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,12 @@ static void BluezConnectionInit(BluezConnection * apConn)
BluezObject * object = BLUEZ_OBJECT(l->data);
GAutoPtr<BluezGattService1> service(bluez_object_get_gatt_service1(object));

if (MakeUniquePointerReceiver(service).Get() != nullptr)
if (service.get() != nullptr)
{
if ((BluezIsServiceOnDevice(MakeUniquePointerReceiver(service).Get(), apConn->mpDevice)) == TRUE &&
(strcmp(bluez_gatt_service1_get_uuid(MakeUniquePointerReceiver(service).Get()), CHIP_BLE_UUID_SERVICE_STRING) ==
0))
if ((BluezIsServiceOnDevice(service.get(), apConn->mpDevice)) == TRUE &&
(strcmp(bluez_gatt_service1_get_uuid(service.get()), CHIP_BLE_UUID_SERVICE_STRING) == 0))
{
apConn->mpService = MakeUniquePointerReceiver(service).Get();
apConn->mpService = service.get();
break;
}
}
Expand All @@ -717,25 +716,22 @@ static void BluezConnectionInit(BluezConnection * apConn)
BluezObject * object = BLUEZ_OBJECT(l->data);
GAutoPtr<BluezGattCharacteristic1> char1(bluez_object_get_gatt_characteristic1(object));

if (MakeUniquePointerReceiver(char1).Get() != nullptr)
if (char1.get() != nullptr)
{
if ((BluezIsCharOnService(MakeUniquePointerReceiver(char1).Get(), apConn->mpService) == TRUE) &&
(strcmp(bluez_gatt_characteristic1_get_uuid(MakeUniquePointerReceiver(char1).Get()),
CHIP_PLAT_BLE_UUID_C1_STRING) == 0))
if ((BluezIsCharOnService(char1.get(), apConn->mpService) == TRUE) &&
(strcmp(bluez_gatt_characteristic1_get_uuid((char1).get()), CHIP_PLAT_BLE_UUID_C1_STRING) == 0))
{
apConn->mpC1 = MakeUniquePointerReceiver(char1).Get();
apConn->mpC1 = char1.get();
}
else if ((BluezIsCharOnService(MakeUniquePointerReceiver(char1).Get(), apConn->mpService) == TRUE) &&
(strcmp(bluez_gatt_characteristic1_get_uuid(MakeUniquePointerReceiver(char1).Get()),
CHIP_PLAT_BLE_UUID_C2_STRING) == 0))
else if ((BluezIsCharOnService(char1.get(), apConn->mpService) == TRUE) &&
(strcmp(bluez_gatt_characteristic1_get_uuid((char1).get()), CHIP_PLAT_BLE_UUID_C2_STRING) == 0))
{
apConn->mpC2 = MakeUniquePointerReceiver(char1).Get();
apConn->mpC2 = char1.get();
}
else if ((BluezIsCharOnService(MakeUniquePointerReceiver(char1).Get(), apConn->mpService) == TRUE) &&
(strcmp(bluez_gatt_characteristic1_get_uuid(MakeUniquePointerReceiver(char1).Get()),
CHIP_PLAT_BLE_UUID_C3_STRING) == 0))
else if ((BluezIsCharOnService(char1.get(), apConn->mpService) == TRUE) &&
(strcmp(bluez_gatt_characteristic1_get_uuid((char1).get()), CHIP_PLAT_BLE_UUID_C3_STRING) == 0))
{
apConn->mpC3 = MakeUniquePointerReceiver(char1).Get();
apConn->mpC3 = char1.get();
}
if ((apConn->mpC1 != nullptr) && (apConn->mpC2 != nullptr))
{
Expand Down Expand Up @@ -948,14 +944,14 @@ static void BluezSignalOnObjectAdded(GDBusObjectManager * aManager, GDBusObject
// TODO: right now we do not handle addition/removal of adapters
// Primary focus here is to handle addition of a device
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(BLUEZ_OBJECT(aObject)));
if (MakeUniquePointerReceiver(device).Get() == nullptr)
if (device.get() == nullptr)
{
return;
}

if (BluezIsDeviceOnAdapter(MakeUniquePointerReceiver(device).Get(), endpoint->mpAdapter) == TRUE)
if (BluezIsDeviceOnAdapter(device.get(), endpoint->mpAdapter) == TRUE)
{
BluezHandleNewDevice(MakeUniquePointerReceiver(device).Get(), endpoint);
BluezHandleNewDevice(device.get(), endpoint);
}
}

Expand Down Expand Up @@ -1077,21 +1073,19 @@ static BluezConnection * BluezCharacteristicGetBluezConnection(BluezGattCharacte
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(BLUEZ_OBJECT(l->data)));
if (device != nullptr)
{
if (BluezIsDeviceOnAdapter(MakeUniquePointerReceiver(device).Get(), apEndpoint->mpAdapter))
if (BluezIsDeviceOnAdapter(device.get(), apEndpoint->mpAdapter))
{
for (ll = objects; ll != nullptr; ll = ll->next)
{
GAutoPtr<BluezGattService1> service(bluez_object_get_gatt_service1(BLUEZ_OBJECT(ll->data)));
if (MakeUniquePointerReceiver(service).Get() != nullptr)
if (service.get() != nullptr)
{
if (BluezIsServiceOnDevice(MakeUniquePointerReceiver(service).Get(),
MakeUniquePointerReceiver(device).Get()))
if (BluezIsServiceOnDevice(service.get(), device.get()))
{
if (BluezIsCharOnService(aChar, MakeUniquePointerReceiver(service).Get()))
if (BluezIsCharOnService(aChar, service.get()))
{
retval = static_cast<BluezConnection *>(g_hash_table_lookup(
apEndpoint->mpConnMap,
g_dbus_proxy_get_object_path(G_DBUS_PROXY(MakeUniquePointerReceiver(device).Get()))));
apEndpoint->mpConnMap, g_dbus_proxy_get_object_path(G_DBUS_PROXY(device.get()))));
}
}
if (retval != nullptr)
Expand Down

0 comments on commit ea7df3a

Please sign in to comment.