1 /* ****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
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 ******************************************************************/
21 #ifndef OC_ACCOUNT_MANAGER_H_
22 #define OC_ACCOUNT_MANAGER_H_
27 #include <IClientWrapper.h>
28 #include <InProcClientWrapper.h>
32 class OCAccountManager
34 friend class OCPlatform_impl;
37 typedef std::shared_ptr<OCAccountManager> Ptr;
39 OCAccountManager(OCAccountManager&&) = default;
40 OCAccountManager(const OCAccountManager&) = delete;
41 OCAccountManager& operator=(OCAccountManager&&) = delete;
42 OCAccountManager& operator=(const OCAccountManager&) = delete;
44 virtual ~OCAccountManager(void);
47 * Function to get the host address of account server.
49 * @return std::string host address
51 std::string host() const;
54 * Function to get the connectivity type for account server.
56 * @return enum connectivity type (flags and adapter)
58 OCConnectivityType connectivityType() const;
61 * Function for account registration to account server.
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.
68 * @return Returns ::OC_STACK_OK if success
70 OCStackResult signUp(const std::string& authProvider,
71 const std::string& authCode,
72 PostCallback cloudConnectHandler);
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.
83 * @return Returns ::OC_STACK_OK if success
85 OCStackResult signUp(const std::string& authProvider,
86 const std::string& authCode,
87 const QueryParamsMap& options,
88 PostCallback cloudConnectHandler);
91 * Function for sign-in to account server.
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.
97 * @return Returns ::OC_STACK_OK if success
99 OCStackResult signIn(const std::string& userUuid,
100 const std::string& accessToken,
101 PostCallback cloudConnectHandler);
104 * Function for sign-out to account server.
106 * @param accessToken Identifier of the resource obtained by account registration.
107 * @param cloudConnectHandler Callback function that will get the result of the operation.
109 * @return Returns ::OC_STACK_OK if success
111 OCStackResult signOut(const std::string& accessToken,
112 PostCallback cloudConnectHandler);
115 * Function for refresh access token to account server.
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.
121 * @return Returns ::OC_STACK_OK if success
123 OCStackResult refreshAccessToken(const std::string& userUuid,
124 const std::string& refreshToken,
125 PostCallback cloudConnectHandler);
128 * Function to get information of the user to account server.
130 * @param userUuid Identifier of the user to get information.
131 * @param cloudConnectHandler Callback function that will get the result of the operation.
133 * @return Returns ::OC_STACK_OK if success
135 OCStackResult searchUser(const std::string& userUuid,
136 GetCallback cloudConnectHandler);
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.
145 * @return Returns ::OC_STACK_OK if success
147 OCStackResult searchUser(const QueryParamsMap& queryParams,
148 GetCallback cloudConnectHandler);
151 * Function to delete the device registered on the account signed-in.
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.
157 * @return Returns ::OC_STACK_OK if success
159 OCStackResult deleteDevice(const std::string& accessToken,
160 const std::string& deviceId,
161 DeleteCallback cloudConnectHandler);
164 * Function to create a group on account server.
166 * @param cloudConnectHandler Callback function that will get the result of the operation.
168 * @return Returns ::OC_STACK_OK if success
170 OCStackResult createGroup(PostCallback cloudConnectHandler);
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.
178 * @param cloudConnectHandler Callback function that will get the result of the operation.
180 * @return Returns ::OC_STACK_OK if success
182 OCStackResult createGroup(const QueryParamsMap& queryParams,
183 PostCallback cloudConnectHandler);
186 * Function to delete the group from account server.
188 * @param groupId Group ID to delete.
189 * @param cloudConnectHandler Callback function that will get the result of the operation.
191 * @return Returns ::OC_STACK_OK if success
193 OCStackResult deleteGroup(const std::string& groupId,
194 DeleteCallback cloudConnectHandler);
197 * Function to get infomation of all your group from account server.
199 * @param cloudConnectHandler Callback function that will get the result of the operation.
201 * @return Returns ::OC_STACK_OK if success
204 OCStackResult getGroupInfoAll(GetCallback cloudConnectHandler);
207 * Function to get information of the specific group from account server.
209 * @param groupId Group ID to get information.
210 * @param cloudConnectHandler Callback function that will get the result of the operation.
212 * @return Returns ::OC_STACK_OK if success
214 OCStackResult getGroupInfo(const std::string& groupId,
215 GetCallback cloudConnectHandler);
218 * Function to add values for properties to the group on account server.
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.
226 * @return Returns ::OC_STACK_OK if success
228 OCStackResult addPropertyValueToGroup(const std::string& groupId,
229 const OCRepresentation propertyValue,
230 PostCallback cloudConnectHandler);
233 * Function to delete values for properties from the group on account server.
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.
241 * @return Returns ::OC_STACK_OK if success
243 OCStackResult deletePropertyValueFromGroup(const std::string& groupId,
244 const OCRepresentation propertyValue,
245 PostCallback cloudConnectHandler);
248 * Function to update values for properties on the group on account server.
249 * It completely replaces existing values for specific properties.
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.
258 * @return Returns ::OC_STACK_OK if success
260 OCStackResult updatePropertyValueOnGroup(const std::string& groupId,
261 const OCRepresentation propertyValue,
262 PostCallback cloudConnectHandler);
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.
268 * @param cloudConnectHandler Callback function that will get the result of the operation.
270 * @return Returns ::OC_STACK_OK if success
272 OCStackResult observeGroup(ObserveCallback cloudConnectHandler);
275 * Function to cancel observe to group resource on account server.
277 * @return Returns ::OC_STACK_OK if success
279 OCStackResult cancelObserveGroup();
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.
288 * @param cloudConnectHandler Callback function that will get the result of the operation.
290 * @return Returns ::OC_STACK_OK if success
292 OCStackResult observeInvitation(ObserveCallback cloudConnectHandler);
295 * Function to cancel observe to invitation resource on account server.
297 * @return Returns ::OC_STACK_OK if success
299 OCStackResult cancelObserveInvitation();
302 * Function to send a invitation to invite a user into a group.
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.
308 * @return Returns ::OC_STACK_OK if success
310 OCStackResult sendInvitation(const std::string& groupId,
311 const std::string& userUuid,
312 PostCallback cloudConnectHandler);
315 * Function to cancel a invitation you has sent on account server before the invited user
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.
322 * @return Returns ::OC_STACK_OK if success
324 OCStackResult cancelInvitation(const std::string& groupId,
325 const std::string& userUuid,
326 DeleteCallback cloudConnectHandler);
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.
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.
338 * @return Returns ::OC_STACK_OK if success
340 OCStackResult replyToInvitation(const std::string& groupId,
342 DeleteCallback cloudConnectHandler);
345 std::weak_ptr<IClientWrapper> m_clientWrapper;
346 std::string m_deviceID;
348 std::string m_userUuid;
349 OCDoHandle m_invitationObserveHandle;
350 OCDoHandle m_groupObserveHandle;
351 OCConnectivityType m_connType;
352 QualityOfService m_defaultQos;
355 OCAccountManager(std::weak_ptr<IClientWrapper> clientWrapper,
356 const std::string& host,
357 OCConnectivityType connectivityType);
359 OCStackResult signInOut(const std::string& userUuid,
360 const std::string& accessToken,
362 PostCallback cloudConnectHandler);
364 OCStackResult searchUser(const std::string& userUuid,
365 const QueryParamsMap& queryParams,
366 GetCallback cloudConnectHandler);
370 #endif // OC_ACCOUNT_MANAGER_H_