observe updates
Fork of mbedConnectorInterface by
Embed:
(wiki syntax)
Show/hide line numbers
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 "StaticResource.h" 00024 00025 // NSDL libraries 00026 #include "nsdl_support.h" 00027 00028 // Constructor 00029 StaticResource::StaticResource(const Logger *logger,const char *name, const char *value) : Resource<string>(logger,string(name),string(value)), m_data_wrapper() 00030 { 00031 } 00032 00033 // Constructor 00034 StaticResource::StaticResource(const Logger *logger,const char *name,const string value) : Resource<string>(logger,string(name),string(value)) 00035 { 00036 this->m_data_wrapper = NULL; 00037 } 00038 00039 // Constructor with buffer lengths 00040 StaticResource::StaticResource(const Logger *logger,const string name,const string value) : Resource<string>(logger,string(name),string(value)) 00041 { 00042 this->m_data_wrapper = 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 } 00050 00051 // Destructor 00052 StaticResource::~StaticResource() 00053 { 00054 } 00055 00056 // Bind resource to Endpoint 00057 void StaticResource::bind(void *p) 00058 { 00059 if (p != NULL) { 00060 sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p; 00061 const uint8_t *name = (const uint8_t *)(this->getName().c_str()); 00062 int name_length = this->getName().size(); 00063 00064 // do we wrap the data? 00065 if (this->getDataWrapper() != NULL) { 00066 // wrap the data... 00067 this->getDataWrapper()->wrap((uint8_t *)this->getValue().c_str(),(int)this->getValue().size()); 00068 nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,this->getDataWrapper()->get(),this->getDataWrapper()->length()); 00069 this->logger()->log("StaticResource: [%s] value: [%s] bound",name,this->getDataWrapper()->get()); 00070 } 00071 else { 00072 // do not wrap the data... 00073 int value_length = this->getValue().size(); 00074 const uint8_t *value = (const uint8_t *)(this->getValue().c_str()); 00075 nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,(uint8_t *)value,value_length); 00076 this->logger()->log("StaticResource: [%s] value: [%s] bound",name,value); 00077 } 00078 } else { 00079 this->logger()->log("StaticResource: NULL parameter in bind()"); 00080 } 00081 }
Generated on Wed Jul 13 2022 02:11:49 by 1.7.2