mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface
Embed:
(wiki syntax)
Show/hide line numbers
DeviceIntegerResource.h
Go to the documentation of this file.
00001 /** 00002 * @file DeviceIntegerResource.h 00003 * @brief mbed CoAP Endpoint Device Integer Resource 00004 * @author Doug Anson 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 __DEVICE_INTEGER_RESOURCE_H__ 00024 #define __DEVICE_INTEGER_RESOURCE_H__ 00025 00026 // Base class 00027 #include "mbed-connector-interface/DynamicResource.h" 00028 00029 // Device Management Responder 00030 #include "mbed-connector-interface/DeviceManagementResponder.h" 00031 00032 /** DeviceIntegerResource class 00033 */ 00034 class DeviceIntegerResource : public DynamicResource 00035 { 00036 public: 00037 /** 00038 Default constructor 00039 @param logger input logger instance for this resource 00040 @param obj_name input the Integer Object ID 00041 @param res_name input the Integer Resource ID 00042 @param res_type input the Integer Resource Type 00043 @param dm_responder input the DM responder instance 00044 @param observable input this Integer is observable 00045 */ 00046 DeviceIntegerResource(const Logger *logger,const char *obj_name,const char *res_name,const char *res_type,const void *dm_responder,bool observable = false) : 00047 DynamicResource(logger,obj_name,res_name,res_type,M2MBase::GET_PUT_ALLOWED,observable) 00048 { 00049 this->m_dm_responder = (DeviceManagementResponder *)dm_responder; 00050 this->m_implements_observation = true; // PUT() sends observation... 00051 } 00052 00053 /** 00054 GET handler 00055 @returns string with this resource type 00056 */ 00057 virtual string get() { 00058 char buf[10]; 00059 memset(buf,0,10); 00060 sprintf(buf,"%d",this->m_value); 00061 return string(buf); 00062 } 00063 00064 /** 00065 PUT handler 00066 @param value input input value 00067 */ 00068 virtual void put(string value) { 00069 sscanf(value.c_str(),"%d",&this->m_value); 00070 this->observe(); 00071 } 00072 00073 protected: 00074 DeviceManagementResponder *m_dm_responder; 00075 00076 private: 00077 int m_value; 00078 }; 00079 00080 #endif // __DEVICE_INTEGER_RESOURCE_H__
Generated on Wed Jul 13 2022 21:59:32 by
1.7.2