@@ -307,7 +307,7 @@ CHIP_ERROR BluezEndpoint::RegisterGattApplicationImpl()
307
307
// / Update the table of open BLE connections whenever a new device is spotted or its attributes have changed.
308
308
void BluezEndpoint::UpdateConnectionTable (BluezDevice1 * apDevice)
309
309
{
310
- const char * objectPath = g_dbus_proxy_get_object_path (G_DBUS_PROXY (apDevice));
310
+ const char * objectPath = g_dbus_proxy_get_object_path (reinterpret_cast <GDBusProxy *> (apDevice));
311
311
BluezConnection * connection = GetBluezConnection (objectPath);
312
312
313
313
if (connection != nullptr && !bluez_device1_get_connected (apDevice))
@@ -321,22 +321,9 @@ void BluezEndpoint::UpdateConnectionTable(BluezDevice1 * apDevice)
321
321
return ;
322
322
}
323
323
324
- if (connection == nullptr && ! bluez_device1_get_connected (apDevice) && mIsCentral )
324
+ if (connection == nullptr )
325
325
{
326
- return ;
327
- }
328
-
329
- if (connection == nullptr && bluez_device1_get_connected (apDevice) &&
330
- (!mIsCentral || bluez_device1_get_services_resolved (apDevice)))
331
- {
332
- connection = chip::Platform::New<BluezConnection>(*this , apDevice);
333
- mpPeerDevicePath = g_strdup (objectPath);
334
- mConnMap [mpPeerDevicePath] = connection;
335
-
336
- ChipLogDetail (DeviceLayer, " New BLE connection: conn %p, device %s, path %s" , connection, connection->GetPeerAddress (),
337
- mpPeerDevicePath);
338
-
339
- BLEManagerImpl::HandleNewConnection (connection);
326
+ HandleNewDevice (apDevice);
340
327
}
341
328
}
342
329
@@ -355,28 +342,22 @@ void BluezEndpoint::BluezSignalInterfacePropertiesChanged(GDBusObjectManagerClie
355
342
356
343
void BluezEndpoint::HandleNewDevice (BluezDevice1 * device)
357
344
{
358
- VerifyOrReturn (!mIsCentral );
359
-
360
- // We need to handle device connection both this function and BluezSignalInterfacePropertiesChanged
361
- // When a device is connected for first time, this function will be triggered.
362
- // The future connections for the same device will trigger ``Connect'' property change.
363
- // TODO: Factor common code in the two function.
364
- BluezConnection * conn;
365
- VerifyOrExit (bluez_device1_get_connected (device), ChipLogError (DeviceLayer, " FAIL: device is not connected" ));
345
+ VerifyOrReturn (bluez_device1_get_connected (device));
346
+ VerifyOrReturn (!mIsCentral || bluez_device1_get_services_resolved (device));
366
347
367
- conn = GetBluezConnection (g_dbus_proxy_get_object_path (G_DBUS_PROXY (device)));
368
- VerifyOrExit (conn == nullptr ,
369
- ChipLogError (DeviceLayer, " FAIL: connection already tracked: conn: %p new device: %s" , conn,
370
- g_dbus_proxy_get_object_path (G_DBUS_PROXY (device))));
348
+ const char * objectPath = g_dbus_proxy_get_object_path (reinterpret_cast <GDBusProxy *>(device));
349
+ BluezConnection * conn = GetBluezConnection (objectPath);
350
+ VerifyOrReturn (conn == nullptr ,
351
+ ChipLogError (DeviceLayer, " FAIL: Connection already tracked: conn=%p device=%s path=%s" , conn,
352
+ conn->GetPeerAddress (), objectPath));
371
353
372
354
conn = chip::Platform::New<BluezConnection>(*this , device);
373
- mpPeerDevicePath = g_strdup (g_dbus_proxy_get_object_path ( G_DBUS_PROXY (device)) );
355
+ mpPeerDevicePath = g_strdup (objectPath );
374
356
mConnMap [mpPeerDevicePath] = conn;
375
357
376
- ChipLogDetail (DeviceLayer, " BLE device connected : conn %p, device %s, path %s" , conn, conn->GetPeerAddress (), mpPeerDevicePath );
358
+ ChipLogDetail (DeviceLayer, " New BLE connection : conn=%p device=%s path= %s" , conn, conn->GetPeerAddress (), objectPath );
377
359
378
- exit :
379
- return ;
360
+ BLEManagerImpl::HandleNewConnection (conn);
380
361
}
381
362
382
363
void BluezEndpoint::BluezSignalOnObjectAdded (GDBusObjectManager * aManager, GDBusObject * aObject)
0 commit comments