2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
18 * @file StNfcPresentationModel.cpp
19 * @brief This is the implementation file for NfcPresentationModel class.
23 #include "StNfcPresentationModel.h"
25 using namespace Tizen::App;
26 using namespace Tizen::App::Package;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Net::Nfc;
31 NfcPresentationModel* NfcPresentationModel::__pNfcPresentationModelInstance = null;
33 NfcPresentationModel::NfcPresentationModel(void)
35 , __pINfcPresentationModelEventListener(null)
39 NfcPresentationModel::~NfcPresentationModel(void)
41 if (__pNfcManager != null)
49 NfcPresentationModel::ActivateNfc(void)
51 if (IsNfcActivated() == true)
56 return __pNfcManager->Activate();
60 NfcPresentationModel::DeactivateNfc(void)
62 if (IsNfcActivated() == false)
67 return __pNfcManager->Deactivate();
71 NfcPresentationModel::IsNfcActivated(void)
73 return __pNfcManager->IsActivated();
77 NfcPresentationModel::OnNfcActivated(result r)
79 FireNfcEvnet(NFC_PRESENTATION_MODEL_EVENT_ACTIVATED, r);
83 NfcPresentationModel::OnNfcDeactivated(result r)
85 FireNfcEvnet(NFC_PRESENTATION_MODEL_EVENT_DEACTIVATED, r);
89 NfcPresentationModel::SetNfcEventListener(const INfcPresentationModelEventListener* pNfcEventListener)
91 __pINfcPresentationModelEventListener = pNfcEventListener;
95 NfcPresentationModel::GetInstance(void)
98 if (__pNfcPresentationModelInstance == null)
100 r = CreateInstance();
103 return __pNfcPresentationModelInstance;
107 NfcPresentationModel::Construct(void)
109 __pNfcManager = new (std::nothrow) NfcManager();
110 result r = __pNfcManager->Construct(*this);
112 // AppAssertf(r == E_SUCCESS, "Failed to construct NfcManager (%s)", GetErrorMessage(r));
116 AppLogDebug("Construct failed(%s)", GetErrorMessage(r));
117 delete __pNfcManager;
118 __pNfcManager = null;
126 NfcPresentationModel::CreateInstance(void)
128 __pNfcPresentationModelInstance = new (std::nothrow) NfcPresentationModel();
129 result r = __pNfcPresentationModelInstance->Construct();
132 delete __pNfcPresentationModelInstance;
133 __pNfcPresentationModelInstance = null;
137 std::atexit(DestroyInstance);
142 NfcPresentationModel::DestroyInstance(void)
144 if (__pNfcPresentationModelInstance != null)
146 delete __pNfcPresentationModelInstance;
147 __pNfcPresentationModelInstance = null;
152 NfcPresentationModel::FireNfcEvnet(NfcPresentationModelEvent nfcEvent, result r)
154 if (__pINfcPresentationModelEventListener == null)
156 AppLogDebug("__pINfcPresentationModelEventListener is null");
160 (const_cast <INfcPresentationModelEventListener*>(__pINfcPresentationModelEventListener))->OnNfcPresentationModelEventCompleted(nfcEvent, r);
165 NfcPredefinedItemPresentationModel* NfcPredefinedItemPresentationModel::__pNfcPredefinedItemPresentationModelInstance = null;
167 NfcPredefinedItemPresentationModel::NfcPredefinedItemPresentationModel(void)
168 : __pNdefPushManager(null)
169 , __pReservedPushCandidatesMap(null)
170 , __pReservedPushCandidatesAppIdList(null)
171 , __pReservedPushCandidatesDescList(null)
175 NfcPredefinedItemPresentationModel::~NfcPredefinedItemPresentationModel(void)
177 delete __pNdefPushManager;
178 delete __pReservedPushCandidatesMap;
179 delete __pReservedPushCandidatesAppIdList;
180 delete __pReservedPushCandidatesDescList;
184 NfcPredefinedItemPresentationModel::InitReservedPushCandidatesList(void)
186 if (__pNdefPushManager == null)
188 AppLogDebug("NdefPushManager is null");
192 delete __pReservedPushCandidatesMap;
193 __pReservedPushCandidatesMap = __pNdefPushManager->GetReservedPushCandidatesN();
195 if(__pReservedPushCandidatesMap == null)
197 AppLogDebug("__pReservedPushCandidatesMap is null");
201 delete __pReservedPushCandidatesAppIdList;
202 __pReservedPushCandidatesAppIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
203 __pReservedPushCandidatesAppIdList->Construct();
205 delete __pReservedPushCandidatesDescList;
206 __pReservedPushCandidatesDescList = new (std::nothrow) ArrayList(SingleObjectDeleter);
207 __pReservedPushCandidatesDescList->Construct();
209 PackageManager* pPackageManager = PackageManager::GetInstance();
210 IMapEnumerator* pEnum = null;
211 pEnum = __pReservedPushCandidatesMap->GetMapEnumeratorN();
213 while (pEnum->MoveNext() == E_SUCCESS)
215 PackageInfo* pPackageInfo = pPackageManager->GetPackageInfoN(*static_cast<AppId*>(pEnum->GetKey()));
218 __pReservedPushCandidatesAppIdList->Add(new (std::nothrow) String(pPackageInfo->GetDisplayName()));
220 __pReservedPushCandidatesDescList->Add(new (std::nothrow) String(*static_cast<String*>(pEnum->GetValue())));
228 NfcPredefinedItemPresentationModel::GetSelectNfcReservedPushCandidatesAppIdIndex(void)
230 PackageId pPackageId = __pNdefPushManager->GetPickedReservedPushMessage();
231 ArrayList* pKeyList = static_cast<ArrayList*>(__pReservedPushCandidatesMap->GetKeysN());
233 for (checkIndex = 0; checkIndex < pKeyList->GetCount(); checkIndex++)
235 String* pKeyId = static_cast<String*>(pKeyList->GetAt(checkIndex));
236 if (pKeyId->Equals(pPackageId, false) == true)
245 NfcPredefinedItemPresentationModel::SetSelectNfcReservedPushCandidatesAppIdIndex(int itemIndex)
247 result r = E_FAILURE;
248 ArrayList* pKeyList = static_cast<ArrayList*>(__pReservedPushCandidatesMap->GetKeysN());
249 PackageId* pPackageId = static_cast<PackageId*>(pKeyList->GetAt(itemIndex));
250 r = __pNdefPushManager->PickReservedPushMessage(*pPackageId);
255 NfcPredefinedItemPresentationModel::IsNfcReservedPushActivated(void)
257 if (__pNdefPushManager == null)
259 AppLogDebug("__pNdefPushManager is null");
262 return __pNdefPushManager->IsReservedPushActivated();
266 NfcPredefinedItemPresentationModel::NfcReservedPushActivated(void)
268 if (__pNdefPushManager == null)
270 AppLogDebug("__pNdefPushManager is null");
273 return __pNdefPushManager->ActivateReservedPush();
277 NfcPredefinedItemPresentationModel::NfcReservedPushDeactivated(void)
279 if (__pNdefPushManager == null)
281 AppLogDebug("__pNdefPushManager is null");
284 return __pNdefPushManager->DeactivateReservedPush();
288 NfcPredefinedItemPresentationModel::GetAllListReservedPushCandidatesAppIdList(void)
290 return __pReservedPushCandidatesAppIdList;
294 NfcPredefinedItemPresentationModel::GetAllListReservedPushCandidatesDescList(void)
296 return __pReservedPushCandidatesDescList;
300 NfcPredefinedItemPresentationModel::OnNdefPushMessageSent(result r)
304 NfcPredefinedItemPresentationModel*
305 NfcPredefinedItemPresentationModel::GetInstance(void)
307 if (__pNfcPredefinedItemPresentationModelInstance == null)
312 return __pNfcPredefinedItemPresentationModelInstance;
316 NfcPredefinedItemPresentationModel::Construct(void)
318 result r = E_SUCCESS;
319 __pNdefPushManager = new (std::nothrow) NdefPushManager();
321 AppAssertf(__pNdefPushManager, "Failed to create NdefPushManager");
323 r = __pNdefPushManager->SetNdefPushManagerListener(this);
329 NfcPredefinedItemPresentationModel::CreateInstance(void)
331 __pNfcPredefinedItemPresentationModelInstance = new (std::nothrow) NfcPredefinedItemPresentationModel();
332 result r = __pNfcPredefinedItemPresentationModelInstance->Construct();
335 delete __pNfcPredefinedItemPresentationModelInstance;
336 __pNfcPredefinedItemPresentationModelInstance = null;
340 std::atexit(DestroyInstance);
344 NfcPredefinedItemPresentationModel::DestroyInstance(void)
346 if (__pNfcPredefinedItemPresentationModelInstance != null)
348 delete __pNfcPredefinedItemPresentationModelInstance;
349 __pNfcPredefinedItemPresentationModelInstance = null;