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.
StaticResource.cpp
00001 /** 00002 * @file StaticResource.h 00003 * @brief mbed CoAP Endpoint Static Resource class 00004 * @author Doug Anson/Chris Paola 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #include "mbed-connector-interface/StaticResource.h" 00024 00025 // Constructor 00026 StaticResource::StaticResource(const Logger *logger,const char *obj_name,const char *res_name, const char *value) : Resource<string>(logger,string(obj_name),string(res_name),string(value)), m_data_wrapper() 00027 { 00028 this->m_object = NULL; 00029 } 00030 00031 // Constructor 00032 StaticResource::StaticResource(const Logger *logger,const char *obj_name,const char *res_name,const string value) : Resource<string>(logger,string(obj_name),string(res_name),string(value)) 00033 { 00034 this->m_data_wrapper = NULL; 00035 this->m_object = NULL; 00036 } 00037 00038 // Constructor with buffer lengths 00039 StaticResource::StaticResource(const Logger *logger,const string obj_name,const string res_name,const string value) : Resource<string>(logger,string(obj_name),string(res_name),string(value)) 00040 { 00041 this->m_data_wrapper = NULL; 00042 this->m_object = NULL; 00043 } 00044 00045 // Copy constructor 00046 StaticResource::StaticResource(const StaticResource &resource) : Resource<string>((const Resource<string> &)resource) 00047 { 00048 this->m_data_wrapper = resource.m_data_wrapper; 00049 this->m_object = resource.m_object; 00050 } 00051 00052 // Destructor 00053 StaticResource::~StaticResource() { 00054 } 00055 00056 // bind CoAP Resource.. 00057 M2MObject *StaticResource::bind(void *p) { 00058 if (p != NULL) { 00059 this->m_object = M2MInterfaceFactory::create_object(this->getObjName().c_str()); 00060 if (this->m_object != NULL) { 00061 M2MObjectInstance* inst = this->m_object->create_object_instance(); 00062 if (inst != NULL) { 00063 if (this->getDataWrapper() != NULL) { 00064 // wrap the data... 00065 this->getDataWrapper()->wrap((uint8_t *)this->getValue().c_str(),(int)this->getValue().size()); 00066 inst->create_static_resource(this->getResName().c_str(),"StaticResource",M2MResourceInstance::STRING,this->getDataWrapper()->get(),(uint8_t)this->getDataWrapper()->length()); 00067 this->logger()->log("StaticResource: [%s] value: [%s] bound",this->getFullName().c_str(),this->getDataWrapper()->get()); 00068 } 00069 else { 00070 // do not wrap the data... 00071 inst->create_static_resource(this->getResName().c_str(),"StaticResource",M2MResourceInstance::STRING,(uint8_t *)this->getValue().c_str(),(uint8_t)this->getValue().size()); 00072 this->logger()->log("StaticResource: [%s] value: [%s] bound",this->getFullName().c_str(),this->getValue().c_str()); 00073 } 00074 } 00075 else { 00076 // create_object_instance() failed... 00077 this->logger()->log("StaticResource: Unable to create object instance..."); 00078 delete this->m_object; 00079 this->m_object = NULL; 00080 } 00081 } 00082 else { 00083 // create_object() failed 00084 this->logger()->log("StaticResource: Unable to create object..."); 00085 } 00086 } 00087 else { 00088 this->logger()->log("StaticResource: NULL value parameter in bind() request..."); 00089 } 00090 return this->m_object; 00091 } 00092
Generated on Wed Jul 13 2022 21:59:32 by
1.7.2