custom for >5 resources
Fork of mbedConnectorInterface by
Diff: api/StaticResource.cpp
- Revision:
- 24:a6915e19814e
- Parent:
- 5:a929d65eb385
diff -r caa0260acc21 -r a6915e19814e api/StaticResource.cpp --- a/api/StaticResource.cpp Thu Mar 19 04:05:08 2015 +0000 +++ b/api/StaticResource.cpp Fri Mar 20 04:08:59 2015 +0000 @@ -26,23 +26,26 @@ #include "nsdl_support.h" // Constructor -StaticResource::StaticResource(const Logger *logger,const char *name, const char *value) : Resource<string>(logger,string(name),string(value)) +StaticResource::StaticResource(const Logger *logger,const char *name, const char *value) : Resource<string>(logger,string(name),string(value)), m_data_wrapper() { } // Constructor StaticResource::StaticResource(const Logger *logger,const char *name,const string value) : Resource<string>(logger,string(name),string(value)) { + this->m_data_wrapper = NULL; } // Constructor with buffer lengths StaticResource::StaticResource(const Logger *logger,const string name,const string value) : Resource<string>(logger,string(name),string(value)) { + this->m_data_wrapper = NULL; } // Copy constructor StaticResource::StaticResource(const StaticResource &resource) : Resource<string>((const Resource<string> &)resource) { + this->m_data_wrapper = resource.m_data_wrapper; } // Destructor @@ -56,11 +59,22 @@ if (p != NULL) { sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p; const uint8_t *name = (const uint8_t *)(this->getName().c_str()); - const uint8_t *value = (const uint8_t *)(this->getValue().c_str()); int name_length = this->getName().size(); - int value_length = this->getValue().size(); - nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,(uint8_t *)value,value_length); - this->logger()->log("StaticResource: [%s] value: [%s] bound",name,value); + + // do we wrap the data? + if (this->getDataWrapper() != NULL) { + // wrap the data... + this->getDataWrapper()->wrap((uint8_t *)this->getValue().c_str(),(int)this->getValue().size()); + nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,this->getDataWrapper()->get(),this->getDataWrapper()->length()); + this->logger()->log("StaticResource: [%s] value: [%s] bound",name,this->getDataWrapper()->get()); + } + else { + // do not wrap the data... + int value_length = this->getValue().size(); + const uint8_t *value = (const uint8_t *)(this->getValue().c_str()); + nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,(uint8_t *)value,value_length); + this->logger()->log("StaticResource: [%s] value: [%s] bound",name,value); + } } else { this->logger()->log("StaticResource: NULL parameter in bind()"); }