This is the sample program that can see the decode result of barcode data on Watson IoT.

Dependencies:   AsciiFont DisplayApp GR-PEACH_video LCD_shield_config LWIPBP3595Interface_STA_for_mbed-os USBDevice

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 "mbed-connector-interface/Logger.h"
00028 
00029 // mbed-client support
00030 #include "mbed-client/m2minterfacefactory.h"
00031 #include "mbed-client/m2minterfaceobserver.h"
00032 #include "mbed-client/m2minterface.h"
00033 #include "mbed-client/m2mobjectinstance.h"
00034 #include "mbed-client/m2mresource.h"
00035 #include "mbed-client/m2mdevice.h"
00036 #include "mbed-client/m2mfirmware.h"
00037 
00038 // string support
00039 #include <string>
00040 
00041 /** Resource class
00042  */
00043 template <typename InnerType> class Resource
00044 {
00045 public:
00046     // Available Resource Types
00047     typedef enum {
00048         STRING,
00049         INTEGER,
00050         FLOAT,
00051         BOOLEAN,
00052         OPAQUE,
00053         TIME,
00054         OBJLINK
00055     }ResourceType;
00056     
00057     /**
00058     Default constructor
00059     @param logger input the Logger instance this Resource is a part of
00060     @param obj_name input the Object Name
00061     @param res_name input the Resource URI/Name
00062     @param value input the Resource value
00063     */
00064     Resource(const Logger *logger,const string obj_name,const string res_name,InnerType value)  {
00065         this->init(logger);
00066         this->m_obj_name = obj_name;
00067         this->m_res_name = res_name;
00068         this->m_value = value;
00069         this->m_implements_observation = false;
00070         this->m_instance_number = 0;
00071     }
00072 
00073     /**
00074     Copy constructor
00075     @param resource input the Resource that is to be deep copied
00076     */
00077     Resource(const Resource<InnerType> &resource) {
00078         this->init(resource.m_logger);
00079         this->m_endpoint = resource.m_endpoint;
00080         this->m_obj_name = resource.m_obj_name;
00081         this->m_res_name = resource.m_res_name;
00082         this->m_value = resource.m_value;
00083         this->m_implements_observation = resource.m_implements_observation;
00084         this->m_instance_number = resource.m_instance_number;
00085     }
00086 
00087     /**
00088     Destructor
00089     */
00090     virtual ~Resource() {
00091     }
00092 
00093     /**
00094     Get the Object name
00095     @return the name of the object
00096     */
00097     string getObjName() {
00098         return this->m_obj_name;
00099     }
00100     
00101     /**
00102     Get the Resource name
00103     @return the name of the resource
00104     */
00105     string getResName() {
00106         return this->m_res_name;
00107     }
00108     
00109     /**
00110     Get the Full  name
00111     @return the name of the object
00112     */
00113     string getFullName() {
00114         char buf[5];
00115         memset(buf,0,5);
00116         sprintf(buf,"/%d/",this->m_instance_number);
00117         return this->m_obj_name + buf + this->m_res_name;
00118     }
00119 
00120     /**
00121     Get the resource value
00122     @return the value of the resource
00123     */
00124     InnerType getValue() {
00125         return this->m_value;
00126     }
00127 
00128     /**
00129     Set the resource name
00130     @param name input the resource name
00131     */
00132     void setName(const string name) {
00133         this->m_name = name;
00134     }
00135 
00136     /**
00137     Set the resource value
00138     @param value input the resource value
00139     */
00140     void setValue(const InnerType value) {
00141         this->m_value = value;
00142     }
00143 
00144     /**
00145     Bind resource to endpoint
00146     @param ep input pointer to the Endpoint instance
00147     */
00148     virtual void bind(void *ep) = 0;
00149 
00150     // access the logger()
00151     Logger *logger() {
00152         return this->m_logger;
00153     }
00154 
00155     /**
00156     set the options
00157     */
00158     void setOptions(const void *options) {
00159         this->m_options = (void *)options;
00160     }
00161     
00162     /**
00163     set the endpoint
00164     */
00165     void setEndpoint(const void *endpoint) {
00166         this->m_endpoint = (void *)endpoint;
00167     }
00168 
00169     // this resource implements its own observation handler
00170     bool implementsObservation() { return this->m_implements_observation; }
00171     
00172     /**
00173     Get our Instance Number
00174     @return our instance number
00175     */
00176     int getInstanceNumber() { return this->m_instance_number; }
00177     
00178     /**
00179     Set our Instance Number
00180     @param instance_number input our designated instance number
00181     */
00182     void setInstanceNumber(int instance_number) { this->m_instance_number = instance_number; }
00183 
00184 protected:
00185     // initialize internals to Resource
00186     void init(const Logger *logger) {
00187         this->m_logger = (Logger *)logger;
00188         this->m_endpoint = NULL;
00189         this->m_obj_name = "";
00190         this->m_res_name = "";
00191         this->m_value = "";
00192         this->m_instance_number = 0;
00193     }
00194 
00195     // get our options
00196     void *getOptions() {
00197         return this->m_options;
00198     }
00199 
00200     Logger         *m_logger;
00201     void           *m_endpoint;
00202     string          m_obj_name;
00203     string          m_res_name;
00204     InnerType       m_value;
00205     bool            m_implements_observation;
00206     void           *m_options;
00207     int             m_instance_number;
00208 };
00209 
00210 #endif // __RESOURCE_H__
00211