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] Use reinterpret_cast<> for trivial glib casting #32376

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/platform/Linux/bluez/BluezAdvertisement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void BluezAdvertisement::Shutdown()

void BluezAdvertisement::StartDone(GObject * aObject, GAsyncResult * aResult)
{
BluezLEAdvertisingManager1 * advMgr = BLUEZ_LEADVERTISING_MANAGER1(aObject);
auto * advMgr = reinterpret_cast<BluezLEAdvertisingManager1 *>(aObject);
GAutoPtr<GError> error;
gboolean success = FALSE;

Expand Down Expand Up @@ -252,7 +252,7 @@ CHIP_ERROR BluezAdvertisement::StartImpl()
adapterObject = g_dbus_interface_get_object(G_DBUS_INTERFACE(mAdapter.get()));
VerifyOrExit(adapterObject != nullptr, ChipLogError(DeviceLayer, "FAIL: NULL adapterObject in %s", __func__));

advMgr.reset(bluez_object_get_leadvertising_manager1(BLUEZ_OBJECT(adapterObject)));
advMgr.reset(bluez_object_get_leadvertising_manager1(reinterpret_cast<BluezObject *>(adapterObject)));
VerifyOrExit(advMgr.get() != nullptr, ChipLogError(DeviceLayer, "FAIL: NULL advMgr in %s", __func__));

g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE("a{sv}"));
Expand Down Expand Up @@ -282,7 +282,7 @@ CHIP_ERROR BluezAdvertisement::Start()

void BluezAdvertisement::StopDone(GObject * aObject, GAsyncResult * aResult)
{
BluezLEAdvertisingManager1 * advMgr = BLUEZ_LEADVERTISING_MANAGER1(aObject);
auto * advMgr = reinterpret_cast<BluezLEAdvertisingManager1 *>(aObject);
GAutoPtr<GError> error;
gboolean success = FALSE;

Expand All @@ -308,7 +308,7 @@ CHIP_ERROR BluezAdvertisement::StopImpl()
adapterObject = g_dbus_interface_get_object(G_DBUS_INTERFACE(mAdapter.get()));
VerifyOrExit(adapterObject != nullptr, ChipLogError(DeviceLayer, "FAIL: NULL adapterObject in %s", __func__));

advMgr.reset(bluez_object_get_leadvertising_manager1(BLUEZ_OBJECT(adapterObject)));
advMgr.reset(bluez_object_get_leadvertising_manager1(reinterpret_cast<BluezObject *>(adapterObject)));
VerifyOrExit(advMgr.get() != nullptr, ChipLogError(DeviceLayer, "FAIL: NULL advMgr in %s", __func__));

bluez_leadvertising_manager1_call_unregister_advertisement(
Expand Down
31 changes: 17 additions & 14 deletions src/platform/Linux/bluez/BluezConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ CHIP_ERROR BluezConnection::SendIndication(chip::System::PacketBufferHandle apBu

void BluezConnection::SendWriteRequestDone(GObject * aObject, GAsyncResult * aResult, gpointer apConnection)
{
BluezGattCharacteristic1 * c1 = BLUEZ_GATT_CHARACTERISTIC1(aObject);
auto * pC1 = reinterpret_cast<BluezGattCharacteristic1 *>(aObject);

GAutoPtr<GError> error;
gboolean success = bluez_gatt_characteristic1_call_write_value_finish(c1, aResult, &error.GetReceiver());
gboolean success = bluez_gatt_characteristic1_call_write_value_finish(pC1, aResult, &error.GetReceiver());

VerifyOrReturn(success == TRUE, ChipLogError(DeviceLayer, "FAIL: SendWriteRequest : %s", error->message));
BLEManagerImpl::HandleWriteComplete(static_cast<BluezConnection *>(apConnection));
Expand Down Expand Up @@ -354,9 +355,10 @@ void BluezConnection::OnCharacteristicChanged(GDBusProxy * aInterface, GVariant

void BluezConnection::SubscribeCharacteristicDone(GObject * aObject, GAsyncResult * aResult, gpointer apConnection)
{
BluezGattCharacteristic1 * c2 = BLUEZ_GATT_CHARACTERISTIC1(aObject);
auto * pC2 = reinterpret_cast<BluezGattCharacteristic1 *>(aObject);

GAutoPtr<GError> error;
gboolean success = bluez_gatt_characteristic1_call_write_value_finish(c2, aResult, &error.GetReceiver());
gboolean success = bluez_gatt_characteristic1_call_write_value_finish(pC2, aResult, &error.GetReceiver());

VerifyOrReturn(success == TRUE, ChipLogError(DeviceLayer, "FAIL: SubscribeCharacteristic : %s", error->message));

Expand All @@ -365,13 +367,12 @@ void BluezConnection::SubscribeCharacteristicDone(GObject * aObject, GAsyncResul

CHIP_ERROR BluezConnection::SubscribeCharacteristicImpl(BluezConnection * connection)
{
BluezGattCharacteristic1 * c2 = nullptr;
VerifyOrExit(connection->mpC2 != nullptr, ChipLogError(DeviceLayer, "C2 is NULL in %s", __func__));
c2 = BLUEZ_GATT_CHARACTERISTIC1(connection->mpC2);
BluezGattCharacteristic1 * pC2 = connection->mpC2;
VerifyOrExit(pC2 != nullptr, ChipLogError(DeviceLayer, "C2 is NULL in %s", __func__));

// Get notifications on the TX characteristic change (e.g. indication is received)
g_signal_connect(c2, "g-properties-changed", G_CALLBACK(OnCharacteristicChanged), connection);
bluez_gatt_characteristic1_call_start_notify(connection->mpC2, nullptr, SubscribeCharacteristicDone, connection);
g_signal_connect(pC2, "g-properties-changed", G_CALLBACK(OnCharacteristicChanged), connection);
bluez_gatt_characteristic1_call_start_notify(pC2, nullptr, SubscribeCharacteristicDone, connection);

exit:
return CHIP_NO_ERROR;
Expand All @@ -386,22 +387,24 @@ CHIP_ERROR BluezConnection::SubscribeCharacteristic()

void BluezConnection::UnsubscribeCharacteristicDone(GObject * aObject, GAsyncResult * aResult, gpointer apConnection)
{
BluezGattCharacteristic1 * c2 = BLUEZ_GATT_CHARACTERISTIC1(aObject);
auto * pC2 = reinterpret_cast<BluezGattCharacteristic1 *>(aObject);

GAutoPtr<GError> error;
gboolean success = bluez_gatt_characteristic1_call_write_value_finish(c2, aResult, &error.GetReceiver());
gboolean success = bluez_gatt_characteristic1_call_write_value_finish(pC2, aResult, &error.GetReceiver());

VerifyOrReturn(success == TRUE, ChipLogError(DeviceLayer, "FAIL: UnsubscribeCharacteristic : %s", error->message));

// Stop listening to the TX characteristic changes
g_signal_handlers_disconnect_by_data(c2, apConnection);
g_signal_handlers_disconnect_by_data(pC2, apConnection);
BLEManagerImpl::HandleSubscribeOpComplete(static_cast<BluezConnection *>(apConnection), false);
}

CHIP_ERROR BluezConnection::UnsubscribeCharacteristicImpl(BluezConnection * connection)
{
VerifyOrExit(connection->mpC2 != nullptr, ChipLogError(DeviceLayer, "C2 is NULL in %s", __func__));
BluezGattCharacteristic1 * pC2 = connection->mpC2;
VerifyOrExit(pC2 != nullptr, ChipLogError(DeviceLayer, "C2 is NULL in %s", __func__));

bluez_gatt_characteristic1_call_stop_notify(connection->mpC2, nullptr, UnsubscribeCharacteristicDone, connection);
bluez_gatt_characteristic1_call_stop_notify(pC2, nullptr, UnsubscribeCharacteristicDone, connection);

exit:
return CHIP_NO_ERROR;
Expand Down
9 changes: 4 additions & 5 deletions src/platform/Linux/bluez/BluezEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ BluezGattCharacteristic1 * BluezEndpoint::CreateGattCharacteristic(BluezGattServ
void BluezEndpoint::RegisterGattApplicationDone(GObject * aObject, GAsyncResult * aResult)
{
GAutoPtr<GError> error;
BluezGattManager1 * gattMgr = BLUEZ_GATT_MANAGER1(aObject);

gboolean success = bluez_gatt_manager1_call_register_application_finish(gattMgr, aResult, &error.GetReceiver());
gboolean success = bluez_gatt_manager1_call_register_application_finish(reinterpret_cast<BluezGattManager1 *>(aObject), aResult,
&error.GetReceiver());

VerifyOrReturn(success == TRUE, {
ChipLogError(DeviceLayer, "FAIL: RegisterApplication : %s", error->message);
Expand All @@ -287,7 +286,7 @@ CHIP_ERROR BluezEndpoint::RegisterGattApplicationImpl()
adapterObject = g_dbus_interface_get_object(G_DBUS_INTERFACE(mAdapter.get()));
VerifyOrExit(adapterObject != nullptr, ChipLogError(DeviceLayer, "FAIL: NULL adapterObject in %s", __func__));

gattMgr.reset(bluez_object_get_gatt_manager1(BLUEZ_OBJECT(adapterObject)));
gattMgr.reset(bluez_object_get_gatt_manager1(reinterpret_cast<BluezObject *>(adapterObject)));
VerifyOrExit(gattMgr.get() != nullptr, ChipLogError(DeviceLayer, "FAIL: NULL gattMgr in %s", __func__));

g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE("a{sv}"));
Expand Down Expand Up @@ -383,7 +382,7 @@ void BluezEndpoint::BluezSignalOnObjectAdded(GDBusObjectManager * aManager, GDBu
{
// 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)));
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(reinterpret_cast<BluezObject *>(aObject)));
VerifyOrReturn(device.get() != nullptr);

if (BluezIsDeviceOnAdapter(device.get(), mAdapter.get()) == TRUE)
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Linux/bluez/BluezObjectIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class BluezObjectIterator
BluezObjectIterator() = default;
explicit BluezObjectIterator(GList * position) : mPosition(position) {}

reference operator*() const { return *BLUEZ_OBJECT(mPosition->data); }
pointer operator->() const { return BLUEZ_OBJECT(mPosition->data); }
reference operator*() const { return *reinterpret_cast<BluezObject *>(mPosition->data); }
pointer operator->() const { return reinterpret_cast<BluezObject *>(mPosition->data); }
bool operator==(const BluezObjectIterator & other) const { return mPosition == other.mPosition; }
bool operator!=(const BluezObjectIterator & other) const { return mPosition != other.mPosition; }

Expand Down
4 changes: 2 additions & 2 deletions src/platform/Linux/bluez/ChipDeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,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)));
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(reinterpret_cast<BluezObject *>(object)));
VerifyOrReturn(device.get() != nullptr);

self->ReportDevice(*device.get());
Expand All @@ -225,7 +225,7 @@ void ChipDeviceScanner::SignalInterfaceChanged(GDBusObjectManagerClient * manage
GDBusProxy * aInterface, GVariant * aChangedProperties,
const gchar * const * aInvalidatedProps, ChipDeviceScanner * self)
{
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(BLUEZ_OBJECT(object)));
GAutoPtr<BluezDevice1> device(bluez_object_get_device1(reinterpret_cast<BluezObject *>(object)));
VerifyOrReturn(device.get() != nullptr);

self->ReportDevice(*device.get());
Expand Down
Loading