2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FScl_AccountImpl.cpp
19 * @brief This is the implementation for _AccountImpl class.
21 * This file contains definitions of @e _AccountImpl class.
25 #include <FBaseResult.h>
26 #include <FBaseString.h>
27 #include <FBaseSysLog.h>
28 #include <FSclAccount.h>
29 #include "FScl_AccountImpl.h"
30 #include "FScl_AccountProviderImpl.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
37 namespace Tizen { namespace Social
40 _AccountImpl::_AccountImpl(const Tizen::Base::String& userName)
41 : __id(INVALID_RECORD_ID)
43 std::unique_ptr<HashMap, AllElementsDeleter> pExtendedData(new (std::nothrow) HashMap());
44 SysTryReturnVoidResult(NID_SCL, pExtendedData != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
46 result r = pExtendedData->Construct();
47 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r));
49 __pExtendedData = std::move(pExtendedData);
50 __userName = userName;
53 _AccountImpl::_AccountImpl(const _AccountImpl& rhs)
55 std::unique_ptr<HashMap, AllElementsDeleter> pExtendedData(new (std::nothrow) HashMap());
56 SysTryReturnVoidResult(NID_SCL, pExtendedData != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
58 result r = pExtendedData->Construct();
59 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r));
61 std::unique_ptr<IMapEnumerator> pMapEnum((rhs.__pExtendedData)->GetMapEnumeratorN());
62 SysTryReturnVoidResult(NID_SCL, pMapEnum != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
64 std::unique_ptr<String> pKey(null);
65 std::unique_ptr<String> pVal(null);
68 while (pMapEnum->MoveNext() == E_SUCCESS)
70 pStr = static_cast<String*> (pMapEnum->GetKey());
71 pKey.reset(new (std::nothrow) String(*pStr));
72 SysTryReturnVoidResult(NID_SCL, pKey != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
74 pStr = static_cast<String*> (pMapEnum->GetValue());
75 pVal.reset(new (std::nothrow) String(*pStr));
76 SysTryReturnVoidResult(NID_SCL, pVal != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
78 r = pExtendedData->Add(pKey.get(), pVal.get());
79 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
85 __pExtendedData = std::move(pExtendedData);
88 __userName = rhs.__userName;
89 __accountProvider = rhs.__accountProvider;
92 _AccountImpl::~_AccountImpl(void)
98 _AccountImpl::operator =(const _AccountImpl& rhs)
105 std::unique_ptr<HashMap, AllElementsDeleter> pExtendedData(new (std::nothrow) HashMap());
106 SysTryReturn(NID_SCL, pExtendedData != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
108 result r = pExtendedData->Construct();
109 SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r));
111 result prevResult = GetLastResult();
113 std::unique_ptr<IMapEnumerator> pMapEnum((rhs.__pExtendedData)->GetMapEnumeratorN());
114 SysTryReturn(NID_SCL, pMapEnum != null, *this, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
116 SetLastResult(prevResult);
118 std::unique_ptr<String> pKey(null);
119 std::unique_ptr<String> pVal(null);
122 while (pMapEnum->MoveNext() == E_SUCCESS)
124 pStr = static_cast<String*> (pMapEnum->GetKey());
125 pKey.reset(new (std::nothrow) String(*pStr));
126 SysTryReturn(NID_SCL, pKey != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
128 pStr = static_cast<String*> (pMapEnum->GetValue());
129 pVal.reset(new (std::nothrow) String(*pStr));
130 SysTryReturn(NID_SCL, pVal != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
132 r = pExtendedData->Add(pKey.get(), pVal.get());
133 SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Propagating.", GetErrorMessage(r));
139 __pExtendedData = std::move(pExtendedData);
142 __userName = rhs.__userName;
143 __accountProvider = rhs.__accountProvider;
149 _AccountImpl::Equals(const Object& rhs) const
151 const _AccountImpl* pAccountImpl = dynamic_cast<const _AccountImpl*> (&rhs);
152 if (pAccountImpl == null)
157 if (__id != pAccountImpl->__id
158 || __userName != pAccountImpl->__userName)
163 if (*(_AccountProviderImpl::GetInstance(__accountProvider)) != *(_AccountProviderImpl::GetInstance(pAccountImpl->__accountProvider)))
168 if (!(__pExtendedData->Equals(*(pAccountImpl->__pExtendedData))))
177 _AccountImpl::GetHashCode(void) const
179 int hashCode = 0xffffffff & __id;
180 hashCode += hashCode;
186 _AccountImpl::GetId(void) const
192 _AccountImpl::GetAccountProvider(void) const
194 return __accountProvider;
198 _AccountImpl::GetUserName(void) const
204 _AccountImpl::GetExtendedDataN(void) const
208 std::unique_ptr<HashMap, AllElementsDeleter> pExtendedData(new (std::nothrow) HashMap());
209 SysTryReturn(NID_SCL, pExtendedData != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
211 result r = pExtendedData->Construct();
212 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r));
214 std::unique_ptr<IMapEnumerator> pMapEnum(__pExtendedData->GetMapEnumeratorN());
215 SysTryReturn(NID_SCL, pMapEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
217 std::unique_ptr<String> pKey(null);
218 std::unique_ptr<String> pVal(null);
221 while (pMapEnum->MoveNext() == E_SUCCESS)
223 pStr = static_cast<String*> (pMapEnum->GetKey());
224 pKey.reset(new (std::nothrow) String(*pStr));
225 SysTryReturn(NID_SCL, pKey != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
227 pStr = static_cast<String*> (pMapEnum->GetValue());
228 pVal.reset(new (std::nothrow) String(*pStr));
229 SysTryReturn(NID_SCL, pVal != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
231 r = pExtendedData->Add(pKey.get(), pVal.get());
232 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
238 return pExtendedData.release();
242 _AccountImpl::SetId(AccountId accountId)
248 _AccountImpl::SetAccountProvider(const AccountProvider& accountProvider)
250 __accountProvider = accountProvider;
254 _AccountImpl::SetUserName(const String& userName)
256 SysTryReturnResult(NID_SCL, !(userName.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. The userName is an empty string.");
258 __userName = userName;
264 _AccountImpl::SetExtendedData(const String& key, const Tizen::Base::String& value)
266 SysTryReturnResult(NID_SCL, !(key.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. The key is an empty string.");
268 std::unique_ptr<String> pValue(new (std::nothrow) String(value));
269 SysTryReturn(NID_SCL, pValue != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
271 if (__pExtendedData->ContainsKey(key))
273 result r = __pExtendedData->SetValue(key, pValue.get());
274 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
280 std::unique_ptr<String> pKey(new (std::nothrow) String(key));
281 SysTryReturn(NID_SCL, pKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
283 result r = __pExtendedData->Add(pKey.get(), pValue.get());
284 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
294 _AccountImpl::GetInstance(const Account& account)
296 return account.__pAccountImpl;
300 _AccountImpl::GetInstance(Account& account)
302 return account.__pAccountImpl;