Mistake on this page? Email us
m2mdevice.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2019 ARM Limited. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  * Licensed under the Apache License, Version 2.0 (the License); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef M2M_DEVICE_H
17 #define M2M_DEVICE_H
18 
19 #include "mbed-client/m2mobject.h"
20 
21 // FORWARD DECLARATION
22 class M2MResource;
24 
33 class M2MDevice : public M2MObject {
34 
35 friend class M2MInterfaceFactory;
36 
37 public:
38 
43  typedef enum {
44  Manufacturer,
45  DeviceType,
46  ModelNumber,
47  SerialNumber,
48  HardwareVersion,
49  FirmwareVersion,
50  SoftwareVersion,
51  Reboot,
52  FactoryReset,
53  AvailablePowerSources,
54  PowerSourceVoltage,
55  PowerSourceCurrent,
56  BatteryLevel,
57  BatteryStatus,
58  MemoryFree,
59  MemoryTotal,
60  ErrorCode,
61  ResetErrorCode,
62  CurrentTime,
63  UTCOffset,
64  Timezone,
65  SupportedBindingMode
67 
68 private:
69 
73  M2MDevice(char *path);
74 
75  // Prevents the use of assignment operator.
76  M2MDevice& operator=( const M2MDevice& /*other*/ );
77 
78  // Prevents the use of copy constructor
79  M2MDevice( const M2MDevice& /*other*/ );
80 
84  virtual ~M2MDevice();
85 
86  static M2MDevice* get_instance();
87 
88 public:
89 
93  static void delete_instance();
94 
104  M2MResource* create_resource(DeviceResource resource, const String &value);
105 
116  M2MResource* create_resource(DeviceResource resource, int64_t value);
117 
126  M2MResourceInstance* create_resource_instance(DeviceResource resource, int64_t value,
127  uint16_t instance_id);
128 
135  M2MResource* create_resource(DeviceResource resource);
136 
143  bool delete_resource(DeviceResource resource);
144 
152  bool delete_resource_instance(DeviceResource resource,
153  uint16_t instance_id);
154 
165  bool set_resource_value(DeviceResource resource,
166  const String &value,
167  uint16_t instance_id = 0);
168 
179  bool set_resource_value(DeviceResource resource,
180  int64_t value,
181  uint16_t instance_id = 0);
182 
192  String resource_value_string(DeviceResource resource,
193  uint16_t instance_id = 0) const;
194 
204  int64_t resource_value_int(DeviceResource resource,
205  uint16_t instance_id = 0) const;
206 
212  bool is_resource_present(DeviceResource resource)const;
213 
218  uint16_t total_resource_count()const;
219 
227  uint16_t per_resource_count(DeviceResource resource)const;
228 
229 private:
230 
231  M2MResourceBase* get_resource_instance(DeviceResource dev_res,
232  uint16_t instance_id) const;
233 
234  static const char* resource_name(DeviceResource resource);
235 
236  static bool check_value_range(DeviceResource resource, const int64_t value);
237 
238 private :
239 
240  M2MObjectInstance* _device_instance; //Not owned
241 
242 protected:
243 
244  static M2MDevice* _instance;
245 
246  friend class Test_M2MDevice;
247  friend class Test_M2MInterfaceFactory;
248 };
249 
250 #endif // M2M_DEVICE_H
Definition: m2mobject.h:35
bool set_resource_value(DeviceResource resource, const String &value, uint16_t instance_id=0)
Sets the value of the given resource enum.
M2MResource * create_resource(DeviceResource resource, const String &value)
Creates a new resource for the given resource enum.
bool delete_resource(DeviceResource resource)
Deletes the resource with the given resource enum. Mandatory resources cannot be deleted.
header M2MObject
bool is_resource_present(DeviceResource resource) const
Indicates whether the resource instance with the given resource enum exists or not.
Definition: m2mobjectinstance.h:42
Definition: m2mdevice.h:33
DeviceResource
An enum defining all the resources associated with the Device Object in the LWM2M framework...
Definition: m2mdevice.h:43
uint16_t per_resource_count(DeviceResource resource) const
Returns the number of resources for a given resource enum.
int64_t resource_value_int(DeviceResource resource, uint16_t instance_id=0) const
Returns the value of the given resource key name, in integer format.
String resource_value_string(DeviceResource resource, uint16_t instance_id=0) const
Returns the value of the given resource enum, in string format.
static void delete_instance()
Deletes an M2MDevice instance.
Definition: m2mresourceinstance.h:38
Definition: m2mresourcebase.h:49
uint16_t total_resource_count() const
Returns the number of resources for the whole device object.
Definition: m2mresource.h:38
M2MResourceInstance * create_resource_instance(DeviceResource resource, int64_t value, uint16_t instance_id)
Creates a new resource instance for the given resource enum.
bool delete_resource_instance(DeviceResource resource, uint16_t instance_id)
Deletes the resource with the given resource enum. Mandatory resources cannot be deleted.
Definition: m2minterfacefactory.h:36
uint16_t instance_id() const
Returns the object's instance ID.