Mistake on this page? Email us
SimpleM2MResource.h
1 // ----------------------------------------------------------------------------
2 // Copyright 2016-2017 ARM Ltd.
3 //
4 // SPDX-License-Identifier: Apache-2.0
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 // ----------------------------------------------------------------------------
18 
19 #ifndef SIMPLE_M2M_RESOURCE_H
20 #define SIMPLE_M2M_RESOURCE_H
21 
23 
24 // As this whole class is build by using C++'s standard template library (STL),
25 // we have it behind a flag. The cost of STL is 15KB of flash, depending on compiler,
26 // so on resource constrained devices it is essential to be able to remove any reference to it.
27 #if MBED_CLOUD_CLIENT_STL_API
28 
29 #include <string>
30 
38 class SimpleM2MResourceBase {
39 
40 protected:
41 
42  // Prevents the use of default constructor.
43  SimpleM2MResourceBase();
44 
45  // Prevents the use of assignment operator.
46  SimpleM2MResourceBase& operator=( const SimpleM2MResourceBase& /*other*/ );
47 
48  // Prevents the use of copy constructor
49  SimpleM2MResourceBase( const M2MBase& /*other*/ );
50 
51  SimpleM2MResourceBase(MbedCloudClient* client, string route);
52 
56  virtual ~SimpleM2MResourceBase();
57 
58 
59 public:
60 
70  bool define_resource_internal(string v,
71  M2MBase::Operation opr,
72  bool observable);
73 
78  string get() const;
79 
85  bool set(string v);
86 
92  bool set(const int& v);
93 
101  bool set_post_function(void(*fn)(void*));
102 
110  bool set_post_function(execute_callback fn);
111 
117  M2MResource* get_resource();
118 
123  virtual void update(){}
124 
125 private:
126 
133  vector<string> parse_route(const char* route);
134 
135 private:
136  MbedCloudClient* _client; // Not owned
137  string _route;
138 };
139 
147 class SimpleM2MResourceString : public SimpleM2MResourceBase
148 {
149 public:
150 
163  SimpleM2MResourceString(MbedCloudClient* client,
164  const char* route,
165  string v,
166  M2MBase::Operation opr = M2MBase::GET_PUT_ALLOWED,
167  bool observable = true,
168  FP1<void, string> on_update = NULL) m2m_deprecated;
169 
182  SimpleM2MResourceString(MbedCloudClient* client,
183  const char* route,
184  string v,
185  M2MBase::Operation opr,
186  bool observable,
187  void(*on_update)(string)) m2m_deprecated;
188 
189 
193  virtual ~SimpleM2MResourceString();
194 
198  string operator=(const string& new_value);
199 
203  operator string() const;
204 
209  virtual void update();
210 
211 private:
212  FP1<void, string> _on_update;
213 };
214 
222 class SimpleM2MResourceInt : public SimpleM2MResourceBase
223 {
224 public:
225 
238  SimpleM2MResourceInt(MbedCloudClient* client,
239  const char* route,
240  int v,
241  M2MBase::Operation opr = M2MBase::GET_PUT_ALLOWED,
242  bool observable = true,
243  FP1<void, int> on_update = NULL) m2m_deprecated;
244 
257  SimpleM2MResourceInt(MbedCloudClient* client,
258  const char* route,
259  int v,
260  M2MBase::Operation opr,
261  bool observable,
262  void(*on_update)(int)) m2m_deprecated;
263 
267  virtual ~SimpleM2MResourceInt();
268 
272  int operator=(int new_value);
273 
277  operator int() const;
278 
283  virtual void update();
284 
285 private:
286  FP1<void, int> _on_update;
287 };
288 
289 #endif
290 
291 #endif // SIMPLE_M2M_RESOURCE_H
Definition: MbedCloudClient.h:85
MbedCloudClient. This class provides an interface for handling all the client interface operations in...