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 classes and its members related to
28 #ifndef __OC_GROUPMANAGER__
29 #define __OC_GROUPMANAGER__
35 #include <ActionSet.h>
36 #include "OCPlatform.h"
43 typedef std::function< void(std::vector< std::shared_ptr< OCResource > >) > CandidateCallback;
44 typedef std::function< void(std::string, OCStackResult) > CollectionPresenceCallback;
46 typedef std::function< void(const HeaderOptions&, const OCRepresentation&, const int) > GetCallback;
47 typedef std::function< void(const HeaderOptions&, const OCRepresentation&, const int) > PostCallback;
48 typedef std::function< void(const HeaderOptions&, const OCRepresentation&, const int) > PutCallback;
51 * This APIs provide functions for application to find appropriate devices (i.e. things) in network,
52 * create a group of the devices, check a presence of member devices in the group, and actuate a
53 * group action in a more convenient way.
59 * Constructor for GroupManager. Constructs a new GroupManager
69 * API for candidate resources discovery.
70 * Callback only call when all resource types found.
72 * @param resourceTypes required resource types(called "candidate")
73 * @param callback callback with OCResource vector.
74 * @param waitsec time to wait to finish finding resources
76 * @return Returns ::OC_STACK_OK if success, some other value upon failure.
78 * @note OCStackResult is defined in ocstack.h.
80 OCStackResult findCandidateResources(std::vector< std::string > resourceTypes,
81 CandidateCallback callback, int waitsec = -1);
84 * API for Collection member's state subscribe.
86 * @note NOT IMPLEMENT YET
88 OCStackResult subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
89 CollectionPresenceCallback);
91 OCStackResult bindResourceToGroup(OCResourceHandle& childHandle,
92 std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
96 void onFoundResource(std::shared_ptr< OCResource > resource, int waitsec);
97 void findPreparedRequest(std::map< std::vector< std::string >, CandidateCallback > &request);
98 void lazyCallback(int second);
100 void onGetForPresence(const HeaderOptions& headerOptions, const OCRepresentation& rep,
101 const int eCode, CollectionPresenceCallback callback);
102 void checkCollectionRepresentation(const OCRepresentation& rep,
103 CollectionPresenceCallback callback);
104 void collectionPresenceHandler(OCStackResult result, const unsigned int nonce,
105 const std::string& hostAddress, std::string host, std::string uri);
108 * API for Collection(Group) action.
113 * API for extracting an action set string from the ActionSet class instance
115 * @param newActionSet pointer of ActionSet class instance
117 * @return std::string return value of this API.
118 * It returns an action set String.
120 std::string getStringFromActionSet(const ActionSet *newActionSet);
123 * API for extracting ActionSet class instance from an action set string.
125 * @param desc description of an action set string
127 * @return ActionSet* return value of this API.
128 * It returns pointer of ActionSet.
130 ActionSet* getActionSetfromString(std::string desc);
133 * API for adding an action set.
134 * Callback is called when the response of PUT operation arrives.
136 * @param resource resource pointer of the group resource
137 * @param newActionSet pointer of ActionSet class instance
138 * @param cb callback for PUT operation.
140 * @return Returns ::OC_STACK_OK if success, some other value upon failure.
142 * @note OCStackResult is defined in ocstack.h.
144 OCStackResult addActionSet(std::shared_ptr< OCResource > resource,
145 const ActionSet* newActionSet, PutCallback cb);
148 * API for executing an existing action set.
149 * Callback is called when the response of POST operation arrives.
151 * @param resource resource pointer of the group resource
152 * @param actionsetName the action set name for executing the action set
153 * @param cb callback for POST operation.
155 * @return Returns ::OC_STACK_OK if success, some other value upon failure.
156 * @note OCStackResult is defined in ocstack.h.
158 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
159 std::string actionsetName, PostCallback cb);
162 * API for executing an existing action set.
163 * Callback is called when the response of POST operation arrives.
165 * @param resource resource pointer of the group resource
166 * @param actionsetName the action set name for executing the action set
167 * @param delay waiting time for until the action set run.
168 * @param cb callback for POST operation.
170 * @return Returns ::OC_STACK_OK if success, some other value upon failure.
171 * @note OCStackResult is defined in ocstack.h.
173 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
174 std::string actionsetName, long int delay, PostCallback cb);
177 * API for canceling an existing action set.
178 * Callback is called when the response of POST operation arrives.
180 * @param resource resource pointer of the group resource
181 * @param actionsetName the action set name for executing the action set
182 * @param cb callback for POST operation.
184 * @return Returns ::OC_STACK_OK if success, some other value upon failure.
185 * @note OCStackResult is defined in ocstack.h.
187 OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
188 std::string actionsetName, PostCallback cb);
191 * API for reading an existing action set.
192 * Callback is called when the response of GET operation arrives.
194 * @param resource resource pointer of the group resource
195 * @param actionsetName the action set name for reading the action set
196 * @param cb callback for GET operation.
198 * @return Returns ::OC_STACK_OK if success, some other value upon failure.
199 * @note OCStackResult is defined in ocstack.h.
201 OCStackResult getActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
205 * API for removing an existing action set.
206 * Callback is called when the response of POST operation arrives.
208 * @param resource resource pointer of the group resource
209 * @param actionsetName the action set name for removing the action set
210 * @param cb callback for POST operation.
212 * @return Returns ::OC_STACK_OK if success, some other value upon failure.
213 * @note OCStackResult is defined in ocstack.h.
215 OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
219 #endif /* __OC_GROUPMANAGER__*/