Skip to content

Commit bf78754

Browse files
committed
Update the code based on review
1. Support valueupdated event 2. Change the balloc/bfree to malloc/free 3. Change return type from BLE_STATUS_T to int
1 parent 1836856 commit bf78754

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

libraries/BLE/src/BLECharacteristic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ BLECharacteristic::~BLECharacteristic()
5050
{
5151
if (_value)
5252
{
53-
bfree(_value);
53+
free(_value);
5454
_value = NULL;
5555
}
5656

5757
if (_event_handlers != NULL)
5858
{
59-
bfree(_event_handlers);
59+
free(_event_handlers);
6060
_event_handlers = NULL;
6161
}
6262
}
@@ -435,7 +435,7 @@ void BLECharacteristic::setEventHandler(BLECharacteristicEvent event,
435435
{
436436
if (_event_handlers == NULL)
437437
{
438-
_event_handlers = (BLECharacteristicEventHandler*)balloc(sizeof(BLECharacteristicEventHandler) * BLECharacteristicEventLast, NULL);
438+
_event_handlers = (BLECharacteristicEventHandler*)malloc(sizeof(BLECharacteristicEventHandler) * BLECharacteristicEventLast);
439439
}
440440

441441
if (_event_handlers != NULL)
@@ -456,7 +456,7 @@ BLECharacteristic::_setValue(const uint8_t value[], uint16_t length)
456456
if (NULL == _value)
457457
{
458458
// Allocate the buffer for characteristic
459-
_value = (unsigned char*)balloc(_value_size, NULL);//malloc(_value_size)
459+
_value = (unsigned char*)malloc(_value_size);
460460
}
461461
if (NULL == _value)
462462
{

libraries/BLE/src/BLECharacteristicImp.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ BLECharacteristicImp::BLECharacteristicImp(const bt_uuid_t* uuid,
4343
_ble_device()
4444
{
4545
_value_size = BLE_MAX_ATTR_DATA_LEN;// Set as MAX value. TODO: long read/write need to twist
46-
_value = (unsigned char*)balloc(_value_size, NULL);
46+
_value = (unsigned char*)malloc(_value_size);
4747
if (_value_size > BLE_MAX_ATTR_DATA_LEN)
4848
{
49-
_value_buffer = (unsigned char*)balloc(_value_size, NULL);
49+
_value_buffer = (unsigned char*)malloc(_value_size);
5050
}
5151

5252
memset(_value, 0, _value_size);
@@ -107,10 +107,10 @@ BLECharacteristicImp::BLECharacteristicImp(BLECharacteristic& characteristic,
107107
{
108108
unsigned char properties = characteristic._properties;
109109
_value_size = characteristic._value_size;
110-
_value = (unsigned char*)balloc(_value_size, NULL);
110+
_value = (unsigned char*)malloc(_value_size);
111111
if (_value_size > BLE_MAX_ATTR_DATA_LEN)
112112
{
113-
_value_buffer = (unsigned char*)balloc(_value_size, NULL);
113+
_value_buffer = (unsigned char*)malloc(_value_size);
114114
}
115115

116116
memset(&_ccc_cfg, 0, sizeof(_ccc_cfg));
@@ -173,12 +173,12 @@ BLECharacteristicImp::~BLECharacteristicImp()
173173
{
174174
releaseDescriptors();
175175
if (_value) {
176-
bfree(_value);
176+
free(_value);
177177
_value = NULL;
178178
}
179179
if (_value_buffer)
180180
{
181-
bfree(_value_buffer);
181+
free(_value_buffer);
182182
_value_buffer = NULL;
183183
}
184184
}
@@ -245,12 +245,26 @@ bool
245245
BLECharacteristicImp::setValue(const unsigned char value[], uint16_t length)
246246
{
247247
_setValue(value, length, 0);
248-
// Read response/Notification/Indication for GATT client
249-
// Write request for GATT server
250-
if (_event_handlers[BLEWritten])
248+
if (BLEUtils::isLocalBLE(_ble_device) == true)
251249
{
252-
BLECharacteristic chrcTmp(this, &_ble_device);
253-
_event_handlers[BLEWritten](_ble_device, chrcTmp);
250+
// GATT server
251+
// Write request for GATT server
252+
if (_event_handlers[BLEWritten])
253+
{
254+
BLECharacteristic chrcTmp(this, &_ble_device);
255+
_event_handlers[BLEWritten](_ble_device, chrcTmp);
256+
}
257+
}
258+
else
259+
{
260+
// GATT client
261+
// Discovered attribute
262+
// Read response/Notification/Indication for GATT client
263+
if (_event_handlers[BLEValueUpdated])
264+
{
265+
BLECharacteristic chrcTmp(this, &_ble_device);
266+
_event_handlers[BLEValueUpdated](_ble_device, chrcTmp);
267+
}
254268
}
255269

256270
return true;

libraries/BLE/src/BLEDescriptor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ BLEDescriptor::BLEDescriptor(BLEDescriptorImp* descriptorImp,
4040
BLEUtils::uuidBT2String(descriptorImp->bt_uuid(), _uuid_cstr);
4141

4242
_value_size = descriptorImp->valueSize();
43-
_value = (unsigned char*)balloc(_value_size, NULL);
43+
_value = (unsigned char*)malloc(_value_size);
4444
memcpy(_value, descriptorImp->value(), _value_size);
4545
}
4646

@@ -57,7 +57,7 @@ BLEDescriptor::BLEDescriptor(const char* uuid,
5757
_bledev.setAddress(*BLEUtils::bleGetLoalAddress());
5858

5959
_value_size = valueLength > BLE_MAX_ATTR_LONGDATA_LEN ? BLE_MAX_ATTR_LONGDATA_LEN : valueLength;
60-
_value = (unsigned char*)balloc(_value_size, NULL);
60+
_value = (unsigned char*)malloc(_value_size);
6161
memcpy(_value, value, _value_size);
6262
}
6363

@@ -70,7 +70,7 @@ BLEDescriptor::~BLEDescriptor()
7070
{
7171
if (_value)
7272
{
73-
bfree(_value);
73+
free(_value);
7474
_value = NULL;
7575
}
7676
}

libraries/BLE/src/BLEDescriptorImp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BLEDescriptorImp::BLEDescriptorImp(BLEDevice& bledevice,
3232

3333
_properties = descriptor.properties();
3434
_value_length = descriptor.valueLength();
35-
_value = (unsigned char*)balloc(_value_length, NULL);
35+
_value = (unsigned char*)malloc(_value_length);
3636

3737
memcpy(_value, descriptor.value(), _value_length);
3838
}
@@ -46,14 +46,14 @@ BLEDescriptorImp::BLEDescriptorImp(const bt_uuid_t* uuid,
4646
_properties(properties)
4747
{
4848
_value_length = BLE_MAX_ATTR_DATA_LEN;
49-
_value = (unsigned char*)balloc(_value_length, NULL);
49+
_value = (unsigned char*)malloc(_value_length);
5050

5151
memset(_value, 0, _value_length);
5252
}
5353

5454
BLEDescriptorImp::~BLEDescriptorImp() {
5555
if (_value) {
56-
bfree(_value);
56+
free(_value);
5757
_value = NULL;
5858
}
5959
}

libraries/BLE/src/BLEProfileManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ BLEProfileManager::~BLEProfileManager (void)
6969
{
7070
if (this->_attr_base)
7171
{
72-
bfree(this->_attr_base);
72+
free(this->_attr_base);
7373
}
7474
ServiceReadLinkNodePtr node = link_node_get_first(&_read_service_header);
7575
while (NULL != node)
@@ -246,7 +246,7 @@ int BLEProfileManager::registerProfile(BLEDevice &bledevice)
246246

247247
if (NULL == _attr_base)
248248
{
249-
_attr_base = (bt_gatt_attr_t *)balloc(attr_counter * sizeof(bt_gatt_attr_t), NULL);
249+
_attr_base = (bt_gatt_attr_t *)malloc(attr_counter * sizeof(bt_gatt_attr_t));
250250
memset(_attr_base, 0x00, (attr_counter * sizeof(bt_gatt_attr_t)));
251251
pr_info(LOG_MODULE_BLE, "_attr_base_-%p, size-%d, attr_counter-%d", _attr_base, sizeof(_attr_base), attr_counter);
252252
if (NULL == _attr_base)
@@ -259,7 +259,7 @@ int BLEProfileManager::registerProfile(BLEDevice &bledevice)
259259
{
260260
if (NULL != _attr_base)
261261
{
262-
bfree(_attr_base);
262+
free(_attr_base);
263263
}
264264
return err_code;
265265
}

0 commit comments

Comments
 (0)