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:
h2zero 2020-05-29 20:49:46 -06:00
parent 99ad62cdd4
commit ffcb325aea
2 changed files with 1 additions and 39 deletions

View file

@ -53,13 +53,12 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
m_uuid = nullptr; m_uuid = nullptr;
break; break;
} }
m_handle = chr->val_handle; m_handle = chr->val_handle;
m_defHandle = chr->def_handle; m_defHandle = chr->def_handle;
m_charProp = chr->properties; m_charProp = chr->properties;
m_pRemoteService = pRemoteService; m_pRemoteService = pRemoteService;
m_notifyCallback = nullptr; m_notifyCallback = nullptr;
m_rawData = nullptr;
m_dataLen = 0;
m_timestamp = 0; m_timestamp = 0;
} // NimBLERemoteCharacteristic } // NimBLERemoteCharacteristic
@ -69,9 +68,6 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
*/ */
NimBLERemoteCharacteristic::~NimBLERemoteCharacteristic() { NimBLERemoteCharacteristic::~NimBLERemoteCharacteristic() {
removeDescriptors(); // Release resources for any descriptor information we may have allocated. removeDescriptors(); // Release resources for any descriptor information we may have allocated.
if(m_rawData != nullptr) {
free(m_rawData);
}
} // ~NimBLERemoteCharacteristic } // ~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() { void NimBLERemoteCharacteristic::releaseSemaphores() {
for (auto &it: m_descriptorVector) { for (auto &it: m_descriptorVector) {
it->releaseSemaphores(); it->releaseSemaphores();

View file

@ -87,8 +87,6 @@ public:
bool writeValue(uint8_t newValue, bool writeValue(uint8_t newValue,
bool response = false); bool response = false);
std::string toString(); std::string toString();
uint8_t* readRawData();
size_t getDataLength();
NimBLERemoteService* getRemoteService(); NimBLERemoteService* getRemoteService();
private: private:
@ -121,8 +119,6 @@ private:
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt"); FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");
FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt"); FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt");
std::string m_value; std::string m_value;
uint8_t* m_rawData;
size_t m_dataLen;
notify_callback m_notifyCallback; notify_callback m_notifyCallback;
time_t m_timestamp; time_t m_timestamp;