[CONPRO-1295] Fix build error dlog string
[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 queryParams Map that has a query key and value for specific users.
131          *                    Account server can response information of more than one user.
132          * @param cloudConnectHandler Callback function that will get the result of the operation.
133          *
134          * @return Returns ::OC_STACK_OK if success
135          */
136         OCStackResult searchUser(const QueryParamsMap& queryParams,
137                                  GetCallback cloudConnectHandler);
138
139         /**
140          * Function to delete the device registered on the account signed-in.
141          *
142          * @param accessToken Identifier of the resource obtained by account registration.
143          * @param deviceId Device ID to delete.
144          * @param cloudConnectHandler Callback function that will get the result of the operation.
145          *
146          * @return Returns ::OC_STACK_OK if success
147          */
148         OCStackResult deleteDevice(const std::string& accessToken,
149                                    const std::string& deviceId,
150                                    DeleteCallback cloudConnectHandler);
151
152         /**
153          * Function to create a group on account server.
154          *
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 createGroup(PostCallback cloudConnectHandler);
160
161         /**
162          * Overload
163          *
164          * @param queryParams Map that has optional properties and values to create a group.
165          *                    Defined properties on the OCF spec are [gname, parent] so far.
166          *                    (2016/10/19)
167          * @param cloudConnectHandler Callback function that will get the result of the operation.
168          *
169          * @return Returns ::OC_STACK_OK if success
170          */
171         OCStackResult createGroup(const QueryParamsMap& queryParams,
172                                   PostCallback cloudConnectHandler);
173
174         /**
175          * Function to delete the group from account server.
176          *
177          * @param groupId Group ID to delete.
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 deleteGroup(const std::string& groupId,
183                                   DeleteCallback cloudConnectHandler);
184
185         /**
186          * Function to get infomation of all your group from account server.
187          *
188          * @param cloudConnectHandler Callback function that will get the result of the operation.
189          *
190          * @return Returns ::OC_STACK_OK if success
191          */
192
193         OCStackResult getGroupInfoAll(GetCallback cloudConnectHandler);
194
195         /**
196          * Function to get information of the specific group from account server.
197          *
198          * @param groupId Group ID to get information.
199          * @param cloudConnectHandler Callback function that will get the result of the operation.
200          *
201          * @return Returns ::OC_STACK_OK if success
202          */
203         OCStackResult getGroupInfo(const std::string& groupId,
204                                    GetCallback cloudConnectHandler);
205
206         /**
207          * Function to add values for properties to the group on account server.
208          *
209          * @param groupId Group ID to add property values.
210          * @param propertyValue OCRepresentation info that has pairs of property and value.
211          *                      Defined properties on the OCF spec are [members, masters, devices,
212          *                      resources, links] so far. (2016/10/19)
213          * @param cloudConnectHandler Callback function that will get the result of the operation.
214          *
215          * @return Returns ::OC_STACK_OK if success
216          */
217         OCStackResult addPropertyValueToGroup(const std::string& groupId,
218                                               const OCRepresentation propertyValue,
219                                               PostCallback cloudConnectHandler);
220
221         /**
222          * Function to delete values for properties from the group on account server.
223          *
224          * @param groupId Group ID to delete information.
225          * @param propertyValue OCRepresentation info that has pairs of property and value.
226          *                      Defined properties on the OCF spec are [members, masters, devices,
227          *                      resources, links] so far. (2016/10/19)
228          * @param cloudConnectHandler Callback function that will get the result of the operation.
229          *
230          * @return Returns ::OC_STACK_OK if success
231          */
232         OCStackResult deletePropertyValueFromGroup(const std::string& groupId,
233                                                    const OCRepresentation propertyValue,
234                                                    PostCallback cloudConnectHandler);
235
236         /**
237          * Function to update values for properties on the group on account server.
238          * It completely replaces existing values for specific properties.
239          *
240          * @param groupId Group ID to add devices.
241          * @param propertyValue OCRepresentation info that has pairs of property and value.
242          *                      Defined properties on the OCF spec are [members, gname, owner,
243          *                      masters, devices, resources, latitude, longitude, radius,
244          *                      backgroundImage] so far. (2016/10/19)
245          * @param cloudConnectHandler Callback function that will get the result of the operation.
246          *
247          * @return Returns ::OC_STACK_OK if success
248          */
249         OCStackResult updatePropertyValueOnGroup(const std::string& groupId,
250                                                  const OCRepresentation propertyValue,
251                                                  PostCallback cloudConnectHandler);
252
253         /**
254          * Function to register observe to group resource on account server.
255          * You can receive a notify when any value of property get changed in the group you joined.
256          *
257          * @param cloudConnectHandler Callback function that will get the result of the operation.
258          *
259          * @return Returns ::OC_STACK_OK if success
260          */
261         OCStackResult observeGroup(ObserveCallback cloudConnectHandler);
262
263         /**
264          * Function to cancel observe to group resource on account server.
265          *
266          * @return Returns ::OC_STACK_OK if success
267          */
268         OCStackResult cancelObserveGroup();
269
270         /**
271          * Function to register observe to invitation resource on account server.
272          * You can receive a notify when you send or receive a invitation.
273          * Sending a invitation will be notified as 'invite' and Receiving will be as 'invited'.
274          * If you receive a invitation from other user, you should call 'replyToInvitation' to
275          * delete the invitation on account server, otherwise it will remain on the server.
276          *
277          * @param cloudConnectHandler Callback function that will get the result of the operation.
278          *
279          * @return Returns ::OC_STACK_OK if success
280          */
281         OCStackResult observeInvitation(ObserveCallback cloudConnectHandler);
282
283         /**
284          * Function to cancel observe to invitation resource on account server.
285          *
286          * @return Returns ::OC_STACK_OK if success
287          */
288         OCStackResult cancelObserveInvitation();
289
290         /**
291          * Function to send a invitation to invite a user into a group.
292          *
293          * @param groupId Group ID for inviting.
294          * @param userUuid Identifier of the user to invite.
295          * @param cloudConnectHandler Callback function that will get the result of the operation.
296          *
297          * @return Returns ::OC_STACK_OK if success
298          */
299         OCStackResult sendInvitation(const std::string& groupId,
300                                      const std::string& userUuid,
301                                      PostCallback cloudConnectHandler);
302
303         /**
304          * Function to cancel a invitation you has sent on account server before the invited user
305          * replies.
306          *
307          * @param groupId Group ID to cancel a invitation.
308          * @param userUuid Identifier of the user to cancel a invitation.
309          * @param cloudConnectHandler Callback function that will get the result of the operation.
310          *
311          * @return Returns ::OC_STACK_OK if success
312          */
313         OCStackResult cancelInvitation(const std::string& groupId,
314                                        const std::string& userUuid,
315                                        DeleteCallback cloudConnectHandler);
316
317         /**
318          * Function to reply to the invitation that you has received.
319          * If you set accept as true, you will join the group as a member and the invitation
320          * will be deleted on account server.
321          * If false, only the invitation will be deleted.
322          *
323          * @param groupId Group ID to delete a invitation.
324          * @param accept boolean whether to join the group or not.
325          * @param cloudConnectHandler Callback function that will get the result of the operation.
326          *
327          * @return Returns ::OC_STACK_OK if success
328          */
329         OCStackResult replyToInvitation(const std::string& groupId,
330                                         const bool accept,
331                                         DeleteCallback cloudConnectHandler);
332
333     private:
334         std::weak_ptr<IClientWrapper> m_clientWrapper;
335         std::string m_deviceID;
336         std::string m_host;
337         std::string m_userUuid;
338         OCDoHandle m_invitationObserveHandle;
339         OCDoHandle m_groupObserveHandle;
340         OCConnectivityType m_connType;
341         QualityOfService m_defaultQos;
342
343     private:
344         OCAccountManager(std::weak_ptr<IClientWrapper> clientWrapper,
345                          const std::string& host,
346                          OCConnectivityType connectivityType);
347
348         OCStackResult signInOut(const std::string& userUuid,
349                                 const std::string& accessToken,
350                                 bool isSignIn,
351                                 PostCallback cloudConnectHandler);
352     };
353 } // namespace OC
354
355 #endif // OC_ACCOUNT_MANAGER_H_
356