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 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.
134 * @return Returns ::OC_STACK_OK if success
136 OCStackResult searchUser(const QueryParamsMap& queryParams,
137 GetCallback cloudConnectHandler);
140 * Function to delete the device registered on the account signed-in.
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.
146 * @return Returns ::OC_STACK_OK if success
148 OCStackResult deleteDevice(const std::string& accessToken,
149 const std::string& deviceId,
150 DeleteCallback cloudConnectHandler);
153 * Function to create a group on account server.
155 * @param cloudConnectHandler Callback function that will get the result of the operation.
157 * @return Returns ::OC_STACK_OK if success
159 OCStackResult createGroup(PostCallback cloudConnectHandler);
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.
167 * @param cloudConnectHandler Callback function that will get the result of the operation.
169 * @return Returns ::OC_STACK_OK if success
171 OCStackResult createGroup(const QueryParamsMap& queryParams,
172 PostCallback cloudConnectHandler);
175 * Function to delete the group from account server.
177 * @param groupId Group ID to delete.
178 * @param cloudConnectHandler Callback function that will get the result of the operation.
180 * @return Returns ::OC_STACK_OK if success
182 OCStackResult deleteGroup(const std::string& groupId,
183 DeleteCallback cloudConnectHandler);
186 * Function to get infomation of all your group from account server.
188 * @param cloudConnectHandler Callback function that will get the result of the operation.
190 * @return Returns ::OC_STACK_OK if success
193 OCStackResult getGroupInfoAll(GetCallback cloudConnectHandler);
196 * Function to get information of the specific group from account server.
198 * @param groupId Group ID to get information.
199 * @param cloudConnectHandler Callback function that will get the result of the operation.
201 * @return Returns ::OC_STACK_OK if success
203 OCStackResult getGroupInfo(const std::string& groupId,
204 GetCallback cloudConnectHandler);
207 * Function to add values for properties to the group on account server.
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.
215 * @return Returns ::OC_STACK_OK if success
217 OCStackResult addPropertyValueToGroup(const std::string& groupId,
218 const OCRepresentation propertyValue,
219 PostCallback cloudConnectHandler);
222 * Function to delete values for properties from the group on account server.
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.
230 * @return Returns ::OC_STACK_OK if success
232 OCStackResult deletePropertyValueFromGroup(const std::string& groupId,
233 const OCRepresentation propertyValue,
234 PostCallback cloudConnectHandler);
237 * Function to update values for properties on the group on account server.
238 * It completely replaces existing values for specific properties.
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.
247 * @return Returns ::OC_STACK_OK if success
249 OCStackResult updatePropertyValueOnGroup(const std::string& groupId,
250 const OCRepresentation propertyValue,
251 PostCallback cloudConnectHandler);
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.
257 * @param cloudConnectHandler Callback function that will get the result of the operation.
259 * @return Returns ::OC_STACK_OK if success
261 OCStackResult observeGroup(ObserveCallback cloudConnectHandler);
264 * Function to cancel observe to group resource on account server.
266 * @return Returns ::OC_STACK_OK if success
268 OCStackResult cancelObserveGroup();
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.
277 * @param cloudConnectHandler Callback function that will get the result of the operation.
279 * @return Returns ::OC_STACK_OK if success
281 OCStackResult observeInvitation(ObserveCallback cloudConnectHandler);
284 * Function to cancel observe to invitation resource on account server.
286 * @return Returns ::OC_STACK_OK if success
288 OCStackResult cancelObserveInvitation();
291 * Function to send a invitation to invite a user into a group.
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.
297 * @return Returns ::OC_STACK_OK if success
299 OCStackResult sendInvitation(const std::string& groupId,
300 const std::string& userUuid,
301 PostCallback cloudConnectHandler);
304 * Function to cancel a invitation you has sent on account server before the invited user
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.
311 * @return Returns ::OC_STACK_OK if success
313 OCStackResult cancelInvitation(const std::string& groupId,
314 const std::string& userUuid,
315 DeleteCallback cloudConnectHandler);
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.
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.
327 * @return Returns ::OC_STACK_OK if success
329 OCStackResult replyToInvitation(const std::string& groupId,
331 DeleteCallback cloudConnectHandler);
334 std::weak_ptr<IClientWrapper> m_clientWrapper;
335 std::string m_deviceID;
337 std::string m_userUuid;
338 OCDoHandle m_invitationObserveHandle;
339 OCDoHandle m_groupObserveHandle;
340 OCConnectivityType m_connType;
341 QualityOfService m_defaultQos;
344 OCAccountManager(std::weak_ptr<IClientWrapper> clientWrapper,
345 const std::string& host,
346 OCConnectivityType connectivityType);
348 OCStackResult signInOut(const std::string& userUuid,
349 const std::string& accessToken,
351 PostCallback cloudConnectHandler);
355 #endif // OC_ACCOUNT_MANAGER_H_