1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 /// @file ThingsManager.h
23 /// @brief This file contains the declaration of ThingsManager class
24 /// and its members related to ThingsManager.
26 #ifndef __OC_THINGSMANAGER__
27 #define __OC_THINGSMANAGER__
33 #include "OCPlatform.h"
35 #include "GroupManager.h"
42 * @class ThingsManager
43 * @brief This class provides a set of functions regarding group management,
44 * synchronization of group, configuration of things, and diagnostics about things.
51 * Constructor for ThingsManager
56 * Virtual destructor for ThingsManager
61 * API for discoverying candidate resources.
62 * Callback is called when all resource types are found.
64 * @param resourceTypes - required resource types(called "candidate")
65 * @param candidateCallback - callback. Returns OCResource vector.
67 * @return OCStackResult - return value of this API.
68 * It returns OC_STACK_OK if success.
70 * NOTE: OCStackResult is defined in ocstack.h.
72 OCStackResult findCandidateResources(std::vector< std::string > resourceTypes,
73 std::function< void(std::vector< std::shared_ptr< OCResource > >) > callback,
77 * API for subscribing child's state.
79 * @param resource - collection resource for subscribing presence of all child resources.
80 * @param callback - callback funcion for result of child's presence.
82 * @return OCStackResult - return value of this API.
83 * It returns OC_STACK_OK if success.
85 * NOTE: OCStackResult is defined in ocstack.h.
87 OCStackResult subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
88 std::function< void(std::string, OCStackResult) > callback);
91 * API for register and bind resource to group.
93 * @param childHandle - child resource handle. It will be filled from resource param.
94 * @param resource - resource for register and bind to group. It has all data.
95 * @param collectionHandle - collection resource handle. It will be added child resource.
97 * @return OCStackResult - return value of this API.
98 * It returns OC_STACK_OK if success.
100 * NOTE: OCStackResult is defined in ocstack.h.
102 OCStackResult bindResourceToGroup(OCResourceHandle& childHandle,
103 std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
105 // Group Synchronization
108 * API for finding a specific remote group when a resource tries to join a group.
109 * Callback is called when a group is found or not.
111 * @param collectionResourceTypes - resource types of a group to find and join
112 * @param callback - callback. It has OCResource param.
113 * If a group is found, OCResource has the group resource.
114 * Otherwise, OCResource is NULL.
116 * @return OCStackResult - return value of this API.
117 * It returns OC_STACK_OK if success.
119 * NOTE: OCStackResult is defined in ocstack.h.
121 OCStackResult findGroup(std::vector< std::string > collectionResourceTypes,
122 FindCallback callback);
125 * API for creating a new group.
127 * @param collectionResourceType - resource type of a group to create
129 * @return OCStackResult - return value of this API.
130 * It returns OC_STACK_OK if success.
132 * NOTE: OCStackResult is defined in ocstack.h.
134 OCStackResult createGroup(std::string collectionResourceType);
137 * API for joining a group. This API is used when a resource that has a group tries
138 * to find a specific remote resource and makes it join a group
140 * @param collectionResourceType - resource type of a group to join.
141 * @param resourceHandle - resource handle to join a group.
143 * @return OCStackResult - return value of this API.
144 * It returns OC_STACK_OK if success.
146 * NOTE: OCStackResult is defined in ocstack.h.
148 OCStackResult joinGroup(std::string collectionResourceType,
149 OCResourceHandle resourceHandle);
152 * API for joining a group. This API is used when a resource that
153 * doesn't have a group tries to find and join a specific remote group.
155 * @param resource - group resource pointer to join.
156 * It can be the callback result of findGroup().
157 * @param resourceHandle - resource handle to join a group.
159 * @return OCStackResult - return value of this API.
160 * It returns OC_STACK_OK if success.
162 * NOTE: OCStackResult is defined in ocstack.h.
164 OCStackResult joinGroup(const std::shared_ptr< OCResource > resource,
165 OCResourceHandle resourceHandle);
168 * API for leaving a joined group.
170 * @param collectionResourceType - resource type of a group to leave.
171 * @param resourceHandle - resource handle to leave a group.
173 * @return OCStackResult - return value of this API.
174 * It returns OC_STACK_OK if success.
176 * NOTE: OCStackResult is defined in ocstack.h.
178 OCStackResult leaveGroup(std::string collectionResourceType,
179 OCResourceHandle resourceHandle);
182 * API for deleting a group.
184 * @param collectionResourceType - resource type of a group to delete.
188 void deleteGroup(std::string collectionResourceType);
191 * API for getting a list of joined groups.
195 * @return std::map - return value of this API.
196 * It returns group resource type and group resource handle as a map type.
198 std::map< std::string, OCResourceHandle > getGroupList(void);
200 // Things Configuration
203 * API for updating configuration value of multiple things of a target group
205 * Callback is called when a response arrives.
206 * Before using the below function, a developer should acquire a resource pointer of
207 * (collection) resource that he wants to send a request by calling findResource() function
208 * provided in OCPlatform. And he should also notice a "Configuration Name" term which
209 * represents a nickname of a target attribute of a resource that he wants to update.
210 * The base motivation to introduce the term is to avoid a usage of URI to access a resource
211 * from a developer. Thus, a developer should know which configuration names are supported
212 * by Things Configuration class and what the configuration name means.
213 * To get a list of supported configuration names,
214 * use getListOfSupportedConfigurationUnits()
215 * function, which provides the list in JSON format.
217 * @param resource - resource pointer representing the target group or the single thing.
218 * @param configurations - ConfigurationUnit: a nickname of attribute of target resource
219 * (e.g., installedlocation, currency, (IP)address)
220 * Value : a value to be updated
221 * @param callback - callback for updateConfigurations.
223 * @return OCStackResult - return value of this API.
224 * It returns OC_STACK_OK if success.
226 * NOTE: OCStackResult is defined in ocstack.h.
228 OCStackResult updateConfigurations(std::shared_ptr< OCResource > resource,
229 std::map< std::string, std::string > configurations,
231 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
232 const int eCode) > callback);
235 * API for getting configuration value of multiple things of a target group
237 * Callback is called when a response arrives.
239 * @param resource - resource pointer representing the target group or the single thing.
240 * @param configurations - ConfigurationUnit: a nickname of attribute of target resource.
241 * @param callback - callback for getConfigurations.
243 * @return OCStackResult - return value of this API.
244 * It returns OC_STACK_OK if success.
246 * NOTE: OCStackResult is defined in ocstack.h.
248 OCStackResult getConfigurations(std::shared_ptr< OCResource > resource,
249 std::vector< std::string > configurations,
251 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
252 const int eCode) > callback);
255 * API for showing the list of supported configuration units (configurable parameters)
256 * Callback is called when a response arrives.
259 * @return std::string - return value of this API.
260 * It returns the list in JSON format
262 std::string getListOfSupportedConfigurationUnits();
265 * API for boostrapping system configuration parameters from a bootstrap server.
266 * Callback call when a response from the bootstrap server arrives.
268 * @param callback - callback for doBootstrap.
270 * @return OCStackResult - return value of this API.
271 * It returns OC_STACK_OK if success.
273 * NOTE: OCStackResult is defined in ocstack.h.
275 OCStackResult doBootstrap(
277 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
278 const int eCode) > callback);
280 // Things Diagnostics
283 * API to let thing(device) reboot.
284 * The target thing could be a group of multiple things or a single thing.
285 * Callback is called when a response arrives.
287 * @param resource - resource pointer representing the target group
288 * @param callback - callback for reboot.
290 * @return OCStackResult - return value of this API.
291 * It returns OC_STACK_OK if success.
293 * NOTE: OCStackResult is defined in ocstack.h.
295 OCStackResult reboot(std::shared_ptr< OCResource > resource,
297 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
298 const int eCode) > callback);
301 * API for factory reset on thing(device).
302 * The target thing could be a group of multiple things or a single thing.
303 * Callback is called when a response arrives.
305 * @param resource - resource pointer representing the target group
306 * @param callback - callback for factoryReset.
308 * @return OCStackResult - return value of this API.
309 * It returns OC_STACK_OK if success.
311 * NOTE: OCStackResult is defined in ocstack.h.
313 OCStackResult factoryReset(std::shared_ptr< OCResource > resource,
315 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
316 const int eCode) > callback);
321 * API for extracting Action Set string from the Action Set class instance
323 * @param newActionSet - pointer of Action Set
325 * @return std::string - return value of this API.
326 * It returns Action Set String.
328 * NOTE: OCStackResult is defined in ocstack.h.
330 std::string getStringFromActionSet(const ActionSet *newActionSet);
333 * API for extrracting Action Set class instance from Action Set String.
335 * @param desc - description of Action set
337 * @return ActionSet* - return value of this API.
338 * It returns pointer of ActionSet.
340 ActionSet* getActionSetfromString(std::string desc);
343 * API for adding an Action Set.
344 * Callback is called when the response of PUT operation arrives.
346 * @param resource - resource pointer of the group resource
347 * @param newActionSet - pointer of Action Set
348 * @param callback - callback for PUT operation.
350 * @return OCStackResult - return value of this API.
351 * It returns OC_STACK_OK if success.
353 * NOTE: OCStackResult is defined in ocstack.h.
355 OCStackResult addActionSet(std::shared_ptr< OCResource > resource,
356 const ActionSet* newActionSet, PutCallback cb);
359 * API for executing the Action Set.
360 * Callback is called when the response of POST operation arrives.
362 * @param resource - resource pointer of the group resource
363 * @param actionsetName - Action Set name for executing the Action set
364 * @param callback - callback for POST operation.
366 * @return OCStackResult - return value of this API.
367 * It returns OC_STACK_OK if success.
369 * NOTE: OCStackResult is defined in ocstack.h.
371 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
372 std::string actionsetName, PostCallback cb);
375 * API for reading the Action Set.
376 * Callback is called when the response of GET operation arrives.
378 * @param resource - resource pointer of the group resource
379 * @param actionsetName - Action Set name for reading the Action set
380 * @param callback - callback for GET operation.
382 * @return OCStackResult - return value of this API.
383 * It returns OC_STACK_OK if success.
385 * NOTE: OCStackResult is defined in ocstack.h.
387 OCStackResult getActionSet(std::shared_ptr< OCResource > resource,
388 std::string actionsetName, GetCallback cb);
391 * API for removing the Action Set.
392 * Callback is called when the response of POST operation arrives.
394 * @param resource - resource pointer of the group resource
395 * @param actionsetName - Action Set name for removing the Action set
396 * @param callback - callback for POST operation.
398 * @return OCStackResult - return value of this API.
399 * It returns OC_STACK_OK if success.
401 * NOTE: OCStackResult is defined in ocstack.h.
403 OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource,
404 std::string actionsetName, PostCallback);
408 #endif /* __OC_THINGSMANAGER__*/