mbed Connector Interface simplification API on top of mbed-client
Fork of mbedConnectorInterfaceV3 by
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!
source/StaticResource.cpp@127:b4a661ff6fb9, 2017-09-26 (annotated)
- Committer:
- ansond
- Date:
- Tue Sep 26 16:01:31 2017 +0000
- Revision:
- 127:b4a661ff6fb9
- Parent:
- 45:db754b994deb
minor re-ordering of FCC init
Who changed what in which revision?
User | Revision | Line number | New 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 | 33:1d0b855df5a5 | 23 | // Class support |
ansond | 27:b8aaf7dc7023 | 24 | #include "mbed-connector-interface/StaticResource.h" |
ansond | 27:b8aaf7dc7023 | 25 | |
ansond | 27:b8aaf7dc7023 | 26 | // Endpoint |
ansond | 27:b8aaf7dc7023 | 27 | #include "mbed-connector-interface/ConnectorEndpoint.h" |
ansond | 27:b8aaf7dc7023 | 28 | |
ansond | 27:b8aaf7dc7023 | 29 | // Constructor |
ansond | 27:b8aaf7dc7023 | 30 | 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 | 31 | { |
ansond | 27:b8aaf7dc7023 | 32 | this->m_data_wrapper = NULL; |
ansond | 27:b8aaf7dc7023 | 33 | this->m_res = NULL; |
ansond | 27:b8aaf7dc7023 | 34 | } |
ansond | 27:b8aaf7dc7023 | 35 | |
ansond | 27:b8aaf7dc7023 | 36 | // Constructor |
ansond | 27:b8aaf7dc7023 | 37 | 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 | 38 | { |
ansond | 27:b8aaf7dc7023 | 39 | this->m_data_wrapper = NULL; |
ansond | 27:b8aaf7dc7023 | 40 | this->m_res = NULL; |
ansond | 27:b8aaf7dc7023 | 41 | } |
ansond | 27:b8aaf7dc7023 | 42 | |
ansond | 27:b8aaf7dc7023 | 43 | // Constructor with buffer lengths |
ansond | 27:b8aaf7dc7023 | 44 | 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 | 45 | { |
ansond | 27:b8aaf7dc7023 | 46 | this->m_data_wrapper = NULL; |
ansond | 27:b8aaf7dc7023 | 47 | this->m_res = NULL; |
ansond | 27:b8aaf7dc7023 | 48 | } |
ansond | 0:1f1f55e73248 | 49 | |
ansond | 27:b8aaf7dc7023 | 50 | // Copy constructor |
ansond | 27:b8aaf7dc7023 | 51 | StaticResource::StaticResource(const StaticResource &resource) : Resource<string>((const Resource<string> &)resource) |
ansond | 27:b8aaf7dc7023 | 52 | { |
ansond | 27:b8aaf7dc7023 | 53 | this->m_data_wrapper = resource.m_data_wrapper; |
ansond | 27:b8aaf7dc7023 | 54 | this->m_res = resource.m_res; |
ansond | 27:b8aaf7dc7023 | 55 | } |
ansond | 27:b8aaf7dc7023 | 56 | |
ansond | 27:b8aaf7dc7023 | 57 | // Destructor |
ansond | 27:b8aaf7dc7023 | 58 | StaticResource::~StaticResource() { |
ansond | 27:b8aaf7dc7023 | 59 | } |
ansond | 27:b8aaf7dc7023 | 60 | |
ansond | 27:b8aaf7dc7023 | 61 | // bind CoAP Resource.. |
ansond | 27:b8aaf7dc7023 | 62 | void StaticResource::bind(void *ep) { |
ansond | 27:b8aaf7dc7023 | 63 | // Static Resources nailed to STRING type... |
ansond | 27:b8aaf7dc7023 | 64 | int type = (int)M2MResourceInstance::STRING; |
ansond | 27:b8aaf7dc7023 | 65 | |
ansond | 27:b8aaf7dc7023 | 66 | // check our Endpoint instance... |
ansond | 27:b8aaf7dc7023 | 67 | if (ep != NULL) { |
ansond | 27:b8aaf7dc7023 | 68 | // cast |
ansond | 27:b8aaf7dc7023 | 69 | Connector::Endpoint *endpoint = (Connector::Endpoint *)ep; |
ansond | 27:b8aaf7dc7023 | 70 | |
ansond | 27:b8aaf7dc7023 | 71 | // get our ObjectInstanceManager |
ansond | 27:b8aaf7dc7023 | 72 | ObjectInstanceManager *oim = endpoint->getObjectInstanceManager(); |
ansond | 27:b8aaf7dc7023 | 73 | |
ansond | 27:b8aaf7dc7023 | 74 | if (this->getDataWrapper() != NULL) { |
ansond | 27:b8aaf7dc7023 | 75 | // wrap the data... |
ansond | 27:b8aaf7dc7023 | 76 | this->getDataWrapper()->wrap((uint8_t *)this->getValue().c_str(),(int)this->getValue().size()); |
ansond | 27:b8aaf7dc7023 | 77 | |
ansond | 27:b8aaf7dc7023 | 78 | // Create our Resource |
ansond | 27:b8aaf7dc7023 | 79 | 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 | 80 | if (this->m_res != NULL) { |
ansond | 45:db754b994deb | 81 | // Record our Instance Number |
ansond | 45:db754b994deb | 82 | this->setInstanceNumber(oim->getLastCreatedInstanceNumber()); |
ansond | 45:db754b994deb | 83 | |
ansond | 27:b8aaf7dc7023 | 84 | // DEBUG |
ansond | 27:b8aaf7dc7023 | 85 | this->logger()->log("StaticResource: [%s] value: [%s] bound",this->getFullName().c_str(),this->getDataWrapper()->get()); |
ansond | 27:b8aaf7dc7023 | 86 | } |
ansond | 27:b8aaf7dc7023 | 87 | } |
ansond | 27:b8aaf7dc7023 | 88 | else { |
ansond | 27:b8aaf7dc7023 | 89 | // Create our Resource |
ansond | 27:b8aaf7dc7023 | 90 | 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 | 91 | if (this->m_res != NULL) { |
ansond | 45:db754b994deb | 92 | // Record our Instance Number |
ansond | 45:db754b994deb | 93 | this->setInstanceNumber(oim->getLastCreatedInstanceNumber()); |
ansond | 45:db754b994deb | 94 | |
ansond | 45:db754b994deb | 95 | // DEBUG |
ansond | 27:b8aaf7dc7023 | 96 | this->logger()->log("StaticResource: [%s] value: [%s] bound",this->getFullName().c_str(),this->getValue().c_str()); |
ansond | 27:b8aaf7dc7023 | 97 | } |
ansond | 27:b8aaf7dc7023 | 98 | } |
ansond | 27:b8aaf7dc7023 | 99 | } |
ansond | 27:b8aaf7dc7023 | 100 | else { |
ansond | 27:b8aaf7dc7023 | 101 | // no instance pointer to our endpoint |
ansond | 27:b8aaf7dc7023 | 102 | this->logger()->log("%s: NULL endpoint instance pointer in bind() request...",this->getFullName().c_str()); |
ansond | 27:b8aaf7dc7023 | 103 | } |
ansond | 27:b8aaf7dc7023 | 104 | } |