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 candidateCallback - callback. OCResource vector.
77 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
79 * NOTE: OCStackResult is defined in ocstack.h.
81 OCStackResult findCandidateResources(std::vector< std::string > resourceTypes,
82 CandidateCallback callback, int waitsec = -1);
85 * API for Collection member's state subscribe.
87 * NOTE: NOT IMPLEMENT YET
89 OCStackResult subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
90 CollectionPresenceCallback);
92 OCStackResult bindResourceToGroup(OCResourceHandle& childHandle,
93 std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
97 void onFoundResource(std::shared_ptr< OCResource > resource, int waitsec);
98 void findPreparedRequest(std::map< std::vector< std::string >, CandidateCallback > &request);
99 void lazyCallback(int second);
101 void onGetForPresence(const HeaderOptions& headerOptions, const OCRepresentation& rep,
102 const int eCode, CollectionPresenceCallback callback);
103 void checkCollectionRepresentation(const OCRepresentation& rep,
104 CollectionPresenceCallback callback);
105 void collectionPresenceHandler(OCStackResult result, const unsigned int nonce,
106 const std::string& hostAddress, std::string host, std::string uri);
109 * API for Collection(Group) action.
114 * API for extracting an action set string from the ActionSet class instance
116 * @param newActionSet pointer of ActionSet class instance
118 * @return std::string return value of this API.
119 * It returns an action set String.
120 * @note OCStackResult is defined in ocstack.h.
122 std::string getStringFromActionSet(const ActionSet *newActionSet);
125 * API for extrracting ActionSet class instance from an action set string.
127 * @param desc description of an action set string
129 * @return ActionSet* return value of this API.
130 * It returns pointer of ActionSet.
132 ActionSet* getActionSetfromString(std::string desc);
135 * API for adding an action set.
136 * Callback is called when the response of PUT operation arrives.
138 * @param resource resource pointer of the group resource
139 * @param newActionSet pointer of ActionSet class instance
140 * @param callback callback for PUT operation.
142 * @return Returns ::OC_STACK_OK if success.
144 * @note OCStackResult is defined in ocstack.h.
146 OCStackResult addActionSet(std::shared_ptr< OCResource > resource,
147 const ActionSet* newActionSet, PutCallback cb);
150 * API for executing an existing action set.
151 * Callback is called when the response of POST operation arrives.
153 * @param resource resource pointer of the group resource
154 * @param actionsetName the action set name for executing the action set
155 * @param callback callback for POST operation.
157 * @return Returns ::OC_STACK_OK if success.
158 * @note OCStackResult is defined in ocstack.h.
160 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
161 std::string actionsetName, PostCallback cb);
164 * API for executing an existing action set.
165 * Callback is called when the response of POST operation arrives.
167 * @param resource resource pointer of the group resource
168 * @param actionsetName the action set name for executing the action set
169 * @param delay waiting time for until the action set run.
170 * @param callback callback for POST operation.
172 * @return Returns ::OC_STACK_OK if success.
173 * @note OCStackResult is defined in ocstack.h.
175 OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
176 std::string actionsetName, long int delay, PostCallback cb);
179 * API for canceling an existing action set.
180 * Callback is called when the response of POST operation arrives.
182 * @param resource resource pointer of the group resource
183 * @param actionsetName the action set name for executing the action set
184 * @param callback callback for POST operation.
186 * @return Returns ::OC_STACK_OK if success.
187 * @note OCStackResult is defined in ocstack.h.
189 OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
190 std::string actionsetName, PostCallback cb);
193 * API for reading an existing action set.
194 * Callback is called when the response of GET operation arrives.
196 * @param resource resource pointer of the group resource
197 * @param actionsetName the action set name for reading the action set
198 * @param callback callback for GET operation.
200 * @return Returns ::OC_STACK_OK if success.
201 * @note OCStackResult is defined in ocstack.h.
203 OCStackResult getActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
207 * API for removing an existing action set.
208 * Callback is called when the response of POST operation arrives.
210 * @param resource resource pointer of the group resource
211 * @param actionsetName the action set name for removing the action set
212 * @param callback callback for POST operation.
214 * @return Returns ::OC_STACK_OK if success.
215 * @note OCStackResult is defined in ocstack.h.
217 OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
221 #endif /* __OC_GROUPMANAGER__*/