custom for >5 resources

Fork of mbedConnectorInterface by Doug Anson

api/StaticResource.cpp

Committer:
sam_grove
Date:
2015-01-27
Revision:
2:853f9ecc12df
Parent:
0:b438482ebbfc
Child:
5:a929d65eb385

File content as of revision 2:853f9ecc12df:

/**
 * @file    StaticResource.h
 * @brief   mbed CoAP Endpoint Static Resource class
 * @author  Doug Anson/Chris Paola
 * @version 1.0
 * @see
 *
 * Copyright (c) 2014
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "StaticResource.h"

// NSDL libraries
#include "nsdl_support.h"

// Constructor
StaticResource::StaticResource(const Logger *logger,const char *name, const char *value) : Resource<string>(logger,string(name),string(value))
{
}

// Constructor
StaticResource::StaticResource(const Logger *logger,const char *name,const string value) : Resource<string>(logger,string(name),string(value))
{
}

// Constructor with buffer lengths
StaticResource::StaticResource(const Logger *logger,const string name,const string value) : Resource<string>(logger,string(name),string(value))
{
}

// Copy constructor
StaticResource::StaticResource(const StaticResource &resource) : Resource<string>((const Resource<string> &)resource)
{
}

// Destructor
StaticResource::~StaticResource()
{
}

// Bind resource to Endpoint
void StaticResource::bind(void *p)
{
    if (p != NULL) {
        sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p;
        std::printf("StaticResource: name[%s] value:[%s]\r\n",this->getName().c_str(),this->getValue().c_str());
        const uint8_t *name = (const uint8_t *)(this->getName().c_str());
        const uint8_t *value = (const uint8_t *)(this->getValue().c_str());
        int name_length = this->getName().size();
        int value_length = this->getValue().size();
        nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,(uint8_t *)value,value_length);
        std::printf("StaticResource[%s(%d)] value: %s(%d) bound\r\n",name,name_length,value,value_length);
    } else {
        std::printf("StaticResource: NULL parameter in bind()\r\n");
    }
}