Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNetNetAccountInfo.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FNetNetAccountInfo.cpp
19  * @brief               This is the implementation for the FNetNetAccountInfo class.
20  */
21
22 #include <unique_ptr.h>
23 #include <FBaseString.h>
24 #include <FBaseUtilStringUtil.h>
25 #include <FNetNetTypes.h>
26 #include <FNetNetEndPoint.h>
27 #include <FNetNetAccountInfo.h>
28 #include <FNetNetAccountManager.h>
29 #include <FBaseSysLog.h>
30 #include "FNet_NetTypes.h"
31 #include "FNet_NetAccountInfoImpl.h"
32
33 using namespace std;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Utility;
36
37 namespace Tizen { namespace Net
38 {
39
40 NetAccountInfo::NetAccountInfo(void)
41         : __pNetAccountInfoImpl(null)
42 {
43 }
44
45 NetAccountInfo::~NetAccountInfo(void)
46 {
47         delete __pNetAccountInfoImpl;
48         __pNetAccountInfoImpl = null;
49 }
50
51 result
52 NetAccountInfo::Construct(const NetAccountInfo& netAccountInfo)
53 {
54         result r = E_SUCCESS;
55         const _NetAccountInfoImpl* pOtherNetAccountInfoImpl = _NetAccountInfoImpl::GetInstance(netAccountInfo);
56
57         SysAssertf(__pNetAccountInfoImpl == null,
58                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
59
60         SysTryReturnResult(NID_NET, pOtherNetAccountInfoImpl != null, E_INVALID_ARG,
61                         "[%s] Invalid argument is used. The specified netAccountInfo is invalid.", GetErrorMessage(E_INVALID_ARG));
62
63         unique_ptr<_NetAccountInfoImpl> pNetAccountInfoImpl(new (std::nothrow) _NetAccountInfoImpl());
64         SysTryReturnResult(NID_NET, pNetAccountInfoImpl != null, E_OUT_OF_MEMORY,
65                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
66
67         r = pNetAccountInfoImpl->Construct(*pOtherNetAccountInfoImpl);
68         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
69
70         __pNetAccountInfoImpl = pNetAccountInfoImpl.release();
71
72         return r;
73 }
74
75 result
76 NetAccountInfo::Construct(void)
77 {
78         result r = E_SUCCESS;
79
80         SysAssertf(__pNetAccountInfoImpl == null,
81                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
82
83         unique_ptr<_NetAccountInfoImpl> pNetAccountInfoImpl(new (std::nothrow) _NetAccountInfoImpl());
84         SysTryReturnResult(NID_NET, pNetAccountInfoImpl != null, E_OUT_OF_MEMORY,
85                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
86
87         r = pNetAccountInfoImpl->Construct();
88         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
89
90         __pNetAccountInfoImpl = pNetAccountInfoImpl.release();
91
92         return r;
93 }
94
95 NetAccountId
96 NetAccountInfo::GetAccountId(void)  const
97 {
98         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
99
100         return __pNetAccountInfoImpl->GetAccountId();
101 }
102
103 String
104 NetAccountInfo::GetAccountName(void) const
105 {
106         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
107
108         return __pNetAccountInfoImpl->GetAccountName();
109 }
110
111 result
112 NetAccountInfo::SetAccountName(const String& accountName)
113 {
114         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
115
116         return __pNetAccountInfoImpl->SetAccountName(accountName);
117 }
118
119 NetProtocolType
120 NetAccountInfo::GetProtocolType(void) const
121 {
122         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
123
124         return __pNetAccountInfoImpl->GetProtocolType();
125 }
126
127 result
128 NetAccountInfo::SetProtocolType(const NetProtocolType netProtocolType)
129 {
130         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
131
132         return __pNetAccountInfoImpl->SetProtocolType(netProtocolType);
133 }
134
135 String
136 NetAccountInfo::GetAccessPointName(void)  const
137 {
138         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
139
140         return __pNetAccountInfoImpl->GetAccessPointName();
141 }
142
143 result
144 NetAccountInfo::SetAccessPointName(const String& accessPointName)
145 {
146         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
147
148         return __pNetAccountInfoImpl->SetAccessPointName(accessPointName);
149 }
150
151 NetAddressScheme
152 NetAccountInfo::GetLocalAddressScheme(void) const
153 {
154         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
155
156         return __pNetAccountInfoImpl->GetLocalAddressScheme();
157 }
158
159 const IpAddress*
160 NetAccountInfo::GetLocalAddress(void) const
161 {
162         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
163
164         return __pNetAccountInfoImpl->GetLocalAddress();
165 }
166
167 result
168 NetAccountInfo::SetLocalAddress(NetAddressScheme localAddrScheme, const IpAddress* pLocalAddress)
169 {
170         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
171
172         return __pNetAccountInfoImpl->SetLocalAddress(localAddrScheme, pLocalAddress);
173 }
174
175 const NetEndPoint*
176 NetAccountInfo::GetProxyAddress(void) const
177 {
178         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
179
180         return __pNetAccountInfoImpl->GetProxyAddress();
181 }
182
183 result
184 NetAccountInfo::SetProxyAddress(const NetEndPoint* pProxyEndPoint)
185 {
186         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
187
188         return __pNetAccountInfoImpl->SetProxyAddress(pProxyEndPoint);
189 }
190
191 NetAddressScheme
192 NetAccountInfo::GetDnsAddressScheme(void) const
193 {
194         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
195
196         return __pNetAccountInfoImpl->GetDnsAddressScheme();
197 }
198
199 const IpAddress*
200 NetAccountInfo::GetPrimaryDnsAddress(void) const
201 {
202         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
203
204         return __pNetAccountInfoImpl->GetPrimaryDnsAddress();
205 }
206
207 const IpAddress*
208 NetAccountInfo::GetSecondaryDnsAddress(void) const
209 {
210         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
211
212         return __pNetAccountInfoImpl->GetSecondaryDnsAddress();
213 }
214
215 result
216 NetAccountInfo::SetDnsAddress(NetAddressScheme dnsAddressScheme, const IpAddress* pPrimaryDnsAddress,
217                                                           const IpAddress* pSecondaryDnsAddress)
218 {
219         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
220
221         return __pNetAccountInfoImpl->SetDnsAddress(dnsAddressScheme, pPrimaryDnsAddress, pSecondaryDnsAddress);
222 }
223
224 result
225 NetAccountInfo::GetAuthenticationInfo(NetNapAuthType& authenticationType, String& id, String& password) const
226 {
227         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
228
229         return __pNetAccountInfoImpl->GetAuthenticationInfo(authenticationType, id, password);
230 }
231
232 result
233 NetAccountInfo::SetAuthenticationInfo(NetNapAuthType authenticationType, const String& id, const String& password)
234 {
235         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
236
237         return __pNetAccountInfoImpl->SetAuthenticationInfo(authenticationType, id, password);
238 }
239
240 NetBearerType
241 NetAccountInfo::GetBearerType(void) const
242 {
243         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
244
245         return __pNetAccountInfoImpl->GetBearerType();
246 }
247
248 String
249 NetAccountInfo::GetHomeUrl(void) const
250 {
251         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
252
253         return __pNetAccountInfoImpl->GetHomeUrl();
254 }
255
256 void
257 NetAccountInfo::SetHomeUrl(const String& homeUrl)
258 {
259         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
260
261         __pNetAccountInfoImpl->SetHomeUrl(homeUrl);
262 }
263
264 int
265 NetAccountInfo::GetMaximumLengthOfId(void) const
266 {
267         return _MAX_AUTH_ID_LENGTH;
268 }
269
270 int
271 NetAccountInfo::GetMaximumLengthOfPassword(void) const
272 {
273         return _MAX_AUTH_PASSWORD_LENGTH;
274 }
275
276 int
277 NetAccountInfo::GetMaximumLengthOfAccountName(void) const
278 {
279         return _MAX_ACCOUNT_NAME_LENGTH;
280 }
281
282 bool
283 NetAccountInfo::IsReadOnly(void) const
284 {
285         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
286
287         return __pNetAccountInfoImpl->IsReadOnly();
288 }
289
290 bool
291 NetAccountInfo::Equals(const Object& rhs) const
292 {
293         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
294
295         const NetAccountInfo* pRhs = dynamic_cast<const NetAccountInfo*>(&rhs);
296         if (pRhs == null)
297         {
298                 return false;
299         }
300
301         const _NetAccountInfoImpl* pRhsImpl = _NetAccountInfoImpl::GetInstance(*pRhs);
302         if (pRhsImpl == null)
303         {
304                 return false;
305         }
306
307         return __pNetAccountInfoImpl->Equals(*pRhsImpl);
308 }
309
310 int
311 NetAccountInfo::GetHashCode(void) const
312 {
313         SysAssertf(__pNetAccountInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
314
315         return __pNetAccountInfoImpl->GetHashCode();
316 }
317
318 }} // Tizen::Net