custom for >5 resources
Fork of mbedConnectorInterface by
api/StaticResource.cpp@0:b438482ebbfc, 2015-01-27 (annotated)
- Committer:
- ansond
- Date:
- Tue Jan 27 22:23:51 2015 +0000
- Revision:
- 0:b438482ebbfc
- Child:
- 2:853f9ecc12df
initial check in
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 |
ansond | 0:b438482ebbfc | 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 | */ |
ansond | 0:b438482ebbfc | 22 | |
ansond | 0:b438482ebbfc | 23 | #include "StaticResource.h" |
ansond | 0:b438482ebbfc | 24 | |
ansond | 0:b438482ebbfc | 25 | // NSDL libraries |
ansond | 0:b438482ebbfc | 26 | #include "nsdl_support.h" |
ansond | 0:b438482ebbfc | 27 | |
ansond | 0:b438482ebbfc | 28 | // Constructor |
ansond | 0:b438482ebbfc | 29 | StaticResource::StaticResource(const Logger *logger,const char *name, const char *value) : Resource<string>(logger,string(name),string(value)) { |
ansond | 0:b438482ebbfc | 30 | } |
ansond | 0:b438482ebbfc | 31 | |
ansond | 0:b438482ebbfc | 32 | // Constructor |
ansond | 0:b438482ebbfc | 33 | StaticResource::StaticResource(const Logger *logger,const char *name,const string value) : Resource<string>(logger,string(name),string(value)) { |
ansond | 0:b438482ebbfc | 34 | } |
ansond | 0:b438482ebbfc | 35 | |
ansond | 0:b438482ebbfc | 36 | // Constructor with buffer lengths |
ansond | 0:b438482ebbfc | 37 | StaticResource::StaticResource(const Logger *logger,const string name,const string value) : Resource<string>(logger,string(name),string(value)) { |
ansond | 0:b438482ebbfc | 38 | } |
ansond | 0:b438482ebbfc | 39 | |
ansond | 0:b438482ebbfc | 40 | // Copy constructor |
ansond | 0:b438482ebbfc | 41 | StaticResource::StaticResource(const StaticResource &resource) : Resource<string>((const Resource<string> &)resource) { |
ansond | 0:b438482ebbfc | 42 | } |
ansond | 0:b438482ebbfc | 43 | |
ansond | 0:b438482ebbfc | 44 | // Destructor |
ansond | 0:b438482ebbfc | 45 | StaticResource::~StaticResource() { |
ansond | 0:b438482ebbfc | 46 | } |
ansond | 0:b438482ebbfc | 47 | |
ansond | 0:b438482ebbfc | 48 | // Bind resource to Endpoint |
ansond | 0:b438482ebbfc | 49 | void StaticResource::bind(void *p) { |
ansond | 0:b438482ebbfc | 50 | if (p != NULL) { |
ansond | 0:b438482ebbfc | 51 | sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p; |
ansond | 0:b438482ebbfc | 52 | std::printf("StaticResource: name[%s] value:[%s]\r\n",this->getName().c_str(),this->getValue().c_str()); |
ansond | 0:b438482ebbfc | 53 | const uint8_t *name = (const uint8_t *)(this->getName().c_str()); |
ansond | 0:b438482ebbfc | 54 | const uint8_t *value = (const uint8_t *)(this->getValue().c_str()); |
ansond | 0:b438482ebbfc | 55 | int name_length = this->getName().size(); |
ansond | 0:b438482ebbfc | 56 | int value_length = this->getValue().size(); |
ansond | 0:b438482ebbfc | 57 | nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,(uint8_t *)value,value_length); |
ansond | 0:b438482ebbfc | 58 | std::printf("StaticResource[%s(%d)] value: %s(%d) bound\r\n",name,name_length,value,value_length); |
ansond | 0:b438482ebbfc | 59 | } |
ansond | 0:b438482ebbfc | 60 | else { |
ansond | 0:b438482ebbfc | 61 | std::printf("StaticResource: NULL parameter in bind()\r\n"); |
ansond | 0:b438482ebbfc | 62 | } |
ansond | 0:b438482ebbfc | 63 | } |