mbed Connector Endpoint interface. This interface permits a mbed endpoint to easily setup MDS resources and emit those resources to an MDS server.

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

api/DynamicResource.h

Committer:
ansond
Date:
2015-01-27
Revision:
0:b438482ebbfc
Child:
2:853f9ecc12df

File content as of revision 0:b438482ebbfc:

/**
 * @file    DynamicResource.h
 * @brief   mbed CoAP Endpoint Dynamic 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.
 */
 
 #ifndef __DYNAMIC_RESOURCE_H__
 #define __DYNAMIC_RESOURCE_H__
 
 // Base Class
 #include "Resource.h"
 
 // NSDL Support
 #include "nsdl_support.h"
    
 class DynamicResource : public Resource<string> {
     public:
        /**
        Default constructor (char strings)
        @param logger input logger instance for this resource
        @param name input the Resource URI/Name
        @param res_type input type for the Resource
        @param res_mask input the resource enablement mask (GET, PUT, etc...)
        @param observable input the resource is Observable (default: FALSE)
        */
        DynamicResource(const Logger *logger,const char *name,const char *res_type,uint8_t res_mask,const bool observable = false);
        
        /**
        Default constructor (char strings)
        @param logger input logger instance for this resource
        @param name input the Resource URI/Name
        @param res_type input type for the Resource
        @param value input initial value for the Resource
        @param res_mask input the resource enablement mask (GET, PUT, etc...)
        @param observable input the resource is Observable (default: FALSE)
        */
        DynamicResource(const Logger *logger,const char *name,const char *res_type,const string value,uint8_t res_mask,const bool observable = false);

        /**
        constructor with string buffer for name
        @param logger input logger instance for this resource
        @param name input the Resource URI/Name
        @param res_type input type for the Resource
        @param value input initial value for the Resource
        @param res_mask input the resource enablement mask (GET, PUT, etc...)
        @param observable input the resource is Observable (default: FALSE)
        */
        DynamicResource(const Logger *logger,const string name,const string res_type,const string value,uint8_t res_mask,const bool observable = false);
                
        /**
        Copy constructor
        @param resource input the DynamicResource that is to be deep copied
        */
        DynamicResource(const DynamicResource &resource);
        
        /**
        Destructor
        */
        virtual ~DynamicResource();
        
        /**
        Bind resource to endpoint
        @param p input pointer to the endpoint resources necessary for binding
        */
        virtual void bind(void *p);
        
        /**
        Process the CoAP message
        @param received_coap_ptr input the received coap pointer
        @param address input the NSDL address pointer
        @param proto input the NSDL protocol pointer
        @return 0 - success, 1 - failure
        */
        uint8_t process(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto);
        
        /**
        Resource value getter (REQUIRED: must be implemented in derived class as all Binders MUST support and implement GET)
        @returns string value of the resource 
        */
        virtual string get() = 0;
        
        /** 
        Resource value setter (OPTIONAL: defaulted noop if not derived. Binders MAY implement PUT if needed)
        @param string value of the resource
        */
        virtual void put(const string value);
        
    protected:
        
    private:
        
        string      m_res_type;
        uint8_t     m_res_mask;
        bool        m_observable;
        
        // convenience method to create a string from the NSDL CoAP data buffers...
        string coapDataToString(uint8_t *coap_data_ptr,int coap_data_ptr_length);
 };
 
 #endif // __DYNAMIC_RESOURCE_H__