Add function to save a ACL into local SVR DB
[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 cloudConnectHandler Callback function that will get the result of the operation.
107          *
108          * @return Returns ::OC_STACK_OK if success
109          */
110         OCStackResult signOut(PostCallback cloudConnectHandler);
111
112         /**
113          * Function for refresh access token to account server
114          *
115          * @param userUuid Identifier of the user obtained by account registration.
116          * @param refreshToken Refresh token used for access token refresh.
117          * @param cloudConnectHandler Callback function that will get the result of the operation.
118          *
119          * @return Returns ::OC_STACK_OK if success
120          */
121         OCStackResult refreshAccessToken(const std::string& userUuid,
122                                          const std::string& refreshToken,
123                                          PostCallback cloudConnectHandler);
124
125         /**
126          * Function to get information of the user to account server
127          *
128          * @param userUuid Identifier of the user to get information.
129          * @param cloudConnectHandler Callback function that will get the result of the operation.
130          *
131          * @return Returns ::OC_STACK_OK if success
132          */
133         OCStackResult searchUser(const std::string& userUuid,
134                                  GetCallback cloudConnectHandler);
135
136         /**
137          * Overload
138          *
139          * @param queryParams Map which can have the query key and value for specific users.
140          *                    account server can response information of more than one user.
141          * @param cloudConnectHandler Callback function that will get the result of the operation.
142          *
143          * @return Returns ::OC_STACK_OK if success
144          */
145         OCStackResult searchUser(const QueryParamsMap& queryParams,
146                                  GetCallback cloudConnectHandler);
147
148         /**
149          * Function to delete the device registered on the account signed-in
150          *
151          * @param deviceId Device ID to delete.
152          * @param cloudConnectHandler Callback function that will get the result of the operation.
153          *
154          * @return Returns ::OC_STACK_OK if success
155          */
156         OCStackResult deleteDevice(const std::string& deviceId,
157                                    DeleteCallback cloudConnectHandler);
158
159         /**
160          * Function to create a group on account server
161          *
162          * @param groupType Group type that can be used for referencing default group ACL creation.
163          * @param cloudConnectHandler Callback function that will get the result of the operation.
164          *
165          * @return Returns ::OC_STACK_OK if success
166          */
167         OCStackResult createGroup(AclGroupType groupType,
168                                   PostCallback cloudConnectHandler);
169
170         /**
171          * Function to get a list of groups joined from account server
172          *
173          * @param cloudConnectHandler Callback function that will get the result of the operation.
174          *
175          * @return Returns ::OC_STACK_OK if success
176          */
177         OCStackResult getGroupList(GetCallback cloudConnectHandler);
178
179         /**
180          * Function to delete the group from account server
181          *
182          * @param groupId Group ID to delete.
183          * @param cloudConnectHandler Callback function that will get the result of the operation.
184          *
185          * @return Returns ::OC_STACK_OK if success
186          */
187         OCStackResult deleteGroup(const std::string& groupId,
188                                   DeleteCallback cloudConnectHandler);
189
190         /**
191          * Function to join the group on account server
192          *
193          * @param groupId Group ID to join
194          * @param cloudConnectHandler Callback function that will get the result of the operation.
195          *
196          * @return Returns ::OC_STACK_OK if success
197          */
198         OCStackResult joinGroup(const std::string& groupId,
199                                 PostCallback cloudConnectHandler);
200
201         /**
202          * Function to add devices to the group on account server
203          *
204          * @param groupId Group ID to add devices.
205          * @param deviceId List of devices to add.
206          * @param cloudConnectHandler Callback function that will get the result of the operation.
207          *
208          * @return Returns ::OC_STACK_OK if success
209          */
210         OCStackResult addDeviceToGroup(const std::string& groupId,
211                                        const std::vector<std::string>& deviceId,
212                                        PostCallback cloudConnectHandler);
213
214         /**
215          * Function to get information of the group from account server
216          *
217          * @param groupId Group ID to get information.
218          * @param cloudConnectHandler Callback function that will get the result of the operation.
219          *
220          * @return Returns ::OC_STACK_OK if success
221          */
222         OCStackResult getGroupInfo(const std::string& groupId,
223                                    GetCallback cloudConnectHandler);
224
225         /**
226          * Function to leave the group joined on account server
227          *
228          * @param groupId Group ID to leave.
229          * @param cloudConnectHandler Callback function that will get the result of the operation.
230          *
231          * @return Returns ::OC_STACK_OK if success
232          */
233         OCStackResult leaveGroup(const std::string& groupId,
234                                  DeleteCallback cloudConnectHandler);
235
236         /**
237          * Function to delete devices from the group on account server
238          *
239          * @param groupId Group ID to delete devices.
240          * @param deviceId List of devices to delete.
241          * @param cloudConnectHandler Callback function that will get the result of the operation.
242          *
243          * @return Returns ::OC_STACK_OK if success
244          */
245         OCStackResult deleteDeviceFromGroup(const std::string& groupId,
246                                             const std::vector<std::string>& deviceId,
247                                             DeleteCallback cloudConnectHandler);
248
249         /**
250          * Function to register observe to the group on account server
251          * User can receive a notify when the group get changed (eg. new user/device added)
252          *
253          * @param groupId Group ID to observe.
254          * @param cloudConnectHandler Callback function that will get the result of the operation.
255          *
256          * @return Returns ::OC_STACK_OK if success
257          */
258         OCStackResult observeGroup(const std::string& groupId,
259                                    ObserveCallback cloudConnectHandler);
260
261         /**
262          * Function to cancel observe to the group on account server
263          *
264          * @param groupId Group ID to observe.
265          *
266          * @return Returns ::OC_STACK_OK if success
267          */
268         OCStackResult cancelObserveGroup(const std::string& groupId);
269
270         /**
271          * Function to register observe to invitation resource on account server
272          * User can receive a invitation which is including group ID to join
273          * Once receive a invitation, user should call 'deleteInvitation' to delete a invitation
274          * on account server.
275          *
276          * @param cloudConnectHandler Callback function that will get the result of the operation.
277          *
278          * @return Returns ::OC_STACK_OK if success
279          */
280         OCStackResult observeInvitation(ObserveCallback cloudConnectHandler);
281
282         /**
283          * Function to cancel observe to invitation resource on account server
284          *
285          * @return Returns ::OC_STACK_OK if success
286          */
287         OCStackResult cancelObserveInvitation();
288
289         /**
290          * Function to send a invitation to invite a user into a group
291          *
292          * @param groupId Group ID for inviting.
293          * @param userUuid Identifier of the user to invite.
294          * @param cloudConnectHandler Callback function that will get the result of the operation.
295          *
296          * @return Returns ::OC_STACK_OK if success
297          */
298         OCStackResult sendInvitation(const std::string& groupId,
299                                      const std::string& userUuid,
300                                      PostCallback cloudConnectHandler);
301
302         /**
303          * Function to cancel a invitation on account server that user has sent
304          *
305          * @param groupId Group ID to cancel a invitation.
306          * @param userUuid Identifier of the user to cancel a invitation.
307          * @param cloudConnectHandler Callback function that will get the result of the operation.
308          *
309          * @return Returns ::OC_STACK_OK if success
310          */
311         OCStackResult cancelInvitation(const std::string& groupId,
312                                        const std::string& userUuid,
313                                        DeleteCallback cloudConnectHandler);
314
315         /**
316          * Function to delete a invitation on account server that user has received
317          *
318          * @param groupId Group ID to delete a invitation.
319          * @param cloudConnectHandler Callback function that will get the result of the operation.
320          *
321          * @return Returns ::OC_STACK_OK if success
322          */
323         OCStackResult deleteInvitation(const std::string& groupId,
324                                        DeleteCallback cloudConnectHandler);
325
326     private:
327         std::weak_ptr<IClientWrapper> m_clientWrapper;
328         std::string m_deviceID;
329         std::string m_host;
330         OCDoHandle m_invitationObserveHandle;
331         mutable std::map<std::string, OCDoHandle> m_groupObserveHandles;
332         OCConnectivityType m_connType;
333         QualityOfService m_defaultQos;
334
335     private:
336         OCAccountManager(std::weak_ptr<IClientWrapper> clientWrapper,
337                          const std::string& host,
338                          OCConnectivityType connectivityType);
339
340         OCStackResult signInOut(const std::string& userUuid,
341                                 const std::string& accessToken,
342                                 bool isSignIn,
343                                 PostCallback cloudConnectHandler);
344
345         OCStackResult searchUser(const std::string& userUuid,
346                                  const QueryParamsMap& queryParams,
347                                  GetCallback cloudConnectHandler);
348     };
349 } // namespace OC
350
351 #endif // OC_ACCOUNT_MANAGER_H_
352