custom for >5 resources

Fork of mbedConnectorInterface by Doug Anson

Committer:
ansond
Date:
Fri Mar 20 04:08:59 2015 +0000
Revision:
24:a6915e19814e
Child:
25:1fc958ac14d1
added DataWrapper

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 24:a6915e19814e 28 this->m_data_length = data_length;
ansond 24:a6915e19814e 29 }
ansond 24:a6915e19814e 30
ansond 24:a6915e19814e 31 // copy constructor
ansond 24:a6915e19814e 32 DataWrapper::DataWrapper(const DataWrapper &data) {
ansond 24:a6915e19814e 33 this->m_data = data.m_data;
ansond 24:a6915e19814e 34 this->m_data_length = data.m_data_length;
ansond 24:a6915e19814e 35 }
ansond 24:a6915e19814e 36
ansond 24:a6915e19814e 37 // destructor
ansond 24:a6915e19814e 38 DataWrapper::~DataWrapper() {
ansond 24:a6915e19814e 39 }
ansond 24:a6915e19814e 40
ansond 24:a6915e19814e 41 // wrap
ansond 24:a6915e19814e 42 void DataWrapper::wrap(uint8_t *data,int data_length) {
ansond 24:a6915e19814e 43 this->reset();
ansond 24:a6915e19814e 44 if (data != NULL && data_length > 0) {
ansond 24:a6915e19814e 45 int length = data_length;
ansond 24:a6915e19814e 46 if (length > this->m_data_length) length = this->m_data_length;
ansond 24:a6915e19814e 47 memcpy(this->m_data,data,length);
ansond 24:a6915e19814e 48 this->m_data_length = length;
ansond 24:a6915e19814e 49 }
ansond 24:a6915e19814e 50 }
ansond 24:a6915e19814e 51
ansond 24:a6915e19814e 52 // unwrap
ansond 24:a6915e19814e 53 void DataWrapper::unwrap(uint8_t *data,int data_length) {
ansond 24:a6915e19814e 54 this->reset();
ansond 24:a6915e19814e 55 if (data != NULL && data_length > 0) {
ansond 24:a6915e19814e 56 int length = data_length;
ansond 24:a6915e19814e 57 if (length > this->m_data_length) length = this->m_data_length;
ansond 24:a6915e19814e 58 memcpy(this->m_data,data,length);
ansond 24:a6915e19814e 59 this->m_data_length = length;
ansond 24:a6915e19814e 60 }
ansond 24:a6915e19814e 61 }
ansond 24:a6915e19814e 62
ansond 24:a6915e19814e 63 void DataWrapper::reset() {
ansond 24:a6915e19814e 64 if (this->m_data != NULL && this->m_data_length > 0)
ansond 24:a6915e19814e 65 memset(this->m_data,0,this->m_data_length);
ansond 24:a6915e19814e 66 this->m_data_length = 0;
ansond 24:a6915e19814e 67 }