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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the declaration of ThingsManager class and its
25 * members related to ThingsManager.
28 #ifndef __OC_THINGSMANAGER__
29 #define __OC_THINGSMANAGER__
35 #include <ActionSet.h>
36 #include "OCPlatform.h"
38 #include "GroupManager.h"
45 * @class ThingsManager
46 * @brief This class provides a set of functions regarding group management,
47 * synchronization of group, configuration of things, and diagnostics about things.
54 * Constructor for ThingsManager
59 * Virtual destructor for ThingsManager
64 * API for discoverying candidate resources.
65 * Callback is called when all resource types are found.
67 * @param resourceTypes - required resource types(called "candidate")
68 * @param candidateCallback - callback. Returns OCResource vector.
70 * @return OCStackResult - return value of this API.
71 * It returns OC_STACK_OK if success.
73 * NOTE: OCStackResult is defined in ocstack.h.
75 OCStackResult findCandidateResources(std::vector< std::string > resourceTypes,
76 std::function< void(std::vector< std::shared_ptr< OCResource > >) > callback,
80 * API for subscribing child's state.
82 * @param resource - collection resource for subscribing presence of all child resources.
83 * @param callback - callback funcion for result of child's presence.
85 * @return OCStackResult - return value of this API.
86 * It returns OC_STACK_OK if success.
88 * NOTE: OCStackResult is defined in ocstack.h.
90 OCStackResult subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
91 std::function< void(std::string, OCStackResult) > callback);
94 * API for registering and binding resource to group.
96 * @param childHandle - child resource handle. It will be filled from resource param.
97 * @param resource - resource for registering and binding to group. It has all data.
98 * @param collectionHandle - collection resource handle. It will be added child resource.
100 * @return OCStackResult - return value of this API.
101 * It returns OC_STACK_OK if success.
103 * NOTE: OCStackResult is defined in ocstack.h.
105 OCStackResult bindResourceToGroup(OCResourceHandle& childHandle,
106 std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
108 // Group Synchronization
111 * API for finding a specific remote group when a resource tries to join a group.
112 * Callback is called when a group is found or not.
114 * @param collectionResourceTypes - resource types of a group to find and join
115 * @param callback - callback. It has OCResource param.
116 * If a group is found, OCResource has the group resource.
117 * Otherwise, OCResource is NULL.
119 * @return OCStackResult - return value of this API.
120 * It returns OC_STACK_OK if success.
122 * NOTE: It return OC_STACK ERROR when it is already finding a group.
123 * You should call this api after the group finding process has stopped.
124 * OCStackResult is defined in ocstack.h.
126 OCStackResult findGroup(std::vector< std::string > collectionResourceTypes,
127 FindCallback callback);
130 * API for creating a new group.
132 * @param collectionResourceType - resource type of a group to create
134 * @return OCStackResult - return value of this API.
135 * It returns OC_STACK_OK if success.
137 * NOTE: OCStackResult is defined in ocstack.h.
139 OCStackResult createGroup(std::string collectionResourceType);
142 * API for joining a group. This API is used when a resource that has a group tries
143 * to find a specific remote resource and makes it join a group
145 * @param collectionResourceType - resource type of a group to join.
146 * @param resourceHandle - resource handle to join a group.
148 * @return OCStackResult - return value of this API.
149 * It returns OC_STACK_OK if success.
151 * NOTE: If you want to join the resource in the remote(other) process,
152 * use joinGroup(const std::shared_ptr< OCResource >, OCResourceHandle)
154 * OCStackResult is defined in ocstack.h.
156 OCStackResult joinGroup(std::string collectionResourceType,
157 OCResourceHandle resourceHandle);
160 * API for joining a group. This API is used when a resource that
161 * doesn't have a group tries to find and join a specific remote group.
163 * @param resource - group resource pointer to join.
164 * It can be the callback result of findGroup().
165 * @param resourceHandle - resource handle to join a group.
167 * @return OCStackResult - return value of this API.
168 * It returns OC_STACK_OK if success.
170 * NOTE: NOTE: If you want to join the resource in the same process,
171 * use joinGroup(std::string, OCResourceHandle)
173 * OCStackResult is defined in ocstack.h.
175 OCStackResult joinGroup(const std::shared_ptr< OCResource > resource,
176 OCResourceHandle resourceHandle);
179 * API for leaving a joined group.
181 * @param collectionResourceType - resource type of a group to leave.
182 * @param resourceHandle - resource handle to leave a group.
184 * @return OCStackResult - return value of this API.
185 * It returns OC_STACK_OK if success.
187 * NOTE: OCStackResult is defined in ocstack.h.
189 OCStackResult leaveGroup(std::string collectionResourceType,
190 OCResourceHandle resourceHandle);
193 * API for leaving a joined group.
195 * @param resource - group resource pointer to join.
196 * It can be the callback result of findGroup().
198 * @param collectionResourceType - resource type of a group to leave.
199 * @param resourceHandle - resource handle to leave a group.
201 * @return OCStackResult - return value of this API.
202 * It returns OC_STACK_OK if success.
204 * NOTE: OCStackResult is defined in ocstack.h.
206 OCStackResult leaveGroup(const std::shared_ptr< OCResource > resource,
207 std::string collectionResourceType,
208 OCResourceHandle resourceHandle);
211 * API for deleting a group.
213 * @param collectionResourceType - resource type of a group to delete.
217 void deleteGroup(std::string collectionResourceType);
220 * API for getting a list of joined groups.
222 * @return std::map - return value of this API.
223 * It returns group resource type and group resource handle as a map type.
225 std::map< std::string, OCResourceHandle > getGroupList();
227 // Things Configuration
230 * API for updating configuration value of multiple things of a target group
232 * Callback is called when a response arrives.
233 * Before using the below function, a developer should acquire a resource pointer of
234 * (collection) resource that he wants to send a request by calling findResource() function
235 * provided in OCPlatform. And he should also notice a "Configuration Name" term which
236 * represents a nickname of a target attribute of a resource that he wants to update.
237 * The base motivation to introduce the term is to avoid a usage of URI to access a resource
238 * from a developer. Thus, a developer should know which configuration names are supported
239 * by Things Configuration class and what the configuration name means.
240 * To get a list of supported configuration names,
241 * use getListOfSupportedConfigurationUnits()
242 * function, which provides the list in JSON format.
244 * @param resource - resource pointer representing the target group or the single thing.
245 * @param configurations - ConfigurationUnit: an attribute key of target resource.
246 * (e.g., loc, st, c, r)
247 * Value : a value to be updated
248 * @param callback - callback for updateConfigurations.
250 * @return OCStackResult - return value of this API.
251 * It returns OC_STACK_OK if success.
253 * NOTE: OCStackResult is defined in ocstack.h.
255 OCStackResult updateConfigurations(std::shared_ptr< OCResource > resource,
256 std::map< std::string, std::string > configurations,
258 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
259 const int eCode) > callback);
262 * API for getting configuration value of multiple things of a target group
264 * Callback is called when a response arrives.
266 * @param resource - resource pointer representing the target group or the single thing.
267 * @param configurations - ConfigurationUnit: an attribute key of target resource.
268 * @param callback - callback for getConfigurations.
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 getConfigurations(std::shared_ptr< OCResource > resource,
276 std::vector< std::string > configurations,
278 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
279 const int eCode) > callback);
282 * API for showing the list of supported configuration units (attribute keys)
283 * Callback is called when a response arrives.
286 * @return std::string - return value of this API.
287 * It returns the list in JSON format
289 std::string getListOfSupportedConfigurationUnits();
292 * API for boostrapping system configuration parameters from a bootstrap server.
293 * Callback is called when a response from the bootstrap server arrives.
295 * @param callback - callback for doBootstrap.
297 * @return OCStackResult - return value of this API.
298 * It returns OC_STACK_OK if success.
300 * NOTE: OCStackResult is defined in ocstack.h.
302 OCStackResult doBootstrap(
304 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
305 const int eCode) > callback);
307 // Things Diagnostics
310 * API to let thing(device) reboot.
311 * The target thing could be a group of multiple things or a single thing.
312 * Callback is called when a response arrives.
314 * @param resource - resource pointer representing the target group
315 * @param callback - callback for reboot.
317 * @return OCStackResult - return value of this API.
318 * It returns OC_STACK_OK if success.
320 * NOTE: OCStackResult is defined in ocstack.h.
322 OCStackResult reboot(std::shared_ptr< OCResource > resource,
324 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
325 const int eCode) > callback);
328 * API for factory reset on thing(device).
329 * The target thing could be a group of multiple things or a single thing.
330 * Callback is called when a response arrives.
332 * @param resource - resource pointer representing the target group
333 * @param callback - callback for factoryReset.
335 * @return OCStackResult - return value of this API.
336 * It returns OC_STACK_OK if success.
338 * NOTE: OCStackResult is defined in ocstack.h.
340 OCStackResult factoryReset(std::shared_ptr< OCResource > resource,
342 void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
343 const int eCode) > callback);
348 * API for extracting an action set string from the ActionSet class instance
350 * @param newActionSet - pointer of ActionSet class instance
352 * @return std::string - return value of this API.
353 * It returns an action set String.
355 * NOTE: OCStackResult is defined in ocstack.h.
357 std::string getStringFromActionSet(const ActionSet *newActionSet);
360 * API for extrracting ActionSet class instance from an action set string.
362 * @param desc - description of an action set string
364 * @return ActionSet* - return value of this API.
365 * It returns pointer of ActionSet.
367 ActionSet* getActionSetfromString(std::string desc);
370 * API for adding an action set.
371 * Callback is called when the response of PUT operation arrives.
373 * @param resource - resource pointer of the group resource
374 * @param newActionSet - pointer of ActionSet class instance
375 * @param callback - callback for PUT operation.
377 * @return OCStackResult - return value of this API.
378 * It returns OC_STACK_OK if success.
380 * NOTE: OCStackResult is defined in ocstack.h.
382 OCStackResult addActionSet(std::shared_ptr< OCResource > resource,
383 const ActionSet* newActionSet, PutCallback cb);
386 * API for executing an existing action set.
387 * Callback is called when the response of POST operation arrives.
389 * @param resource - resource pointer of the group resource
390 * @param actionsetName - the action set name for executing the action set
391 * @param callback - callback for POST operation.
393 * @return OCStackResult - return value of this API.
394 * It returns OC_STACK_OK if success.
396 * NOTE: OCStackResult is defined in ocstack.h.
398 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
399 std::string actionsetName, PostCallback cb);
402 * API for executing an existing action set.
403 * Callback is called when the response of POST operation arrives.
405 * @param resource - resource pointer of the group resource
406 * @param actionsetName - the action set name for executing the action set
407 * @param delay - waiting time for until the action set run.
408 * @param callback - callback for POST operation.
410 * @return OCStackResult - return value of this API.
411 * It returns OC_STACK_OK if success.
413 * NOTE: OCStackResult is defined in ocstack.h.
415 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
416 std::string actionsetName, long int delay, PostCallback cb);
419 * API for canceling an existing action set.
420 * Callback is called when the response of POST operation arrives.
422 * @param resource - resource pointer of the group resource
423 * @param actionsetName - the action set name for executing the action set
424 * @param callback - callback for POST operation.
426 * @return OCStackResult - return value of this API.
427 * It returns OC_STACK_OK if success.
429 * NOTE: OCStackResult is defined in ocstack.h.
431 OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
432 std::string actionsetName, PostCallback cb);
434 * API for reading an existing action set.
435 * Callback is called when the response of GET operation arrives.
437 * @param resource - resource pointer of the group resource
438 * @param actionsetName - the action set name for reading the action set
439 * @param callback - callback for GET operation.
441 * @return OCStackResult - return value of this API.
442 * It returns OC_STACK_OK if success.
444 * NOTE: OCStackResult is defined in ocstack.h.
446 OCStackResult getActionSet(std::shared_ptr< OCResource > resource,
447 std::string actionsetName, GetCallback cb);
450 * API for removing an existing action set.
451 * Callback is called when the response of POST operation arrives.
453 * @param resource - resource pointer of the group resource
454 * @param actionsetName - the action set name for removing the action set
455 * @param callback - callback for POST operation.
457 * @return OCStackResult - return value of this API.
458 * It returns OC_STACK_OK if success.
460 * NOTE: OCStackResult is defined in ocstack.h.
462 OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource,
463 std::string actionsetName, PostCallback);
467 #endif /* __OC_THINGSMANAGER__*/