observe updates

Fork of mbedConnectorInterface by Doug Anson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Resource.h Source File

Resource.h

Go to the documentation of this file.
00001 /**
00002  * @file    Resource.h
00003  * @brief   mbed CoAP Endpoint Resource base class template
00004  * @author  Doug Anson/Chris Paola
00005  * @version 1.0
00006  * @see
00007  *
00008  * Copyright (c) 2014
00009  *
00010  * Licensed under the Apache License, Version 2.0 (the "License");
00011  * you may not use this file except in compliance with the License.
00012  * You may obtain a copy of the License at
00013  *
00014  *     http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing, software
00017  * distributed under the License is distributed on an "AS IS" BASIS,
00018  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  * See the License for the specific language governing permissions and
00020  * limitations under the License.
00021  */
00022 
00023 #ifndef __RESOURCE_H__
00024 #define __RESOURCE_H__
00025 
00026 // logging facility
00027 #include "Logger.h"
00028 
00029 // string support
00030 #include <string>
00031 
00032 /** Resource class
00033  */
00034 template <typename InnerType> class Resource
00035 {
00036 public:
00037     /**
00038     Default constructor
00039     @param logger input the Logger instance this Resource is a part of
00040     @param name input the Resource URI/Name
00041     @param value input the Resource value
00042     */
00043     Resource(const Logger *logger,const string name,InnerType value)  {
00044         this->init(logger);
00045         this->m_name = name;
00046         this->m_value = value;
00047         this->m_implements_observation = false;
00048     }
00049 
00050     /**
00051     Copy constructor
00052     @param resource input the Resource that is to be deep copied
00053     */
00054     Resource(const Resource<InnerType> &resource) {
00055         this->init(resource.m_logger);
00056         this->m_endpoint = resource.m_endpoint;
00057         this->m_name = resource.m_name;
00058         this->m_value = resource.m_value;
00059         this->m_implements_observation = resource.m_implements_observation;
00060     }
00061 
00062     /**
00063     Destructor
00064     */
00065     virtual ~Resource() {
00066     }
00067 
00068     /**
00069     Get the resource name
00070     @return the name of the resource
00071     */
00072     string getName() {
00073         return this->m_name;
00074     }
00075 
00076     /**
00077     Get the resource value
00078     @return the value of the resource
00079     */
00080     InnerType getValue() {
00081         return this->m_value;
00082     }
00083 
00084     /**
00085     Set the resource name
00086     @param name input the resource name
00087     */
00088     void setName(const string name) {
00089         this->m_name = name;
00090     }
00091 
00092     /**
00093     Set the resource value
00094     @param value input the resource value
00095     */
00096     void setValue(const InnerType value) {
00097         this->m_value = value;
00098     }
00099 
00100     /**
00101     Bind resource to endpoint
00102     */
00103     virtual void bind(void *p) = 0;
00104 
00105     // access the logger()
00106     Logger *logger() {
00107         return this->m_logger;
00108     }
00109     
00110     // this resource implements its own observation handler
00111     bool implementsObservation() { return this->m_implements_observation; }
00112 
00113 protected:
00114     // initialize internals to Resource
00115     void init(const Logger *logger) {
00116         this->m_logger = (Logger *)logger;
00117         this->m_endpoint = NULL;
00118         this->m_name = "";
00119         this->m_value = "";
00120     }
00121     
00122     Logger      *m_logger;
00123     void        *m_endpoint;
00124     string       m_name;
00125     InnerType    m_value;
00126     bool         m_implements_observation;
00127 };
00128 
00129 #endif // __RESOURCE_H__