@@ -61,26 +61,11 @@ gboolean BluezIsCharOnService(BluezGattCharacteristic1 * aChar, BluezGattService
61
61
} // namespace
62
62
63
63
BluezConnection::BluezConnection (const BluezEndpoint & aEndpoint, BluezDevice1 * apDevice) :
64
- mpDevice (reinterpret_cast <BluezDevice1 *>(g_object_ref(apDevice)))
64
+ mDevice (reinterpret_cast <BluezDevice1 *>(g_object_ref(apDevice)))
65
65
{
66
66
Init (aEndpoint);
67
67
}
68
68
69
- BluezConnection::~BluezConnection ()
70
- {
71
- g_object_unref (mpDevice);
72
- if (mpService)
73
- g_object_unref (mpService);
74
- if (mpC1)
75
- g_object_unref (mpC1);
76
- if (mpC2)
77
- g_object_unref (mpC2);
78
- #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
79
- if (mpC3)
80
- g_object_unref (mpC2);
81
- #endif
82
- }
83
-
84
69
BluezConnection::IOChannel::~IOChannel ()
85
70
{
86
71
if (mWatchSource != nullptr )
@@ -98,64 +83,64 @@ CHIP_ERROR BluezConnection::Init(const BluezEndpoint & aEndpoint)
98
83
{
99
84
if (!aEndpoint.mIsCentral )
100
85
{
101
- mpService = reinterpret_cast <BluezGattService1 *>(g_object_ref (aEndpoint.mpService ));
102
- mpC1 = reinterpret_cast <BluezGattCharacteristic1 *>(g_object_ref (aEndpoint.mpC1 ));
103
- mpC2 = reinterpret_cast <BluezGattCharacteristic1 *>(g_object_ref (aEndpoint.mpC2 ));
86
+ mService . reset ( reinterpret_cast <BluezGattService1 *>(g_object_ref (aEndpoint.mService . get ()) ));
87
+ mC1 . reset ( reinterpret_cast <BluezGattCharacteristic1 *>(g_object_ref (aEndpoint.mC1 . get ()) ));
88
+ mC2 . reset ( reinterpret_cast <BluezGattCharacteristic1 *>(g_object_ref (aEndpoint.mC2 . get ()) ));
104
89
}
105
90
else
106
91
{
107
- for (BluezObject & object : BluezObjectList (aEndpoint.mpObjMgr ))
92
+ for (BluezObject & object : BluezObjectList (aEndpoint.mObjMgr . get () ))
108
93
{
109
94
BluezGattService1 * service = bluez_object_get_gatt_service1 (&object);
110
95
if (service != nullptr )
111
96
{
112
- if ((BluezIsServiceOnDevice (service, mpDevice )) == TRUE &&
97
+ if ((BluezIsServiceOnDevice (service, mDevice . get () )) == TRUE &&
113
98
(strcmp (bluez_gatt_service1_get_uuid (service), CHIP_BLE_UUID_SERVICE_STRING) == 0 ))
114
99
{
115
- mpService = service;
100
+ mService . reset ( service) ;
116
101
break ;
117
102
}
118
103
g_object_unref (service);
119
104
}
120
105
}
121
106
122
- VerifyOrExit (mpService != nullptr , ChipLogError (DeviceLayer, " FAIL: NULL service in %s" , __func__));
107
+ VerifyOrExit (mService , ChipLogError (DeviceLayer, " FAIL: NULL service in %s" , __func__));
123
108
124
- for (BluezObject & object : BluezObjectList (aEndpoint.mpObjMgr ))
109
+ for (BluezObject & object : BluezObjectList (aEndpoint.mObjMgr . get () ))
125
110
{
126
111
BluezGattCharacteristic1 * char1 = bluez_object_get_gatt_characteristic1 (&object);
127
112
if (char1 != nullptr )
128
113
{
129
- if ((BluezIsCharOnService (char1, mpService ) == TRUE ) &&
114
+ if ((BluezIsCharOnService (char1, mService . get () ) == TRUE ) &&
130
115
(strcmp (bluez_gatt_characteristic1_get_uuid (char1), CHIP_PLAT_BLE_UUID_C1_STRING) == 0 ))
131
116
{
132
- mpC1 = char1;
117
+ mC1 . reset ( char1) ;
133
118
}
134
- else if ((BluezIsCharOnService (char1, mpService ) == TRUE ) &&
119
+ else if ((BluezIsCharOnService (char1, mService . get () ) == TRUE ) &&
135
120
(strcmp (bluez_gatt_characteristic1_get_uuid (char1), CHIP_PLAT_BLE_UUID_C2_STRING) == 0 ))
136
121
{
137
- mpC2 = char1;
122
+ mC2 . reset ( char1) ;
138
123
}
139
124
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
140
- else if ((BluezIsCharOnService (char1, mpService ) == TRUE ) &&
125
+ else if ((BluezIsCharOnService (char1, mService . get () ) == TRUE ) &&
141
126
(strcmp (bluez_gatt_characteristic1_get_uuid (char1), CHIP_PLAT_BLE_UUID_C3_STRING) == 0 ))
142
127
{
143
- mpC3 = char1;
128
+ mC3 . reset ( char1) ;
144
129
}
145
130
#endif
146
131
else
147
132
{
148
133
g_object_unref (char1);
149
134
}
150
- if ((mpC1 != nullptr ) && (mpC2 != nullptr ) )
135
+ if (mC1 && mC2 )
151
136
{
152
137
break ;
153
138
}
154
139
}
155
140
}
156
141
157
- VerifyOrExit (mpC1 != nullptr , ChipLogError (DeviceLayer, " FAIL: NULL C1 in %s" , __func__));
158
- VerifyOrExit (mpC2 != nullptr , ChipLogError (DeviceLayer, " FAIL: NULL C2 in %s" , __func__));
142
+ VerifyOrExit (mC1 , ChipLogError (DeviceLayer, " FAIL: NULL C1 in %s" , __func__));
143
+ VerifyOrExit (mC2 , ChipLogError (DeviceLayer, " FAIL: NULL C2 in %s" , __func__));
159
144
}
160
145
161
146
exit :
@@ -169,7 +154,7 @@ CHIP_ERROR BluezConnection::BluezDisconnect(BluezConnection * conn)
169
154
170
155
ChipLogDetail (DeviceLayer, " %s peer=%s" , __func__, conn->GetPeerAddress ());
171
156
172
- success = bluez_device1_call_disconnect_sync (conn->mpDevice , nullptr , &error.GetReceiver ());
157
+ success = bluez_device1_call_disconnect_sync (conn->mDevice . get () , nullptr , &error.GetReceiver ());
173
158
VerifyOrExit (success == TRUE , ChipLogError (DeviceLayer, " FAIL: Disconnect: %s" , error->message ));
174
159
175
160
exit :
@@ -183,7 +168,7 @@ CHIP_ERROR BluezConnection::CloseConnection()
183
168
184
169
const char * BluezConnection::GetPeerAddress () const
185
170
{
186
- return bluez_device1_get_address (mpDevice );
171
+ return bluez_device1_get_address (mDevice . get () );
187
172
}
188
173
189
174
gboolean BluezConnection::WriteHandlerCallback (GIOChannel * aChannel, GIOCondition aCond, BluezConnection * apConn)
@@ -205,7 +190,7 @@ gboolean BluezConnection::WriteHandlerCallback(GIOChannel * aChannel, GIOConditi
205
190
// Casting len to size_t is safe, since we ensured that it's not negative.
206
191
newVal = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, buf, static_cast <size_t >(len), sizeof (uint8_t ));
207
192
208
- bluez_gatt_characteristic1_set_value (apConn->mpC1 , newVal);
193
+ bluez_gatt_characteristic1_set_value (apConn->mC1 . get () , newVal);
209
194
BLEManagerImpl::HandleRXCharWrite (apConn, buf, static_cast <size_t >(len));
210
195
isSuccess = true ;
211
196
@@ -267,7 +252,7 @@ CHIP_ERROR BluezConnection::SendIndicationImpl(ConnectionDataBundle * data)
267
252
GAutoPtr<GError> error;
268
253
size_t len, written;
269
254
270
- if (bluez_gatt_characteristic1_get_notify_acquired (data->mConn .mpC2 ) == TRUE )
255
+ if (bluez_gatt_characteristic1_get_notify_acquired (data->mConn .mC2 . get () ) == TRUE )
271
256
{
272
257
auto * buf = static_cast <const char *>(g_variant_get_fixed_array (data->mData .get (), &len, sizeof (uint8_t )));
273
258
VerifyOrExit (len <= static_cast <size_t >(std::numeric_limits<gssize>::max ()),
@@ -278,7 +263,7 @@ CHIP_ERROR BluezConnection::SendIndicationImpl(ConnectionDataBundle * data)
278
263
}
279
264
else
280
265
{
281
- bluez_gatt_characteristic1_set_value (data->mConn .mpC2 , data->mData .release ());
266
+ bluez_gatt_characteristic1_set_value (data->mConn .mC2 . get () , data->mData .release ());
282
267
}
283
268
284
269
exit :
@@ -288,7 +273,7 @@ CHIP_ERROR BluezConnection::SendIndicationImpl(ConnectionDataBundle * data)
288
273
CHIP_ERROR BluezConnection::SendIndication (chip::System::PacketBufferHandle apBuf)
289
274
{
290
275
VerifyOrReturnError (!apBuf.IsNull (), CHIP_ERROR_INVALID_ARGUMENT, ChipLogError (DeviceLayer, " apBuf is NULL in %s" , __func__));
291
- VerifyOrReturnError (mpC2 != nullptr , CHIP_ERROR_INTERNAL, ChipLogError (DeviceLayer, " C2 is NULL in %s" , __func__));
276
+ VerifyOrReturnError (mC2 , CHIP_ERROR_INTERNAL, ChipLogError (DeviceLayer, " C2 is NULL in %s" , __func__));
292
277
293
278
ConnectionDataBundle bundle (*this , apBuf);
294
279
return PlatformMgrImpl ().GLibMatterContextInvokeSync (SendIndicationImpl, &bundle);
@@ -315,16 +300,16 @@ CHIP_ERROR BluezConnection::SendWriteRequestImpl(ConnectionDataBundle * data)
315
300
g_variant_builder_add (&optionsBuilder, " {sv}" , " type" , g_variant_new_string (" request" ));
316
301
auto options = g_variant_builder_end (&optionsBuilder);
317
302
318
- bluez_gatt_characteristic1_call_write_value (data->mConn .mpC1 , data->mData .release (), options, nullptr , SendWriteRequestDone ,
319
- const_cast <BluezConnection *>(&data->mConn ));
303
+ bluez_gatt_characteristic1_call_write_value (data->mConn .mC1 . get () , data->mData .release (), options, nullptr ,
304
+ SendWriteRequestDone, const_cast <BluezConnection *>(&data->mConn ));
320
305
321
306
return CHIP_NO_ERROR;
322
307
}
323
308
324
309
CHIP_ERROR BluezConnection::SendWriteRequest (chip::System::PacketBufferHandle apBuf)
325
310
{
326
311
VerifyOrReturnError (!apBuf.IsNull (), CHIP_ERROR_INVALID_ARGUMENT, ChipLogError (DeviceLayer, " apBuf is NULL in %s" , __func__));
327
- VerifyOrReturnError (mpC1 != nullptr , CHIP_ERROR_INTERNAL, ChipLogError (DeviceLayer, " C1 is NULL in %s" , __func__));
312
+ VerifyOrReturnError (mC1 , CHIP_ERROR_INTERNAL, ChipLogError (DeviceLayer, " C1 is NULL in %s" , __func__));
328
313
329
314
ConnectionDataBundle bundle (*this , apBuf);
330
315
return PlatformMgrImpl ().GLibMatterContextInvokeSync (SendWriteRequestImpl, &bundle);
@@ -360,7 +345,7 @@ void BluezConnection::SubscribeCharacteristicDone(GObject * aObject, GAsyncResul
360
345
361
346
CHIP_ERROR BluezConnection::SubscribeCharacteristicImpl (BluezConnection * connection)
362
347
{
363
- BluezGattCharacteristic1 * pC2 = connection->mpC2 ;
348
+ BluezGattCharacteristic1 * pC2 = connection->mC2 . get () ;
364
349
VerifyOrExit (pC2 != nullptr , ChipLogError (DeviceLayer, " C2 is NULL in %s" , __func__));
365
350
366
351
// Get notifications on the TX characteristic change (e.g. indication is received)
@@ -394,7 +379,7 @@ void BluezConnection::UnsubscribeCharacteristicDone(GObject * aObject, GAsyncRes
394
379
395
380
CHIP_ERROR BluezConnection::UnsubscribeCharacteristicImpl (BluezConnection * connection)
396
381
{
397
- BluezGattCharacteristic1 * pC2 = connection->mpC2 ;
382
+ BluezGattCharacteristic1 * pC2 = connection->mC2 . get () ;
398
383
VerifyOrExit (pC2 != nullptr , ChipLogError (DeviceLayer, " C2 is NULL in %s" , __func__));
399
384
400
385
bluez_gatt_characteristic1_call_stop_notify (pC2, nullptr , UnsubscribeCharacteristicDone, connection);
0 commit comments