Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: IoT_LED_demo ServoTest uWater_Project hackathon ... more
Revision 25:1fc958ac14d1, committed 2015-03-20
- Comitter:
- ansond
- Date:
- Fri Mar 20 05:32:16 2015 +0000
- Parent:
- 24:a6915e19814e
- Child:
- 26:b06a19916f05
- Commit message:
- updates
Changed in this revision
--- a/api/DataWrapper.cpp Fri Mar 20 04:08:59 2015 +0000
+++ b/api/DataWrapper.cpp Fri Mar 20 05:32:16 2015 +0000
@@ -25,17 +25,32 @@
// constructor
DataWrapper::DataWrapper(uint8_t *data,int data_length) {
this->m_data = data;
- this->m_data_length = data_length;
+ this->m_data_length = 0;
+ this->m_data_length_max = data_length;
+ this->m_alloced = false;
+ this->reset();
+ }
+
+ // constructor (alloc)
+ DataWrapper::DataWrapper(int data_length) {
+ this->m_data = (uint8_t *)malloc(data_length+1);
+ memset(this->m_data,0,data_length+1);
+ this->m_data_length = 0;
+ this->m_data_length_max = data_length;
+ this->m_alloced = true;
}
// copy constructor
DataWrapper::DataWrapper(const DataWrapper &data) {
this->m_data = data.m_data;
this->m_data_length = data.m_data_length;
+ this->m_data_length_max = data.m_data_length_max;
+ this->m_alloced = data.m_alloced;
}
// destructor
DataWrapper::~DataWrapper() {
+ if (this->m_alloced && this->m_data != NULL) free(this->m_data);
}
// wrap
@@ -43,7 +58,7 @@
this->reset();
if (data != NULL && data_length > 0) {
int length = data_length;
- if (length > this->m_data_length) length = this->m_data_length;
+ if (length > this->m_data_length_max) length = this->m_data_length_max;
memcpy(this->m_data,data,length);
this->m_data_length = length;
}
@@ -54,14 +69,14 @@
this->reset();
if (data != NULL && data_length > 0) {
int length = data_length;
- if (length > this->m_data_length) length = this->m_data_length;
+ if (length > this->m_data_length_max) length = this->m_data_length_max;
memcpy(this->m_data,data,length);
this->m_data_length = length;
}
}
void DataWrapper::reset() {
- if (this->m_data != NULL && this->m_data_length > 0)
- memset(this->m_data,0,this->m_data_length);
+ if (this->m_data != NULL && this->m_data_length_max > 0)
+ memset(this->m_data,0,this->m_data_length_max);
this->m_data_length = 0;
}
\ No newline at end of file
--- a/api/DataWrapper.h Fri Mar 20 04:08:59 2015 +0000
+++ b/api/DataWrapper.h Fri Mar 20 05:32:16 2015 +0000
@@ -34,6 +34,11 @@
DataWrapper(uint8_t *data,int data_length);
/**
+ Default constructor (alloc)
+ */
+ DataWrapper(int data_length);
+
+ /**
Default copy constructor
*/
DataWrapper(const DataWrapper &data);
@@ -69,10 +74,13 @@
Reset the wrapper
*/
void reset();
-
+ protected:
+ uint8_t *m_data;
+
private:
- uint8_t *m_data;
+ bool m_alloced;
int m_data_length;
+ int m_data_length_max;
};
#endif // __DATA_WRAPPER_H__
\ No newline at end of file
--- a/api/DynamicResource.cpp Fri Mar 20 04:08:59 2015 +0000
+++ b/api/DynamicResource.cpp Fri Mar 20 05:32:16 2015 +0000
@@ -105,7 +105,10 @@
sn_coap_hdr_s *coap_res_ptr = 0;
// create our key for debugging output...
+ DataWrapper *hold = this->getDataWrapper();
+ this->setDataWrapper(NULL);
string key = this->coapDataToString(received_coap_ptr->uri_path_ptr,received_coap_ptr->uri_path_len);
+ this->setDataWrapper(hold);
if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) {
coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
