Implementation of JNI for subscribe device presence to RD
[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 <OCApi.h>
25 #include <IClientWrapper.h>
26 #include <InProcClientWrapper.h>
27
28 namespace OC
29 {
30     class OCAccountManager
31     {
32         friend class OCPlatform_impl;
33
34     public:
35         typedef std::shared_ptr<OCAccountManager> Ptr;
36
37         OCAccountManager(OCAccountManager&&) = default;
38         OCAccountManager(const OCAccountManager&) = delete;
39         OCAccountManager& operator=(OCAccountManager&&) = delete;
40         OCAccountManager& operator=(const OCAccountManager&) = delete;
41
42         virtual ~OCAccountManager(void);
43
44         /**
45         * Function to get the host address of account server
46         *
47         * @return std::string host address
48         */
49         std::string host() const;
50
51         /**
52         * Function to get the connectivity type for account server
53         *
54         * @return enum connectivity type (flags and adapter)
55         */
56         OCConnectivityType connectivityType() const;
57
58         /**
59          * Function for account registration to account server
60          *
61          * @param authProvider Provider name used for authentication.
62          * @param authCode The authorization code obtained by using an authorization server
63          *                 as an intermediary between the client and resource owner.
64          * @param cloudConnectHandler Callback function that will get the result of the operation.
65          *
66          * @return Returns ::OC_STACK_OK if success
67          */
68         OCStackResult signUp(const std::string& authProvider,
69                              const std::string& authCode,
70                              PostCallback cloudConnectHandler);
71
72         /**
73          * Overload
74          *
75          * @param authProvider Provider name used for authentication.
76          * @param authCode The authorization code obtained by using an authorization server
77          *                 as an intermediary between the client and resource owner.
78          * @param options The option values depends on auth provider.
79          * @param cloudConnectHandler Callback function that will get the result of the operation.
80          *
81          * @return Returns ::OC_STACK_OK if success
82          */
83         OCStackResult signUp(const std::string& authProvider,
84                              const std::string& authCode,
85                              const QueryParamsMap& options,
86                              PostCallback cloudConnectHandler);
87
88         /**
89          * Function for sign-in to account server
90          *
91          * @param userUuid Identifier of the user obtained by account registration.
92          * @param accessToken Identifier of the resource obtained by account registration.
93          * @param cloudConnectHandler Callback function that will get the result of the operation.
94          *
95          * @return Returns ::OC_STACK_OK if success
96          */
97         OCStackResult signIn(const std::string& userUuid,
98                              const std::string& accessToken,
99                              PostCallback cloudConnectHandler);
100
101         /**
102          * Function for sign-out to account server
103          *
104          * @param cloudConnectHandler Callback function that will get the result of the operation.
105          *
106          * @return Returns ::OC_STACK_OK if success
107          */
108         OCStackResult signOut(PostCallback cloudConnectHandler);
109
110         /**
111          * Function for refresh access token to account server
112          *
113          * @param userUuid Identifier of the user obtained by account registration.
114          * @param refreshToken Refresh token used for access token refresh.
115          * @param cloudConnectHandler Callback function that will get the result of the operation.
116          *
117          * @return Returns ::OC_STACK_OK if success
118          */
119         OCStackResult refreshAccessToken(const std::string& userUuid,
120                                          const std::string& refreshToken,
121                                          PostCallback cloudConnectHandler);
122
123         /**
124          * Function to get information of the user to account server
125          *
126          * @param userUuid Identifier of the user to get information.
127          * @param cloudConnectHandler Callback function that will get the result of the operation.
128          *
129          * @return Returns ::OC_STACK_OK if success
130          */
131         OCStackResult searchUser(const std::string& userUuid,
132                                  GetCallback cloudConnectHandler);
133
134         /**
135          * Overload
136          *
137          * @param queryParams Map which can have the query key and value for specific users.
138          *                    account server can response information of more than one user.
139          * @param cloudConnectHandler Callback function that will get the result of the operation.
140          *
141          * @return Returns ::OC_STACK_OK if success
142          */
143         OCStackResult searchUser(const QueryParamsMap& queryParams,
144                                  GetCallback cloudConnectHandler);
145
146         /**
147          * Function to delete the device registered on the account signed-in
148          *
149          * @param deviceId Device ID to delete.
150          * @param cloudConnectHandler Callback function that will get the result of the operation.
151          *
152          * @return Returns ::OC_STACK_OK if success
153          */
154         OCStackResult deleteDevice(const std::string& deviceId,
155                                    DeleteCallback cloudConnectHandler);
156
157     private:
158         std::weak_ptr<IClientWrapper> m_clientWrapper;
159         std::string m_deviceID;
160         std::string m_host;
161         OCConnectivityType m_connType;
162         QualityOfService m_defaultQos;
163
164     private:
165         OCAccountManager(std::weak_ptr<IClientWrapper> clientWrapper,
166                          const std::string& host,
167                          OCConnectivityType connectivityType);
168
169         OCStackResult signInOut(const std::string& userUuid,
170                                 const std::string& accessToken,
171                                 bool isSignIn,
172                                 PostCallback cloudConnectHandler);
173
174         OCStackResult searchUser(const std::string& userUuid,
175                                  const QueryParamsMap& queryParams,
176                                  GetCallback cloudConnectHandler);
177     };
178 } // namespace OC
179
180 #endif // OC_ACCOUNT_MANAGER_H_
181