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 
38 class M2MDevice : public M2MObject {
39 
40 friend class M2MInterfaceFactory;
41 
42 public:
43 
48  typedef enum {
49  Manufacturer,
50  DeviceType,
51  ModelNumber,
52  SerialNumber,
53  HardwareVersion,
54  FirmwareVersion,
55  SoftwareVersion,
56  Reboot,
57  FactoryReset,
58  AvailablePowerSources,
59  PowerSourceVoltage,
60  PowerSourceCurrent,
61  BatteryLevel,
62  BatteryStatus,
63  MemoryFree,
64  MemoryTotal,
65  ErrorCode,
66  ResetErrorCode,
67  CurrentTime,
68  UTCOffset,
69  Timezone,
70  SupportedBindingMode
72 
73 private:
74 
78  M2MDevice(char *path);
79 
80  // Prevents the use of assignment operator.
81  M2MDevice& operator=( const M2MDevice& /*other*/ );
82 
83  // Prevents the use of copy constructor
84  M2MDevice( const M2MDevice& /*other*/ );
85 
89  virtual ~M2MDevice();
90 
91  static M2MDevice* get_instance();
92 
93 public:
94 
98  static void delete_instance();
99 
109  M2MResource* create_resource(DeviceResource resource, const String &value);
110 
121  M2MResource* create_resource(DeviceResource resource, int64_t value);
122 
131  M2MResourceInstance* create_resource_instance(DeviceResource resource, int64_t value,
132  uint16_t instance_id);
133 
140  M2MResource* create_resource(DeviceResource resource);
141 
148  bool delete_resource(DeviceResource resource);
149 
157  bool delete_resource_instance(DeviceResource resource,
158  uint16_t instance_id);
159 
170  bool set_resource_value(DeviceResource resource,
171  const String &value,
172  uint16_t instance_id = 0);
173 
184  bool set_resource_value(DeviceResource resource,
185  int64_t value,
186  uint16_t instance_id = 0);
187 
197  String resource_value_string(DeviceResource resource,
198  uint16_t instance_id = 0) const;
199 
209  int64_t resource_value_int(DeviceResource resource,
210  uint16_t instance_id = 0) const;
211 
217  bool is_resource_present(DeviceResource resource)const;
218 
223  uint16_t total_resource_count()const;
224 
232  uint16_t per_resource_count(DeviceResource resource)const;
233 
234 private:
235 
236  M2MResourceBase* get_resource_instance(DeviceResource dev_res,
237  uint16_t instance_id) const;
238 
239  static const char* resource_name(DeviceResource resource);
240 
241  static bool check_value_range(DeviceResource resource, const int64_t value);
242 
243 private :
244 
245  M2MObjectInstance* _device_instance; //Not owned
246 
247 protected:
248 
249  static M2MDevice* _instance;
250 
251  friend class Test_M2MDevice;
252  friend class Test_M2MInterfaceFactory;
253 };
254 
255 #endif // M2M_DEVICE_H
The base class for Client Objects.
Definition: m2mobject.h:39
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.
M2MObject. This class is the base class for the mbed Client Objects.
bool is_resource_present(DeviceResource resource) const
Indicates whether the resource instance with the given resource enum exists or not.
Definition: m2mobjectinstance.h:36
A class representin the Device Object model of the LwM2M framework.
Definition: m2mdevice.h:38
DeviceResource
An enum defining all the resources associated with the Device Object in the LWM2M framework...
Definition: m2mdevice.h:48
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.
Definition: m2mstring.h:33
static void delete_instance()
Deletes an M2MDevice instance.
Definition: m2mresourceinstance.h:32
Definition: m2mresourcebase.h:43
uint16_t total_resource_count() const
Returns the number of resources for the whole device object.
The base class for Client Resources.
Definition: m2mresource.h:40
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.