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.
Fork of mbedConnectorInterface by
api/StaticResource.cpp@48:f6dc5f56b810, 2015-04-13 (annotated)
- Committer:
- michaeljkoster
- Date:
- Mon Apr 13 22:36:34 2015 +0000
- Revision:
- 48:f6dc5f56b810
- Parent:
- 24:a6915e19814e
update DynamicResource and OptionsBuilder for observe
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ansond | 0:b438482ebbfc | 1 | /** |
| ansond | 0:b438482ebbfc | 2 | * @file StaticResource.h |
| ansond | 0:b438482ebbfc | 3 | * @brief mbed CoAP Endpoint Static Resource class |
| ansond | 0:b438482ebbfc | 4 | * @author Doug Anson/Chris Paola |
| ansond | 0:b438482ebbfc | 5 | * @version 1.0 |
| sam_grove | 2:853f9ecc12df | 6 | * @see |
| ansond | 0:b438482ebbfc | 7 | * |
| ansond | 0:b438482ebbfc | 8 | * Copyright (c) 2014 |
| ansond | 0:b438482ebbfc | 9 | * |
| ansond | 0:b438482ebbfc | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| ansond | 0:b438482ebbfc | 11 | * you may not use this file except in compliance with the License. |
| ansond | 0:b438482ebbfc | 12 | * You may obtain a copy of the License at |
| ansond | 0:b438482ebbfc | 13 | * |
| ansond | 0:b438482ebbfc | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| ansond | 0:b438482ebbfc | 15 | * |
| ansond | 0:b438482ebbfc | 16 | * Unless required by applicable law or agreed to in writing, software |
| ansond | 0:b438482ebbfc | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
| ansond | 0:b438482ebbfc | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| ansond | 0:b438482ebbfc | 19 | * See the License for the specific language governing permissions and |
| ansond | 0:b438482ebbfc | 20 | * limitations under the License. |
| ansond | 0:b438482ebbfc | 21 | */ |
| sam_grove | 2:853f9ecc12df | 22 | |
| sam_grove | 2:853f9ecc12df | 23 | #include "StaticResource.h" |
| sam_grove | 2:853f9ecc12df | 24 | |
| sam_grove | 2:853f9ecc12df | 25 | // NSDL libraries |
| sam_grove | 2:853f9ecc12df | 26 | #include "nsdl_support.h" |
| sam_grove | 2:853f9ecc12df | 27 | |
| sam_grove | 2:853f9ecc12df | 28 | // Constructor |
| ansond | 24:a6915e19814e | 29 | StaticResource::StaticResource(const Logger *logger,const char *name, const char *value) : Resource<string>(logger,string(name),string(value)), m_data_wrapper() |
| sam_grove | 2:853f9ecc12df | 30 | { |
| sam_grove | 2:853f9ecc12df | 31 | } |
| sam_grove | 2:853f9ecc12df | 32 | |
| sam_grove | 2:853f9ecc12df | 33 | // Constructor |
| sam_grove | 2:853f9ecc12df | 34 | StaticResource::StaticResource(const Logger *logger,const char *name,const string value) : Resource<string>(logger,string(name),string(value)) |
| sam_grove | 2:853f9ecc12df | 35 | { |
| ansond | 24:a6915e19814e | 36 | this->m_data_wrapper = NULL; |
| sam_grove | 2:853f9ecc12df | 37 | } |
| sam_grove | 2:853f9ecc12df | 38 | |
| sam_grove | 2:853f9ecc12df | 39 | // Constructor with buffer lengths |
| sam_grove | 2:853f9ecc12df | 40 | StaticResource::StaticResource(const Logger *logger,const string name,const string value) : Resource<string>(logger,string(name),string(value)) |
| sam_grove | 2:853f9ecc12df | 41 | { |
| ansond | 24:a6915e19814e | 42 | this->m_data_wrapper = NULL; |
| sam_grove | 2:853f9ecc12df | 43 | } |
| sam_grove | 2:853f9ecc12df | 44 | |
| sam_grove | 2:853f9ecc12df | 45 | // Copy constructor |
| sam_grove | 2:853f9ecc12df | 46 | StaticResource::StaticResource(const StaticResource &resource) : Resource<string>((const Resource<string> &)resource) |
| sam_grove | 2:853f9ecc12df | 47 | { |
| ansond | 24:a6915e19814e | 48 | this->m_data_wrapper = resource.m_data_wrapper; |
| sam_grove | 2:853f9ecc12df | 49 | } |
| sam_grove | 2:853f9ecc12df | 50 | |
| sam_grove | 2:853f9ecc12df | 51 | // Destructor |
| sam_grove | 2:853f9ecc12df | 52 | StaticResource::~StaticResource() |
| sam_grove | 2:853f9ecc12df | 53 | { |
| sam_grove | 2:853f9ecc12df | 54 | } |
| sam_grove | 2:853f9ecc12df | 55 | |
| sam_grove | 2:853f9ecc12df | 56 | // Bind resource to Endpoint |
| sam_grove | 2:853f9ecc12df | 57 | void StaticResource::bind(void *p) |
| sam_grove | 2:853f9ecc12df | 58 | { |
| ansond | 0:b438482ebbfc | 59 | if (p != NULL) { |
| ansond | 0:b438482ebbfc | 60 | sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p; |
| ansond | 0:b438482ebbfc | 61 | const uint8_t *name = (const uint8_t *)(this->getName().c_str()); |
| ansond | 0:b438482ebbfc | 62 | int name_length = this->getName().size(); |
| ansond | 24:a6915e19814e | 63 | |
| ansond | 24:a6915e19814e | 64 | // do we wrap the data? |
| ansond | 24:a6915e19814e | 65 | if (this->getDataWrapper() != NULL) { |
| ansond | 24:a6915e19814e | 66 | // wrap the data... |
| ansond | 24:a6915e19814e | 67 | this->getDataWrapper()->wrap((uint8_t *)this->getValue().c_str(),(int)this->getValue().size()); |
| ansond | 24:a6915e19814e | 68 | nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,this->getDataWrapper()->get(),this->getDataWrapper()->length()); |
| ansond | 24:a6915e19814e | 69 | this->logger()->log("StaticResource: [%s] value: [%s] bound",name,this->getDataWrapper()->get()); |
| ansond | 24:a6915e19814e | 70 | } |
| ansond | 24:a6915e19814e | 71 | else { |
| ansond | 24:a6915e19814e | 72 | // do not wrap the data... |
| ansond | 24:a6915e19814e | 73 | int value_length = this->getValue().size(); |
| ansond | 24:a6915e19814e | 74 | const uint8_t *value = (const uint8_t *)(this->getValue().c_str()); |
| ansond | 24:a6915e19814e | 75 | nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,(uint8_t *)value,value_length); |
| ansond | 24:a6915e19814e | 76 | this->logger()->log("StaticResource: [%s] value: [%s] bound",name,value); |
| ansond | 24:a6915e19814e | 77 | } |
| sam_grove | 2:853f9ecc12df | 78 | } else { |
| ansond | 5:a929d65eb385 | 79 | this->logger()->log("StaticResource: NULL parameter in bind()"); |
| ansond | 0:b438482ebbfc | 80 | } |
| sam_grove | 2:853f9ecc12df | 81 | } |
