mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-24 06:00:55 +01:00
Remove getRawData() and getDataLength()
Previously getRawData() made an unnecessary copy of the remote characteristic value data in order to return a uint8_t*. The resources used for this was unjustified by the value it provided as templates to retrieve such data have been added. Also the application writer could cast the std::string result of readValue() and/or getValue() however they choose using the data() method on the container if desired. getDataLength() is also an unnecessary function as the length can be retrieved by the returned std::string from readValue() and/or getValue() with the length() method.
This commit is contained in:
parent
99ad62cdd4
commit
ffcb325aea
2 changed files with 1 additions and 39 deletions
|
@ -53,13 +53,12 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
|
|||
m_uuid = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
m_handle = chr->val_handle;
|
||||
m_defHandle = chr->def_handle;
|
||||
m_charProp = chr->properties;
|
||||
m_pRemoteService = pRemoteService;
|
||||
m_notifyCallback = nullptr;
|
||||
m_rawData = nullptr;
|
||||
m_dataLen = 0;
|
||||
m_timestamp = 0;
|
||||
} // NimBLERemoteCharacteristic
|
||||
|
||||
|
@ -69,9 +68,6 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
|
|||
*/
|
||||
NimBLERemoteCharacteristic::~NimBLERemoteCharacteristic() {
|
||||
removeDescriptors(); // Release resources for any descriptor information we may have allocated.
|
||||
if(m_rawData != nullptr) {
|
||||
free(m_rawData);
|
||||
}
|
||||
} // ~NimBLERemoteCharacteristic
|
||||
|
||||
/*
|
||||
|
@ -702,36 +698,6 @@ int NimBLERemoteCharacteristic::onWriteCB(uint16_t conn_handle,
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read raw data from remote characteristic as hex bytes
|
||||
* @return uint8_t pointer to the data read.
|
||||
*/
|
||||
uint8_t* NimBLERemoteCharacteristic::readRawData() {
|
||||
if(m_rawData != nullptr) {
|
||||
free(m_rawData);
|
||||
m_rawData = nullptr;
|
||||
}
|
||||
|
||||
m_dataLen = m_value.length();
|
||||
// If we have data copy it to rawData
|
||||
if(m_dataLen) {
|
||||
m_rawData = (uint8_t*) calloc(m_dataLen, sizeof(uint8_t));
|
||||
memcpy(m_rawData, m_value.data(), m_dataLen);
|
||||
}
|
||||
|
||||
return m_rawData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the length of the data read from the remote characteristic.
|
||||
* @return size_t length of the data in bytes.
|
||||
*/
|
||||
size_t NimBLERemoteCharacteristic::getDataLength() {
|
||||
return m_value.length();
|
||||
}
|
||||
|
||||
|
||||
void NimBLERemoteCharacteristic::releaseSemaphores() {
|
||||
for (auto &it: m_descriptorVector) {
|
||||
it->releaseSemaphores();
|
||||
|
|
|
@ -87,8 +87,6 @@ public:
|
|||
bool writeValue(uint8_t newValue,
|
||||
bool response = false);
|
||||
std::string toString();
|
||||
uint8_t* readRawData();
|
||||
size_t getDataLength();
|
||||
NimBLERemoteService* getRemoteService();
|
||||
|
||||
private:
|
||||
|
@ -121,8 +119,6 @@ private:
|
|||
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");
|
||||
FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt");
|
||||
std::string m_value;
|
||||
uint8_t* m_rawData;
|
||||
size_t m_dataLen;
|
||||
notify_callback m_notifyCallback;
|
||||
time_t m_timestamp;
|
||||
|
||||
|
|
Loading…
Reference in a new issue