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