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;
53 * This APIs provide functions for application to find appropriate devices (i.e. things) in network,
54 * create a group of the devices, check a presence of member devices in the group, and actuate a
55 * group action in a more convenient way.
61 * Constructor for GroupManager. Constructs a new GroupManager
71 * API for candidate resources discovery.
72 * Callback only call when all resource types found.
74 * @param resourceTypes required resource types(called "candidate")
75 * @param callback callback with OCResource vector.
76 * @param waitsec time to wait to finish finding resources
78 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
80 * NOTE: OCStackResult is defined in ocstack.h.
82 OCStackResult findCandidateResources(std::vector< std::string > resourceTypes,
83 CandidateCallback callback, int waitsec = -1);
86 * API for Collection member's state subscribe.
88 * NOTE: NOT IMPLEMENT YET
90 OCStackResult subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
91 CollectionPresenceCallback);
93 OCStackResult bindResourceToGroup(OCResourceHandle& childHandle,
94 std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
98 void onFoundResource(std::shared_ptr< OCResource > resource, int waitsec);
99 void findPreparedRequest(std::map< std::vector< std::string >, CandidateCallback > &request);
100 void lazyCallback(int second);
102 void onGetForPresence(const HeaderOptions& headerOptions, const OCRepresentation& rep,
103 const int eCode, CollectionPresenceCallback callback);
104 void checkCollectionRepresentation(const OCRepresentation& rep,
105 CollectionPresenceCallback callback);
106 void collectionPresenceHandler(OCStackResult result, const unsigned int nonce,
107 const std::string& hostAddress, std::string host, std::string uri);
110 * API for Collection(Group) action.
115 * API for extracting an action set string from the ActionSet class instance
117 * @param newActionSet pointer of ActionSet class instance
119 * @return std::string return value of this API.
120 * It returns an action set String.
121 * @note OCStackResult is defined in ocstack.h.
123 std::string getStringFromActionSet(const ActionSet *newActionSet);
126 * API for extracting ActionSet class instance from an action set string.
128 * @param desc description of an action set string
130 * @return ActionSet* return value of this API.
131 * It returns pointer of ActionSet.
133 ActionSet* getActionSetfromString(std::string desc);
136 * API for adding an action set.
137 * Callback is called when the response of PUT operation arrives.
139 * @param resource resource pointer of the group resource
140 * @param newActionSet pointer of ActionSet class instance
141 * @param cb callback for PUT operation.
143 * @return Returns ::OC_STACK_OK if success.
145 * @note OCStackResult is defined in ocstack.h.
147 OCStackResult addActionSet(std::shared_ptr< OCResource > resource,
148 const ActionSet* newActionSet, PutCallback cb);
151 * API for executing an existing action set.
152 * Callback is called when the response of POST operation arrives.
154 * @param resource resource pointer of the group resource
155 * @param actionsetName the action set name for executing the action set
156 * @param cb callback for POST operation.
158 * @return Returns ::OC_STACK_OK if success.
159 * @note OCStackResult is defined in ocstack.h.
161 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
162 std::string actionsetName, PostCallback cb);
165 * API for executing an existing action set.
166 * Callback is called when the response of POST operation arrives.
168 * @param resource resource pointer of the group resource
169 * @param actionsetName the action set name for executing the action set
170 * @param delay waiting time for until the action set run.
171 * @param cb callback for POST operation.
173 * @return Returns ::OC_STACK_OK if success.
174 * @note OCStackResult is defined in ocstack.h.
176 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
177 std::string actionsetName, long int delay, PostCallback cb);
180 * API for canceling an existing action set.
181 * Callback is called when the response of POST operation arrives.
183 * @param resource resource pointer of the group resource
184 * @param actionsetName the action set name for executing the action set
185 * @param cb callback for POST operation.
187 * @return Returns ::OC_STACK_OK if success.
188 * @note OCStackResult is defined in ocstack.h.
190 OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
191 std::string actionsetName, PostCallback cb);
194 * API for reading an existing action set.
195 * Callback is called when the response of GET operation arrives.
197 * @param resource resource pointer of the group resource
198 * @param actionsetName the action set name for reading the action set
199 * @param cb callback for GET operation.
201 * @return Returns ::OC_STACK_OK if success.
202 * @note OCStackResult is defined in ocstack.h.
204 OCStackResult getActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
208 * API for removing an existing action set.
209 * Callback is called when the response of POST operation arrives.
211 * @param resource resource pointer of the group resource
212 * @param actionsetName the action set name for removing the action set
213 * @param cb callback for POST operation.
215 * @return Returns ::OC_STACK_OK if success.
216 * @note OCStackResult is defined in ocstack.h.
218 OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
222 #endif /* __OC_GROUPMANAGER__*/