mbed Connector Interface simplification API on top of mbed-client

Fork of mbedConnectorInterfaceV3 by Doug Anson

NOTE:

This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!

Committer:
ansond
Date:
Tue Jun 14 04:01:34 2016 +0000
Revision:
27:b8aaf7dc7023
Parent:
0:1f1f55e73248
Child:
33:1d0b855df5a5
Initial merge and update of device and firmware objects

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 27:b8aaf7dc7023 1 /**
ansond 27:b8aaf7dc7023 2 * @file StaticResource.h
ansond 27:b8aaf7dc7023 3 * @brief mbed CoAP Endpoint Static Resource class
ansond 27:b8aaf7dc7023 4 * @author Doug Anson/Chris Paola
ansond 27:b8aaf7dc7023 5 * @version 1.0
ansond 27:b8aaf7dc7023 6 * @see
ansond 27:b8aaf7dc7023 7 *
ansond 27:b8aaf7dc7023 8 * Copyright (c) 2014
ansond 27:b8aaf7dc7023 9 *
ansond 27:b8aaf7dc7023 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 27:b8aaf7dc7023 11 * you may not use this file except in compliance with the License.
ansond 27:b8aaf7dc7023 12 * You may obtain a copy of the License at
ansond 27:b8aaf7dc7023 13 *
ansond 27:b8aaf7dc7023 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 27:b8aaf7dc7023 15 *
ansond 27:b8aaf7dc7023 16 * Unless required by applicable law or agreed to in writing, software
ansond 27:b8aaf7dc7023 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 27:b8aaf7dc7023 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 27:b8aaf7dc7023 19 * See the License for the specific language governing permissions and
ansond 27:b8aaf7dc7023 20 * limitations under the License.
ansond 27:b8aaf7dc7023 21 */
ansond 27:b8aaf7dc7023 22
ansond 27:b8aaf7dc7023 23 #include "mbed-connector-interface/StaticResource.h"
ansond 27:b8aaf7dc7023 24
ansond 27:b8aaf7dc7023 25 // Endpoint
ansond 27:b8aaf7dc7023 26 #include "mbed-connector-interface/ConnectorEndpoint.h"
ansond 27:b8aaf7dc7023 27
ansond 27:b8aaf7dc7023 28 // Constructor
ansond 27:b8aaf7dc7023 29 StaticResource::StaticResource(const Logger *logger,const char *obj_name,const char *res_name, const char *value) : Resource<string>(logger,string(obj_name),string(res_name),string(value)), m_data_wrapper()
ansond 27:b8aaf7dc7023 30 {
ansond 27:b8aaf7dc7023 31 this->m_data_wrapper = NULL;
ansond 27:b8aaf7dc7023 32 this->m_res = NULL;
ansond 27:b8aaf7dc7023 33 }
ansond 27:b8aaf7dc7023 34
ansond 27:b8aaf7dc7023 35 // Constructor
ansond 27:b8aaf7dc7023 36 StaticResource::StaticResource(const Logger *logger,const char *obj_name,const char *res_name,const string value) : Resource<string>(logger,string(obj_name),string(res_name),string(value))
ansond 27:b8aaf7dc7023 37 {
ansond 27:b8aaf7dc7023 38 this->m_data_wrapper = NULL;
ansond 27:b8aaf7dc7023 39 this->m_res = NULL;
ansond 27:b8aaf7dc7023 40 }
ansond 27:b8aaf7dc7023 41
ansond 27:b8aaf7dc7023 42 // Constructor with buffer lengths
ansond 27:b8aaf7dc7023 43 StaticResource::StaticResource(const Logger *logger,const string obj_name,const string res_name,const string value) : Resource<string>(logger,string(obj_name),string(res_name),string(value))
ansond 27:b8aaf7dc7023 44 {
ansond 27:b8aaf7dc7023 45 this->m_data_wrapper = NULL;
ansond 27:b8aaf7dc7023 46 this->m_res = NULL;
ansond 27:b8aaf7dc7023 47 }
ansond 0:1f1f55e73248 48
ansond 27:b8aaf7dc7023 49 // Copy constructor
ansond 27:b8aaf7dc7023 50 StaticResource::StaticResource(const StaticResource &resource) : Resource<string>((const Resource<string> &)resource)
ansond 27:b8aaf7dc7023 51 {
ansond 27:b8aaf7dc7023 52 this->m_data_wrapper = resource.m_data_wrapper;
ansond 27:b8aaf7dc7023 53 this->m_res = resource.m_res;
ansond 27:b8aaf7dc7023 54 }
ansond 27:b8aaf7dc7023 55
ansond 27:b8aaf7dc7023 56 // Destructor
ansond 27:b8aaf7dc7023 57 StaticResource::~StaticResource() {
ansond 27:b8aaf7dc7023 58 }
ansond 27:b8aaf7dc7023 59
ansond 27:b8aaf7dc7023 60 // bind CoAP Resource..
ansond 27:b8aaf7dc7023 61 void StaticResource::bind(void *ep) {
ansond 27:b8aaf7dc7023 62 // Static Resources nailed to STRING type...
ansond 27:b8aaf7dc7023 63 int type = (int)M2MResourceInstance::STRING;
ansond 27:b8aaf7dc7023 64
ansond 27:b8aaf7dc7023 65 // check our Endpoint instance...
ansond 27:b8aaf7dc7023 66 if (ep != NULL) {
ansond 27:b8aaf7dc7023 67 // cast
ansond 27:b8aaf7dc7023 68 Connector::Endpoint *endpoint = (Connector::Endpoint *)ep;
ansond 27:b8aaf7dc7023 69
ansond 27:b8aaf7dc7023 70 // get our ObjectInstanceManager
ansond 27:b8aaf7dc7023 71 ObjectInstanceManager *oim = endpoint->getObjectInstanceManager();
ansond 27:b8aaf7dc7023 72
ansond 27:b8aaf7dc7023 73 if (this->getDataWrapper() != NULL) {
ansond 27:b8aaf7dc7023 74 // wrap the data...
ansond 27:b8aaf7dc7023 75 this->getDataWrapper()->wrap((uint8_t *)this->getValue().c_str(),(int)this->getValue().size());
ansond 27:b8aaf7dc7023 76
ansond 27:b8aaf7dc7023 77 // Create our Resource
ansond 27:b8aaf7dc7023 78 this->m_res = (M2MResource *)oim->createStaticResourceInstance((char *)this->getObjName().c_str(),(char *)this->getResName().c_str(),(char *)"StaticResource",(int)type,(void *)this->getDataWrapper()->get(),(int)this->getDataWrapper()->length());
ansond 27:b8aaf7dc7023 79 if (this->m_res != NULL) {
ansond 27:b8aaf7dc7023 80 // DEBUG
ansond 27:b8aaf7dc7023 81 this->logger()->log("StaticResource: [%s] value: [%s] bound",this->getFullName().c_str(),this->getDataWrapper()->get());
ansond 27:b8aaf7dc7023 82 }
ansond 27:b8aaf7dc7023 83 }
ansond 27:b8aaf7dc7023 84 else {
ansond 27:b8aaf7dc7023 85 // Create our Resource
ansond 27:b8aaf7dc7023 86 this->m_res = (M2MResource *)oim->createStaticResourceInstance((char *)this->getObjName().c_str(),(char *)this->getResName().c_str(),(char *)"StaticResource",(int)type,(void *)this->getValue().c_str(),(int)this->getValue().size());
ansond 27:b8aaf7dc7023 87 if (this->m_res != NULL) {
ansond 27:b8aaf7dc7023 88 this->logger()->log("StaticResource: [%s] value: [%s] bound",this->getFullName().c_str(),this->getValue().c_str());
ansond 27:b8aaf7dc7023 89 }
ansond 27:b8aaf7dc7023 90 }
ansond 27:b8aaf7dc7023 91 }
ansond 27:b8aaf7dc7023 92 else {
ansond 27:b8aaf7dc7023 93 // no instance pointer to our endpoint
ansond 27:b8aaf7dc7023 94 this->logger()->log("%s: NULL endpoint instance pointer in bind() request...",this->getFullName().c_str());
ansond 27:b8aaf7dc7023 95 }
ansond 27:b8aaf7dc7023 96 }