mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Fix descriptors not being deleted (#4104)
This commit is contained in:
parent
1166d93805
commit
75573a3ed1
7 changed files with 26 additions and 6 deletions
|
@ -109,8 +109,7 @@ void BluetoothProxy::loop() {
|
|||
// after sending them to save memory. If something actually needs them
|
||||
// it can parse them again.
|
||||
for (auto &characteristic : service->characteristics) {
|
||||
characteristic->parsed = false;
|
||||
characteristic->descriptors.clear();
|
||||
characteristic->release_descriptors();
|
||||
}
|
||||
connection->send_service_++;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,13 @@ BLECharacteristic::~BLECharacteristic() {
|
|||
delete desc; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
|
||||
void BLECharacteristic::release_descriptors() {
|
||||
this->parsed = false;
|
||||
for (auto &desc : this->descriptors)
|
||||
delete desc; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
this->descriptors.clear();
|
||||
}
|
||||
|
||||
void BLECharacteristic::parse_descriptors() {
|
||||
this->parsed = true;
|
||||
uint16_t offset = 0;
|
||||
|
|
|
@ -24,6 +24,7 @@ class BLECharacteristic {
|
|||
esp_gatt_char_prop_t properties;
|
||||
std::vector<BLEDescriptor *> descriptors;
|
||||
void parse_descriptors();
|
||||
void release_descriptors();
|
||||
BLEDescriptor *get_descriptor(espbt::ESPBTUUID uuid);
|
||||
BLEDescriptor *get_descriptor(uint16_t uuid);
|
||||
BLEDescriptor *get_descriptor_by_handle(uint16_t handle);
|
||||
|
|
|
@ -76,6 +76,13 @@ void BLEClientBase::disconnect() {
|
|||
}
|
||||
}
|
||||
|
||||
void BLEClientBase::release_services() {
|
||||
for (auto &svc : this->services_)
|
||||
delete svc; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
this->services_.clear();
|
||||
esp_ble_gattc_cache_clean(this->remote_bda_);
|
||||
}
|
||||
|
||||
bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t esp_gattc_if,
|
||||
esp_ble_gattc_cb_param_t *param) {
|
||||
if (event == ESP_GATTC_REG_EVT && this->app_id != param->reg.app_id)
|
||||
|
@ -132,10 +139,7 @@ bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
|||
return false;
|
||||
ESP_LOGV(TAG, "[%d] [%s] ESP_GATTC_DISCONNECT_EVT, reason %d", this->connection_index_,
|
||||
this->address_str_.c_str(), param->disconnect.reason);
|
||||
for (auto &svc : this->services_)
|
||||
delete svc; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
this->services_.clear();
|
||||
esp_ble_gattc_cache_clean(this->remote_bda_);
|
||||
this->release_services();
|
||||
this->set_state(espbt::ClientState::IDLE);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ class BLEClientBase : public espbt::ESPBTClient, public Component {
|
|||
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
|
||||
void connect() override;
|
||||
void disconnect();
|
||||
void release_services();
|
||||
|
||||
bool connected() { return this->state_ == espbt::ClientState::ESTABLISHED; }
|
||||
|
||||
|
|
|
@ -29,6 +29,13 @@ BLEService::~BLEService() {
|
|||
delete chr; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
|
||||
void BLEService::release_characteristics() {
|
||||
this->parsed = false;
|
||||
for (auto &chr : this->characteristics)
|
||||
delete chr; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
this->characteristics.clear();
|
||||
}
|
||||
|
||||
void BLEService::parse_characteristics() {
|
||||
this->parsed = true;
|
||||
uint16_t offset = 0;
|
||||
|
|
|
@ -25,6 +25,7 @@ class BLEService {
|
|||
std::vector<BLECharacteristic *> characteristics;
|
||||
BLEClientBase *client;
|
||||
void parse_characteristics();
|
||||
void release_characteristics();
|
||||
BLECharacteristic *get_characteristic(espbt::ESPBTUUID uuid);
|
||||
BLECharacteristic *get_characteristic(uint16_t uuid);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue