2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FScl_AccountProviderImpl.cpp
18 * @brief This is the implementation for _AccountProviderImpl class.
20 * This file contains definitions of @e _AccountProviderImpl class.
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"
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
34 namespace Tizen { namespace Social
37 _AccountProviderImpl::_AccountProviderImpl(void)
38 : __isMultipleAccountSupported(false)
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));
43 result r = pCapabilityList->Construct();
44 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pCapabilityList.", GetErrorMessage(r));
46 __pCapabilityList = std::move(pCapabilityList);
49 _AccountProviderImpl::_AccountProviderImpl(const _AccountProviderImpl& rhs)
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));
54 result r = pCapabilityList->Construct();
55 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pCapabilityList.", GetErrorMessage(r));
57 std::unique_ptr<IEnumerator> pEnum(rhs.__pCapabilityList->GetEnumeratorN());
58 SysTryReturnVoidResult(NID_SCL, pEnum != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
60 std::unique_ptr<String> pCapability(null);
61 String* pTempCapability = null;
63 while (pEnum->MoveNext() == E_SUCCESS)
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));
69 r = pCapabilityList->Add(pCapability.get());
70 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
72 pCapability.release();
75 __pCapabilityList = std::move(pCapabilityList);
77 __appId = rhs.__appId;
78 __displayName = rhs.__displayName;
79 __iconPath = rhs.__iconPath;
80 __smallIconPath = rhs.__smallIconPath;
81 __isMultipleAccountSupported = rhs.__isMultipleAccountSupported;
84 _AccountProviderImpl::~_AccountProviderImpl(void)
90 _AccountProviderImpl::operator =(const _AccountProviderImpl& rhs)
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));
100 result r = pCapabilityList->Construct();
101 SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Failed to construct pCapabilityList.", GetErrorMessage(r));
103 result prevResult = GetLastResult();
105 std::unique_ptr<IEnumerator> pEnum(rhs.__pCapabilityList->GetEnumeratorN());
106 SysTryReturn(NID_SCL, pEnum != null, *this, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
108 SetLastResult(prevResult);
110 std::unique_ptr<String> pCapability(null);
111 String* pTempCapability = null;
113 while (pEnum->MoveNext() == E_SUCCESS)
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));
119 r = pCapabilityList->Add(pCapability.get());
120 SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Propagating.", GetErrorMessage(r));
122 pCapability.release();
125 __pCapabilityList = std::move(pCapabilityList);
127 __appId = rhs.__appId;
128 __displayName = rhs.__displayName;
129 __iconPath = rhs.__iconPath;
130 __smallIconPath = rhs.__smallIconPath;
131 __isMultipleAccountSupported = rhs.__isMultipleAccountSupported;
137 _AccountProviderImpl::operator ==(const _AccountProviderImpl& rhs) const
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))))
153 _AccountProviderImpl::operator !=(const _AccountProviderImpl& rhs) const
155 return !(*this == rhs);
159 _AccountProviderImpl::Equals(const Object& rhs) const
161 const _AccountProviderImpl* pAccountProviderImpl = dynamic_cast<const _AccountProviderImpl*> (&rhs);
162 if (pAccountProviderImpl == null)
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))))
181 _AccountProviderImpl::GetHashCode(void) const
185 hashCode += __appId.GetHashCode();
186 hashCode += __displayName.GetHashCode();
192 _AccountProviderImpl::AddCapability(const String& capability)
194 std::unique_ptr<IEnumerator> pEnum(__pCapabilityList->GetEnumeratorN());
195 SysTryReturnResult(NID_SCL, pEnum != null, GetLastResult(), "Propagating.");
197 String* pTempCapability = null;
198 bool alreadyExist = false;
200 while (pEnum->MoveNext() == E_SUCCESS)
202 pTempCapability = static_cast<String*> (pEnum->GetCurrent());
203 if (*pTempCapability == capability)
210 SysTryReturnResult(NID_SCL, !alreadyExist, E_OBJ_ALREADY_EXIST, "The capability already exists.");
212 std::unique_ptr<String> pCapability(new (std::nothrow) String(capability));
213 SysTryReturnResult(NID_SCL, pCapability != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
215 result r = __pCapabilityList->Add(pCapability.get());
216 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
218 pCapability.release();
224 _AccountProviderImpl::GetAppId(void) const
230 _AccountProviderImpl::GetCapabilitiesN(void) const
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));
237 result r = pCapabilityList->Construct();
238 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Failed to construct pCapabilityList.", GetErrorMessage(r));
240 std::unique_ptr<IEnumerator> pEnum(__pCapabilityList->GetEnumeratorN());
241 SysTryReturn(NID_SCL, pEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
243 std::unique_ptr<String> pCapability(null);
244 String* pTempCapability = null;
246 while (pEnum->MoveNext() == E_SUCCESS)
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));
252 r = pCapabilityList->Add(pCapability.get());
253 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
255 pCapability.release();
258 return pCapabilityList.release();
262 _AccountProviderImpl::GetDisplayName(void) const
264 return __displayName;
268 _AccountProviderImpl::GetIconPath(void) const
274 _AccountProviderImpl::GetSmallIconPath(void) const
276 return __smallIconPath;
280 _AccountProviderImpl::IsMultipleAccountSupported(void) const
282 return __isMultipleAccountSupported;
286 _AccountProviderImpl::SetAppId(const AppId& appId)
292 _AccountProviderImpl::SetDisplayName(const String& displayName)
294 __displayName = displayName;
298 _AccountProviderImpl::SetIconPath(const String& iconPath)
300 __iconPath = iconPath;
304 _AccountProviderImpl::SetSmallIconPath(const String& smallIconPath)
306 __smallIconPath = smallIconPath;
310 _AccountProviderImpl::SetMultipleAccountsSupport(bool isSupported)
312 __isMultipleAccountSupported = isSupported;
315 const _AccountProviderImpl*
316 _AccountProviderImpl::GetInstance(const AccountProvider& accountProvider)
318 return accountProvider.__pAccountProviderImpl;
321 _AccountProviderImpl*
322 _AccountProviderImpl::GetInstance(AccountProvider& accountProvider)
324 return accountProvider.__pAccountProviderImpl;