added max-age and content-format

Fork of mbedConnectorInterface by Doug Anson

Committer:
ansond
Date:
Wed Mar 25 05:12:35 2015 +0000
Revision:
27:eb6818ad257a
Parent:
25:1fc958ac14d1
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 24:a6915e19814e 1 /**
ansond 24:a6915e19814e 2 * @file DynamicResource.h
ansond 24:a6915e19814e 3 * @brief mbed CoAP Endpoint Dynamic Resource class (header)
ansond 24:a6915e19814e 4 * @author Doug Anson/Chris Paola
ansond 24:a6915e19814e 5 * @version 1.0
ansond 24:a6915e19814e 6 * @see
ansond 24:a6915e19814e 7 *
ansond 24:a6915e19814e 8 * Copyright (c) 2014
ansond 24:a6915e19814e 9 *
ansond 24:a6915e19814e 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 24:a6915e19814e 11 * you may not use this file except in compliance with the License.
ansond 24:a6915e19814e 12 * You may obtain a copy of the License at
ansond 24:a6915e19814e 13 *
ansond 24:a6915e19814e 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 24:a6915e19814e 15 *
ansond 24:a6915e19814e 16 * Unless required by applicable law or agreed to in writing, software
ansond 24:a6915e19814e 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 24:a6915e19814e 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 24:a6915e19814e 19 * See the License for the specific language governing permissions and
ansond 24:a6915e19814e 20 * limitations under the License.
ansond 24:a6915e19814e 21 */
ansond 24:a6915e19814e 22
ansond 24:a6915e19814e 23 #include "DataWrapper.h"
ansond 24:a6915e19814e 24
ansond 24:a6915e19814e 25 // constructor
ansond 24:a6915e19814e 26 DataWrapper::DataWrapper(uint8_t *data,int data_length) {
ansond 24:a6915e19814e 27 this->m_data = data;
ansond 25:1fc958ac14d1 28 this->m_data_length = 0;
ansond 25:1fc958ac14d1 29 this->m_data_length_max = data_length;
ansond 25:1fc958ac14d1 30 this->m_alloced = false;
ansond 25:1fc958ac14d1 31 this->reset();
ansond 25:1fc958ac14d1 32 }
ansond 25:1fc958ac14d1 33
ansond 25:1fc958ac14d1 34 // constructor (alloc)
ansond 25:1fc958ac14d1 35 DataWrapper::DataWrapper(int data_length) {
ansond 25:1fc958ac14d1 36 this->m_data = (uint8_t *)malloc(data_length+1);
ansond 25:1fc958ac14d1 37 memset(this->m_data,0,data_length+1);
ansond 25:1fc958ac14d1 38 this->m_data_length = 0;
ansond 25:1fc958ac14d1 39 this->m_data_length_max = data_length;
ansond 25:1fc958ac14d1 40 this->m_alloced = true;
ansond 24:a6915e19814e 41 }
ansond 24:a6915e19814e 42
ansond 24:a6915e19814e 43 // copy constructor
ansond 24:a6915e19814e 44 DataWrapper::DataWrapper(const DataWrapper &data) {
ansond 24:a6915e19814e 45 this->m_data = data.m_data;
ansond 24:a6915e19814e 46 this->m_data_length = data.m_data_length;
ansond 25:1fc958ac14d1 47 this->m_data_length_max = data.m_data_length_max;
ansond 25:1fc958ac14d1 48 this->m_alloced = data.m_alloced;
ansond 24:a6915e19814e 49 }
ansond 24:a6915e19814e 50
ansond 24:a6915e19814e 51 // destructor
ansond 24:a6915e19814e 52 DataWrapper::~DataWrapper() {
ansond 25:1fc958ac14d1 53 if (this->m_alloced && this->m_data != NULL) free(this->m_data);
ansond 24:a6915e19814e 54 }
ansond 24:a6915e19814e 55
ansond 24:a6915e19814e 56 // wrap
ansond 24:a6915e19814e 57 void DataWrapper::wrap(uint8_t *data,int data_length) {
ansond 24:a6915e19814e 58 this->reset();
ansond 24:a6915e19814e 59 if (data != NULL && data_length > 0) {
ansond 24:a6915e19814e 60 int length = data_length;
ansond 25:1fc958ac14d1 61 if (length > this->m_data_length_max) length = this->m_data_length_max;
ansond 24:a6915e19814e 62 memcpy(this->m_data,data,length);
ansond 24:a6915e19814e 63 this->m_data_length = length;
ansond 24:a6915e19814e 64 }
ansond 24:a6915e19814e 65 }
ansond 24:a6915e19814e 66
ansond 24:a6915e19814e 67 // unwrap
ansond 24:a6915e19814e 68 void DataWrapper::unwrap(uint8_t *data,int data_length) {
ansond 24:a6915e19814e 69 this->reset();
ansond 24:a6915e19814e 70 if (data != NULL && data_length > 0) {
ansond 24:a6915e19814e 71 int length = data_length;
ansond 25:1fc958ac14d1 72 if (length > this->m_data_length_max) length = this->m_data_length_max;
ansond 24:a6915e19814e 73 memcpy(this->m_data,data,length);
ansond 24:a6915e19814e 74 this->m_data_length = length;
ansond 24:a6915e19814e 75 }
ansond 24:a6915e19814e 76 }
ansond 27:eb6818ad257a 77
ansond 27:eb6818ad257a 78 // reset
ansond 24:a6915e19814e 79 void DataWrapper::reset() {
ansond 25:1fc958ac14d1 80 if (this->m_data != NULL && this->m_data_length_max > 0)
ansond 25:1fc958ac14d1 81 memset(this->m_data,0,this->m_data_length_max);
ansond 24:a6915e19814e 82 this->m_data_length = 0;
ansond 27:eb6818ad257a 83 }
ansond 27:eb6818ad257a 84
ansond 27:eb6818ad257a 85 // set the app key
ansond 27:eb6818ad257a 86 void DataWrapper::setAppKey(uint8_t *appkey,int appkey_length) {
ansond 27:eb6818ad257a 87 // do nothing in the base class
ansond 27:eb6818ad257a 88 ;
ansond 27:eb6818ad257a 89 }
ansond 27:eb6818ad257a 90