modified OCAccountManager APIs
[platform/upstream/iotivity.git] / resource / include / OCAccountManager.h
1 /* ****************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 #ifndef OC_ACCOUNT_MANAGER_H_
22 #define OC_ACCOUNT_MANAGER_H_
23
24 #include <map>
25
26 #include <OCApi.h>
27 #include <IClientWrapper.h>
28 #include <InProcClientWrapper.h>
29
30 namespace OC
31 {
32     class OCAccountManager
33     {
34         friend class OCPlatform_impl;
35
36     public:
37         typedef std::shared_ptr<OCAccountManager> Ptr;
38
39         OCAccountManager(OCAccountManager&&) = default;
40         OCAccountManager(const OCAccountManager&) = delete;
41         OCAccountManager& operator=(OCAccountManager&&) = delete;
42         OCAccountManager& operator=(const OCAccountManager&) = delete;
43
44         virtual ~OCAccountManager(void);
45
46         /**
47         * Function to get the host address of account server.
48         *
49         * @return std::string host address
50         */
51         std::string host() const;
52
53         /**
54         * Function to get the connectivity type for account server.
55         *
56         * @return enum connectivity type (flags and adapter)
57         */
58         OCConnectivityType connectivityType() const;
59
60         /**
61          * Function for account registration to account server.
62          *
63          * @param authProvider Provider name used for authentication.
64          * @param authCode The authorization code obtained by using an authorization server
65          *                 as an intermediary between the client and resource owner.
66          * @param cloudConnectHandler Callback function that will get the result of the operation.
67          *
68          * @return Returns ::OC_STACK_OK if success
69          */
70         OCStackResult signUp(const std::string& authProvider,
71                              const std::string& authCode,
72                              PostCallback cloudConnectHandler);
73
74         /**
75          * Overload
76          *
77          * @param authProvider Provider name used for authentication.
78          * @param authCode The authorization code obtained by using an authorization server
79          *                 as an intermediary between the client and resource owner.
80          * @param options The option values depends on auth provider.
81          * @param cloudConnectHandler Callback function that will get the result of the operation.
82          *
83          * @return Returns ::OC_STACK_OK if success
84          */
85         OCStackResult signUp(const std::string& authProvider,
86                              const std::string& authCode,
87                              const QueryParamsMap& options,
88                              PostCallback cloudConnectHandler);
89
90         /**
91          * Function for sign-in to account server.
92          *
93          * @param userUuid Identifier of the user obtained by account registration.
94          * @param accessToken Identifier of the resource obtained by account registration.
95          * @param cloudConnectHandler Callback function that will get the result of the operation.
96          *
97          * @return Returns ::OC_STACK_OK if success
98          */
99         OCStackResult signIn(const std::string& userUuid,
100                              const std::string& accessToken,
101                              PostCallback cloudConnectHandler);
102
103         /**
104          * Function for sign-out to account server.
105          *
106          * @param accessToken Identifier of the resource obtained by account registration.
107          * @param cloudConnectHandler Callback function that will get the result of the operation.
108          *
109          * @return Returns ::OC_STACK_OK if success
110          */
111         OCStackResult signOut(const std::string& accessToken,
112                               PostCallback cloudConnectHandler);
113
114         /**
115          * Function for refresh access token to account server.
116          *
117          * @param userUuid Identifier of the user obtained by account registration.
118          * @param refreshToken Refresh token used for access token refresh.
119          * @param cloudConnectHandler Callback function that will get the result of the operation.
120          *
121          * @return Returns ::OC_STACK_OK if success
122          */
123         OCStackResult refreshAccessToken(const std::string& userUuid,
124                                          const std::string& refreshToken,
125                                          PostCallback cloudConnectHandler);
126
127         /**
128          * Function to get information of the user to account server.
129          *
130          * @param userUuid Identifier of the user to get information.
131          * @param cloudConnectHandler Callback function that will get the result of the operation.
132          *
133          * @return Returns ::OC_STACK_OK if success
134          */
135         OCStackResult searchUser(const std::string& userUuid,
136                                  GetCallback cloudConnectHandler);
137
138         /**
139          * Overload
140          *
141          * @param queryParams Map that has a query key and value for specific users.
142          *                    Account server can response information of more than one user.
143          * @param cloudConnectHandler Callback function that will get the result of the operation.
144          *
145          * @return Returns ::OC_STACK_OK if success
146          */
147         OCStackResult searchUser(const QueryParamsMap& queryParams,
148                                  GetCallback cloudConnectHandler);
149
150         /**
151          * Function to delete the device registered on the account signed-in.
152          *
153          * @param accessToken Identifier of the resource obtained by account registration.
154          * @param deviceId Device ID to delete.
155          * @param cloudConnectHandler Callback function that will get the result of the operation.
156          *
157          * @return Returns ::OC_STACK_OK if success
158          */
159         OCStackResult deleteDevice(const std::string& accessToken,
160                                    const std::string& deviceId,
161                                    DeleteCallback cloudConnectHandler);
162
163         /**
164          * Function to create a group on account server.
165          *
166          * @param cloudConnectHandler Callback function that will get the result of the operation.
167          *
168          * @return Returns ::OC_STACK_OK if success
169          */
170         OCStackResult createGroup(PostCallback cloudConnectHandler);
171
172         /**
173          * Overload
174          *
175          * @param queryParams Map that has optional properties and values to create a group.
176          *                    Defined properties on the OCF spec are [gname, parent] so far.
177          *                    (2016/10/19)
178          * @param cloudConnectHandler Callback function that will get the result of the operation.
179          *
180          * @return Returns ::OC_STACK_OK if success
181          */
182         OCStackResult createGroup(const QueryParamsMap& queryParams,
183                                   PostCallback cloudConnectHandler);
184
185         /**
186          * Function to delete the group from account server.
187          *
188          * @param groupId Group ID to delete.
189          * @param cloudConnectHandler Callback function that will get the result of the operation.
190          *
191          * @return Returns ::OC_STACK_OK if success
192          */
193         OCStackResult deleteGroup(const std::string& groupId,
194                                   DeleteCallback cloudConnectHandler);
195
196         /**
197          * Function to get infomation of all your group from account server.
198          *
199          * @param cloudConnectHandler Callback function that will get the result of the operation.
200          *
201          * @return Returns ::OC_STACK_OK if success
202          */
203
204         OCStackResult getGroupInfoAll(GetCallback cloudConnectHandler);
205
206         /**
207          * Function to get information of the specific group from account server.
208          *
209          * @param groupId Group ID to get information.
210          * @param cloudConnectHandler Callback function that will get the result of the operation.
211          *
212          * @return Returns ::OC_STACK_OK if success
213          */
214         OCStackResult getGroupInfo(const std::string& groupId,
215                                    GetCallback cloudConnectHandler);
216
217         /**
218          * Function to add values for properties to the group on account server.
219          *
220          * @param groupId Group ID to add property values.
221          * @param propertyValue OCRepresentation info that has pairs of property and value.
222          *                      Defined properties on the OCF spec are [members, masters, devices,
223          *                      resources, links] so far. (2016/10/19)
224          * @param cloudConnectHandler Callback function that will get the result of the operation.
225          *
226          * @return Returns ::OC_STACK_OK if success
227          */
228         OCStackResult addPropertyValueToGroup(const std::string& groupId,
229                                               const OCRepresentation propertyValue,
230                                               PostCallback cloudConnectHandler);
231
232         /**
233          * Function to delete values for properties from the group on account server.
234          *
235          * @param groupId Group ID to delete information.
236          * @param propertyValue OCRepresentation info that has pairs of property and value.
237          *                      Defined properties on the OCF spec are [members, masters, devices,
238          *                      resources, links] so far. (2016/10/19)
239          * @param cloudConnectHandler Callback function that will get the result of the operation.
240          *
241          * @return Returns ::OC_STACK_OK if success
242          */
243         OCStackResult deletePropertyValueFromGroup(const std::string& groupId,
244                                                    const OCRepresentation propertyValue,
245                                                    PostCallback cloudConnectHandler);
246
247         /**
248          * Function to update values for properties on the group on account server.
249          * It completely replaces existing values for specific properties.
250          *
251          * @param groupId Group ID to add devices.
252          * @param propertyValue OCRepresentation info that has pairs of property and value.
253          *                      Defined properties on the OCF spec are [members, gname, owner,
254          *                      masters, devices, resources, latitude, longitude, radius,
255          *                      backgroundImage] so far. (2016/10/19)
256          * @param cloudConnectHandler Callback function that will get the result of the operation.
257          *
258          * @return Returns ::OC_STACK_OK if success
259          */
260         OCStackResult updatePropertyValueOnGroup(const std::string& groupId,
261                                                  const OCRepresentation propertyValue,
262                                                  PostCallback cloudConnectHandler);
263
264         /**
265          * Function to register observe to group resource on account server.
266          * You can receive a notify when any value of property get changed in the group you joined.
267          *
268          * @param cloudConnectHandler Callback function that will get the result of the operation.
269          *
270          * @return Returns ::OC_STACK_OK if success
271          */
272         OCStackResult observeGroup(ObserveCallback cloudConnectHandler);
273
274         /**
275          * Function to cancel observe to group resource on account server.
276          *
277          * @return Returns ::OC_STACK_OK if success
278          */
279         OCStackResult cancelObserveGroup();
280
281         /**
282          * Function to register observe to invitation resource on account server.
283          * You can receive a notify when you send or receive a invitation.
284          * Sending a invitation will be notified as 'invite' and Receiving will be as 'invited'.
285          * If you receive a invitation from other user, you should call 'replyToInvitation' to
286          * delete the invitation on account server, otherwise it will remain on the server.
287          *
288          * @param cloudConnectHandler Callback function that will get the result of the operation.
289          *
290          * @return Returns ::OC_STACK_OK if success
291          */
292         OCStackResult observeInvitation(ObserveCallback cloudConnectHandler);
293
294         /**
295          * Function to cancel observe to invitation resource on account server.
296          *
297          * @return Returns ::OC_STACK_OK if success
298          */
299         OCStackResult cancelObserveInvitation();
300
301         /**
302          * Function to send a invitation to invite a user into a group.
303          *
304          * @param groupId Group ID for inviting.
305          * @param userUuid Identifier of the user to invite.
306          * @param cloudConnectHandler Callback function that will get the result of the operation.
307          *
308          * @return Returns ::OC_STACK_OK if success
309          */
310         OCStackResult sendInvitation(const std::string& groupId,
311                                      const std::string& userUuid,
312                                      PostCallback cloudConnectHandler);
313
314         /**
315          * Function to cancel a invitation you has sent on account server before the invited user
316          * replies.
317          *
318          * @param groupId Group ID to cancel a invitation.
319          * @param userUuid Identifier of the user to cancel a invitation.
320          * @param cloudConnectHandler Callback function that will get the result of the operation.
321          *
322          * @return Returns ::OC_STACK_OK if success
323          */
324         OCStackResult cancelInvitation(const std::string& groupId,
325                                        const std::string& userUuid,
326                                        DeleteCallback cloudConnectHandler);
327
328         /**
329          * Function to reply to the invitation that you has received.
330          * If you set accept as true, you will join the group as a member and the invitation
331          * will be deleted on account server.
332          * If false, only the invitation will be deleted.
333          *
334          * @param groupId Group ID to delete a invitation.
335          * @param accept boolean whether to join the group or not.
336          * @param cloudConnectHandler Callback function that will get the result of the operation.
337          *
338          * @return Returns ::OC_STACK_OK if success
339          */
340         OCStackResult replyToInvitation(const std::string& groupId,
341                                         const bool accept,
342                                         DeleteCallback cloudConnectHandler);
343
344     private:
345         std::weak_ptr<IClientWrapper> m_clientWrapper;
346         std::string m_deviceID;
347         std::string m_host;
348         std::string m_userUuid;
349         OCDoHandle m_invitationObserveHandle;
350         OCDoHandle m_groupObserveHandle;
351         OCConnectivityType m_connType;
352         QualityOfService m_defaultQos;
353
354     private:
355         OCAccountManager(std::weak_ptr<IClientWrapper> clientWrapper,
356                          const std::string& host,
357                          OCConnectivityType connectivityType);
358
359         OCStackResult signInOut(const std::string& userUuid,
360                                 const std::string& accessToken,
361                                 bool isSignIn,
362                                 PostCallback cloudConnectHandler);
363
364         OCStackResult searchUser(const std::string& userUuid,
365                                  const QueryParamsMap& queryParams,
366                                  GetCallback cloudConnectHandler);
367     };
368 } // namespace OC
369
370 #endif // OC_ACCOUNT_MANAGER_H_
371