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_AccountImpl.cpp
18 * @brief This is the implementation for _AccountImpl class.
20 * This file contains definitions of @e _AccountImpl class.
24 #include <FBaseResult.h>
25 #include <FBaseString.h>
26 #include <FBaseSysLog.h>
27 #include <FSclAccount.h>
28 #include "FScl_AccountImpl.h"
29 #include "FScl_AccountProviderImpl.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace Social
39 _AccountImpl::_AccountImpl(const Tizen::Base::String& userName)
40 : __id(INVALID_RECORD_ID)
42 std::unique_ptr<HashMap, AllElementsDeleter> pExtendedData(new (std::nothrow) HashMap());
43 SysTryReturnVoidResult(NID_SCL, pExtendedData != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45 result r = pExtendedData->Construct();
46 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r));
48 __pExtendedData = std::move(pExtendedData);
49 __userName = userName;
52 _AccountImpl::_AccountImpl(const _AccountImpl& rhs)
54 std::unique_ptr<HashMap, AllElementsDeleter> pExtendedData(new (std::nothrow) HashMap());
55 SysTryReturnVoidResult(NID_SCL, pExtendedData != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
57 result r = pExtendedData->Construct();
58 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r));
60 std::unique_ptr<IMapEnumerator> pMapEnum((rhs.__pExtendedData)->GetMapEnumeratorN());
61 SysTryReturnVoidResult(NID_SCL, pMapEnum != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
63 std::unique_ptr<String> pKey(null);
64 std::unique_ptr<String> pVal(null);
67 while (pMapEnum->MoveNext() == E_SUCCESS)
69 pStr = static_cast<String*> (pMapEnum->GetKey());
70 pKey.reset(new (std::nothrow) String(*pStr));
71 SysTryReturnVoidResult(NID_SCL, pKey != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
73 pStr = static_cast<String*> (pMapEnum->GetValue());
74 pVal.reset(new (std::nothrow) String(*pStr));
75 SysTryReturnVoidResult(NID_SCL, pVal != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
77 r = pExtendedData->Add(pKey.get(), pVal.get());
78 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
84 __pExtendedData = std::move(pExtendedData);
87 __userName = rhs.__userName;
88 __accountProvider = rhs.__accountProvider;
91 _AccountImpl::~_AccountImpl(void)
97 _AccountImpl::operator =(const _AccountImpl& rhs)
104 std::unique_ptr<HashMap, AllElementsDeleter> pExtendedData(new (std::nothrow) HashMap());
105 SysTryReturn(NID_SCL, pExtendedData != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
107 result r = pExtendedData->Construct();
108 SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r));
110 result prevResult = GetLastResult();
112 std::unique_ptr<IMapEnumerator> pMapEnum((rhs.__pExtendedData)->GetMapEnumeratorN());
113 SysTryReturn(NID_SCL, pMapEnum != null, *this, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
115 SetLastResult(prevResult);
117 std::unique_ptr<String> pKey(null);
118 std::unique_ptr<String> pVal(null);
121 while (pMapEnum->MoveNext() == E_SUCCESS)
123 pStr = static_cast<String*> (pMapEnum->GetKey());
124 pKey.reset(new (std::nothrow) String(*pStr));
125 SysTryReturn(NID_SCL, pKey != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
127 pStr = static_cast<String*> (pMapEnum->GetValue());
128 pVal.reset(new (std::nothrow) String(*pStr));
129 SysTryReturn(NID_SCL, pVal != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
131 r = pExtendedData->Add(pKey.get(), pVal.get());
132 SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Propagating.", GetErrorMessage(r));
138 __pExtendedData = std::move(pExtendedData);
141 __userName = rhs.__userName;
142 __accountProvider = rhs.__accountProvider;
148 _AccountImpl::Equals(const Object& rhs) const
150 const _AccountImpl* pAccountImpl = dynamic_cast<const _AccountImpl*> (&rhs);
151 if (pAccountImpl == null)
156 if (__id != pAccountImpl->__id
157 || __userName != pAccountImpl->__userName)
162 if (*(_AccountProviderImpl::GetInstance(__accountProvider)) != *(_AccountProviderImpl::GetInstance(pAccountImpl->__accountProvider)))
167 if (!(__pExtendedData->Equals(*(pAccountImpl->__pExtendedData))))
176 _AccountImpl::GetHashCode(void) const
178 int hashCode = 0xffffffff & __id;
179 hashCode += hashCode;
185 _AccountImpl::GetId(void) const
191 _AccountImpl::GetAccountProvider(void) const
193 return __accountProvider;
197 _AccountImpl::GetUserName(void) const
203 _AccountImpl::GetExtendedDataN(void) const
207 std::unique_ptr<HashMap, AllElementsDeleter> pExtendedData(new (std::nothrow) HashMap());
208 SysTryReturn(NID_SCL, pExtendedData != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
210 result r = pExtendedData->Construct();
211 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r));
213 std::unique_ptr<IMapEnumerator> pMapEnum(__pExtendedData->GetMapEnumeratorN());
214 SysTryReturn(NID_SCL, pMapEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
216 std::unique_ptr<String> pKey(null);
217 std::unique_ptr<String> pVal(null);
220 while (pMapEnum->MoveNext() == E_SUCCESS)
222 pStr = static_cast<String*> (pMapEnum->GetKey());
223 pKey.reset(new (std::nothrow) String(*pStr));
224 SysTryReturn(NID_SCL, pKey != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
226 pStr = static_cast<String*> (pMapEnum->GetValue());
227 pVal.reset(new (std::nothrow) String(*pStr));
228 SysTryReturn(NID_SCL, pVal != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
230 r = pExtendedData->Add(pKey.get(), pVal.get());
231 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
237 return pExtendedData.release();
241 _AccountImpl::SetId(AccountId accountId)
247 _AccountImpl::SetAccountProvider(const AccountProvider& accountProvider)
249 __accountProvider = accountProvider;
253 _AccountImpl::SetUserName(const String& userName)
255 SysTryReturnResult(NID_SCL, !(userName.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. The userName is an empty string.");
257 __userName = userName;
263 _AccountImpl::SetExtendedData(const String& key, const Tizen::Base::String& value)
265 SysTryReturnResult(NID_SCL, !(key.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. The key is an empty string.");
267 std::unique_ptr<String> pValue(new (std::nothrow) String(value));
268 SysTryReturn(NID_SCL, pValue != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
270 if (__pExtendedData->ContainsKey(key))
272 result r = __pExtendedData->SetValue(key, pValue.get());
273 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
279 std::unique_ptr<String> pKey(new (std::nothrow) String(key));
280 SysTryReturn(NID_SCL, pKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
282 result r = __pExtendedData->Add(pKey.get(), pValue.get());
283 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
293 _AccountImpl::GetInstance(const Account& account)
295 return account.__pAccountImpl;
299 _AccountImpl::GetInstance(Account& account)
301 return account.__pAccountImpl;