Merge "Export internal APIs needed by samsung-socil" into tizen_2.1
[framework/osp/social.git] / src / FScl_AccountProviderImpl.cpp
1 //
2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17  * @file                FScl_AccountProviderImpl.cpp
18  * @brief               This is the implementation for _AccountProviderImpl class.
19  *
20  * This file contains definitions of @e _AccountProviderImpl class.
21  */
22
23 #include <FBaseColIList.h>
24 #include <FBaseResult.h>
25 #include <FBaseString.h>
26 #include <FBaseSysLog.h>
27 #include <FSclAccountProvider.h>
28 #include "FScl_AccountProviderImpl.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33
34 namespace Tizen { namespace Social
35 {
36
37 _AccountProviderImpl::_AccountProviderImpl(void)
38         : __isMultipleAccountSupported(false)
39 {
40         std::unique_ptr<ArrayList, AllElementsDeleter> pCapabilityList(new (std::nothrow) ArrayList());
41         SysTryReturnVoidResult(NID_SCL, pCapabilityList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
42
43         result r = pCapabilityList->Construct();
44         SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pCapabilityList.", GetErrorMessage(r));
45
46         __pCapabilityList = std::move(pCapabilityList);
47 }
48
49 _AccountProviderImpl::_AccountProviderImpl(const _AccountProviderImpl& rhs)
50 {
51         std::unique_ptr<ArrayList, AllElementsDeleter> pCapabilityList(new (std::nothrow) ArrayList());
52         SysTryReturnVoidResult(NID_SCL, pCapabilityList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
53
54         result r = pCapabilityList->Construct();
55         SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pCapabilityList.", GetErrorMessage(r));
56
57         std::unique_ptr<IEnumerator> pEnum(rhs.__pCapabilityList->GetEnumeratorN());
58         SysTryReturnVoidResult(NID_SCL, pEnum != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
59
60         std::unique_ptr<String> pCapability(null);
61         String* pTempCapability = null;
62
63         while (pEnum->MoveNext() == E_SUCCESS)
64         {
65                 pTempCapability = static_cast<String*> (pEnum->GetCurrent());
66                 pCapability.reset(new (std::nothrow) String(*pTempCapability));
67                 SysTryReturnVoidResult(NID_SCL, pCapability != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
68
69                 r = pCapabilityList->Add(pCapability.get());
70                 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
71
72                 pCapability.release();
73         }
74
75         __pCapabilityList = std::move(pCapabilityList);
76
77         __appId = rhs.__appId;
78         __displayName = rhs.__displayName;
79         __iconPath = rhs.__iconPath;
80         __smallIconPath = rhs.__smallIconPath;
81         __isMultipleAccountSupported = rhs.__isMultipleAccountSupported;
82 }
83
84 _AccountProviderImpl::~_AccountProviderImpl(void)
85 {
86         // empty body
87 }
88
89 _AccountProviderImpl&
90 _AccountProviderImpl::operator =(const _AccountProviderImpl& rhs)
91 {
92         if (this == &rhs)
93         {
94                 return *this;
95         }
96
97         std::unique_ptr<ArrayList, AllElementsDeleter> pCapabilityList(new (std::nothrow) ArrayList());
98         SysTryReturn(NID_SCL, pCapabilityList != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
99
100         result r = pCapabilityList->Construct();
101         SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Failed to construct pCapabilityList.", GetErrorMessage(r));
102
103         result prevResult = GetLastResult();
104
105         std::unique_ptr<IEnumerator> pEnum(rhs.__pCapabilityList->GetEnumeratorN());
106         SysTryReturn(NID_SCL, pEnum != null, *this, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
107
108         SetLastResult(prevResult);
109
110         std::unique_ptr<String> pCapability(null);
111         String* pTempCapability = null;
112
113         while (pEnum->MoveNext() == E_SUCCESS)
114         {
115                 pTempCapability = static_cast<String*> (pEnum->GetCurrent());
116                 pCapability.reset(new (std::nothrow) String(*pTempCapability));
117                 SysTryReturn(NID_SCL, pCapability != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
118
119                 r = pCapabilityList->Add(pCapability.get());
120                 SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Propagating.", GetErrorMessage(r));
121
122                 pCapability.release();
123         }
124
125         __pCapabilityList = std::move(pCapabilityList);
126
127         __appId = rhs.__appId;
128         __displayName = rhs.__displayName;
129         __iconPath = rhs.__iconPath;
130         __smallIconPath = rhs.__smallIconPath;
131         __isMultipleAccountSupported = rhs.__isMultipleAccountSupported;
132
133         return *this;
134 }
135
136 bool
137 _AccountProviderImpl::operator ==(const _AccountProviderImpl& rhs) const
138 {
139         if ((__appId == rhs.__appId) &&
140                 (__displayName == rhs.__displayName) &&
141                 (__iconPath == rhs.__iconPath) &&
142                 (__smallIconPath == rhs.__smallIconPath) &&
143                 (__isMultipleAccountSupported == rhs.__isMultipleAccountSupported) &&
144                 (__pCapabilityList->Equals(*(rhs.__pCapabilityList))))
145         {
146                 return true;
147         }
148
149         return false;
150 }
151
152 bool
153 _AccountProviderImpl::operator !=(const _AccountProviderImpl& rhs) const
154 {
155         return !(*this == rhs);
156 }
157
158 bool
159 _AccountProviderImpl::Equals(const Object& rhs) const
160 {
161         const _AccountProviderImpl* pAccountProviderImpl = dynamic_cast<const _AccountProviderImpl*> (&rhs);
162         if (pAccountProviderImpl == null)
163         {
164                 return false;
165         }
166
167         if ((__appId != pAccountProviderImpl->__appId) ||
168                 (__displayName != pAccountProviderImpl->__displayName) ||
169                 (__iconPath != pAccountProviderImpl->__iconPath) ||
170                 (__smallIconPath != pAccountProviderImpl->__smallIconPath) ||
171                 (__isMultipleAccountSupported != pAccountProviderImpl->__isMultipleAccountSupported) ||
172                 !(__pCapabilityList->Equals(*(pAccountProviderImpl->__pCapabilityList))))
173         {
174                 return false;
175         }
176
177         return true;
178 }
179
180 int
181 _AccountProviderImpl::GetHashCode(void) const
182 {
183         int hashCode = 0;
184
185         hashCode += __appId.GetHashCode();
186         hashCode += __displayName.GetHashCode();
187
188         return hashCode;
189 }
190
191 result
192 _AccountProviderImpl::AddCapability(const String& capability)
193 {
194         std::unique_ptr<IEnumerator> pEnum(__pCapabilityList->GetEnumeratorN());
195         SysTryReturnResult(NID_SCL, pEnum != null, GetLastResult(), "Propagating.");
196
197         String* pTempCapability = null;
198         bool alreadyExist = false;
199
200         while (pEnum->MoveNext() == E_SUCCESS)
201         {
202                 pTempCapability = static_cast<String*> (pEnum->GetCurrent());
203                 if (*pTempCapability == capability)
204                 {
205                         alreadyExist = true;
206                         break;
207                 }
208         }
209
210         SysTryReturnResult(NID_SCL, !alreadyExist, E_OBJ_ALREADY_EXIST, "The capability already exists.");
211
212         std::unique_ptr<String> pCapability(new (std::nothrow) String(capability));
213         SysTryReturnResult(NID_SCL, pCapability != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
214
215         result r = __pCapabilityList->Add(pCapability.get());
216         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
217
218         pCapability.release();
219
220         return E_SUCCESS;
221 }
222
223 AppId
224 _AccountProviderImpl::GetAppId(void) const
225 {
226         return __appId;
227 }
228
229 IList*
230 _AccountProviderImpl::GetCapabilitiesN(void) const
231 {
232         ClearLastResult();
233
234         std::unique_ptr<ArrayList, AllElementsDeleter> pCapabilityList(new (std::nothrow) ArrayList());
235         SysTryReturn(NID_SCL, pCapabilityList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
236
237         result r = pCapabilityList->Construct();
238         SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Failed to construct pCapabilityList.", GetErrorMessage(r));
239
240         std::unique_ptr<IEnumerator> pEnum(__pCapabilityList->GetEnumeratorN());
241         SysTryReturn(NID_SCL, pEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
242
243         std::unique_ptr<String> pCapability(null);
244         String* pTempCapability = null;
245
246         while (pEnum->MoveNext() == E_SUCCESS)
247         {
248                 pTempCapability = static_cast<String*> (pEnum->GetCurrent());
249                 pCapability.reset(new (std::nothrow) String(*pTempCapability));
250                 SysTryReturn(NID_SCL, pCapability != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
251
252                 r = pCapabilityList->Add(pCapability.get());
253                 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
254
255                 pCapability.release();
256         }
257
258         return pCapabilityList.release();
259 }
260
261 String
262 _AccountProviderImpl::GetDisplayName(void) const
263 {
264         return __displayName;
265 }
266
267 String
268 _AccountProviderImpl::GetIconPath(void) const
269 {
270         return __iconPath;
271 }
272
273 String
274 _AccountProviderImpl::GetSmallIconPath(void) const
275 {
276         return __smallIconPath;
277 }
278
279 bool
280 _AccountProviderImpl::IsMultipleAccountSupported(void) const
281 {
282         return __isMultipleAccountSupported;
283 }
284
285 void
286 _AccountProviderImpl::SetAppId(const AppId& appId)
287 {
288         __appId = appId;
289 }
290
291 void
292 _AccountProviderImpl::SetDisplayName(const String& displayName)
293 {
294         __displayName = displayName;
295 }
296
297 void
298 _AccountProviderImpl::SetIconPath(const String& iconPath)
299 {
300         __iconPath = iconPath;
301 }
302
303 void
304 _AccountProviderImpl::SetSmallIconPath(const String& smallIconPath)
305 {
306         __smallIconPath = smallIconPath;
307 }
308
309 void
310 _AccountProviderImpl::SetMultipleAccountsSupport(bool isSupported)
311 {
312         __isMultipleAccountSupported = isSupported;
313 }
314
315 const _AccountProviderImpl*
316 _AccountProviderImpl::GetInstance(const AccountProvider& accountProvider)
317 {
318         return accountProvider.__pAccountProviderImpl;
319 }
320
321 _AccountProviderImpl*
322 _AccountProviderImpl::GetInstance(AccountProvider& accountProvider)
323 {
324         return accountProvider.__pAccountProviderImpl;
325 }
326
327 }} //Tizen::Social