Applied latest source code
[apps/native/preloaded/Settings.git] / src / StBluetoothPresentationModel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                StBluetoothPresentationModel.cpp
19  * @brief               This is the implementation file for Bluetooth Presentation Model class.
20  */
21
22 #include <cstdlib>
23 #include <FApp.h>
24 #include "StBluetoothPresentationModel.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Net::Bluetooth;
30
31 static const int BLUETOOTH_DISCOVERABLE_TIME_2_MINUTES = 120;
32 static const int BLUETOOTH_DISCOVERABLE_TIME_5_MINUTES = 300;
33 static const int BLUETOOTH_DISCOVERABLE_TIME_1_HOUR = 3600;
34
35 BluetoothPresentationModel* BluetoothPresentationModel::__pBluetoothPresentationModelInstance = null;
36
37 BluetoothPresentationModel::BluetoothPresentationModel(void)
38         : __pBluetoothMgr(null)
39         , __pPairedRemoteDeviceList(null)
40         , __pFoundRemoteDeviceList(null)
41         , __pBluetoothPresentationModelEventListener(null)
42         , __bluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_BASE)
43 {
44 }
45
46 BluetoothPresentationModel::~BluetoothPresentationModel(void)
47 {
48         delete __pBluetoothMgr;
49
50         __pBluetoothPresentationModelEventListener = null;
51         RemoveFoundRemoteDeviceList();
52         RemovePairedRemoteDeviceList();
53 }
54
55 BluetoothPresentationModel*
56 BluetoothPresentationModel::GetInstance(void)
57 {
58         if (__pBluetoothPresentationModelInstance == null)
59         {
60                 CreateInstance();
61         }
62
63         return __pBluetoothPresentationModelInstance;
64 }
65
66 result
67 BluetoothPresentationModel::Construct(void)
68 {
69         __pBluetoothMgr = new (std::nothrow) BluetoothManager();
70         result r = __pBluetoothMgr->Construct(*this);
71         if (IsFailed(r))
72         {
73                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
74                 delete __pBluetoothMgr;
75                 __pBluetoothMgr = null;
76                 return r;
77         }
78
79         __pBluetoothMgr->SetBluetoothDeviceListener(this);
80
81         if (IsBluetoothActivated() == true)
82         {
83                 UpdatePairedRemoteDeviceList();
84         }
85
86         return r;
87 }
88
89 void
90 BluetoothPresentationModel::CreateInstance(void)
91 {
92         __pBluetoothPresentationModelInstance = new (std::nothrow) BluetoothPresentationModel();
93         result r = __pBluetoothPresentationModelInstance->Construct();
94         if (IsFailed(r))
95         {
96                 delete __pBluetoothPresentationModelInstance;
97                 __pBluetoothPresentationModelInstance = null;
98                 return;
99         }
100
101         std::atexit(DestroyInstance);
102 }
103
104 void
105 BluetoothPresentationModel::DestroyInstance(void)
106 {
107         delete __pBluetoothPresentationModelInstance;
108         __pBluetoothPresentationModelInstance = null;
109 }
110
111 void
112 BluetoothPresentationModel::UpdatePairedRemoteDeviceList(void)
113 {
114         RemovePairedRemoteDeviceList();
115
116         __pPairedRemoteDeviceList = __pBluetoothMgr->GetPairedDeviceListN();
117         if (__pPairedRemoteDeviceList == null)
118         {
119                 AppLogDebug("__pPairedRemoteDeviceList is null");
120         }
121 }
122
123 void
124 BluetoothPresentationModel::RemovePairedRemoteDeviceList(void)
125 {
126         if (__pPairedRemoteDeviceList == null)
127         {
128                 AppLogDebug("__pPairedRemoteDeviceList is null");
129                 return;
130         }
131
132         __pPairedRemoteDeviceList->RemoveAll();
133         delete __pPairedRemoteDeviceList;
134         __pPairedRemoteDeviceList = null;
135 }
136
137 result
138 BluetoothPresentationModel::InitFoundRemoteDeviceList(void)
139 {
140         __pFoundRemoteDeviceList = new (std::nothrow) ArrayList(SingleObjectDeleter);
141
142         result r = __pFoundRemoteDeviceList->Construct();
143         if (IsFailed(r))
144         {
145                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
146                 delete __pFoundRemoteDeviceList;
147                 __pFoundRemoteDeviceList = null;
148         }
149
150         return r;
151 }
152
153 void
154 BluetoothPresentationModel::RemoveFoundRemoteDeviceList(void)
155 {
156         if (__pFoundRemoteDeviceList == null)
157         {
158                 AppLogDebug("__pFoundRemoteDeviceList is null");
159                 return;
160         }
161
162         delete __pFoundRemoteDeviceList;
163         __pFoundRemoteDeviceList = null;
164 }
165
166 int
167 BluetoothPresentationModel::GetFoundRemoteDeviceListCount(void)
168 {
169         int foundDeviceListCount = 0;
170
171         if (IsBluetoothActivated() == false || __pFoundRemoteDeviceList == null)
172         {
173                 if (__pFoundRemoteDeviceList == null)
174                 {
175                         AppLogDebug("__pFoundRemoteDeviceList is null");
176                 }
177                 else
178                 {
179                         AppLogDebug("Bluetooth is Deactivated");
180                 }
181                 return foundDeviceListCount;
182         }
183
184         foundDeviceListCount = __pFoundRemoteDeviceList->GetCount();
185         return foundDeviceListCount;
186 }
187
188 result
189 BluetoothPresentationModel::SetBluetoothVisibleMode(BluetoothVisibleMode mode)
190 {
191         int discoveryTime = 0;
192         BluetoothDiscoverableMode discoverablemode = BT_DISC_MODE_NOT_DISCOVERABLE;
193
194         switch (mode)
195         {
196         case BLUETOOTH_VISIBLE_MDOE_2_MINUTES:
197                 {
198                         discoveryTime = BLUETOOTH_DISCOVERABLE_TIME_2_MINUTES;
199                         discoverablemode = BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE;
200                 }
201                 break;
202
203         case BLUETOOTH_VISIBLE_MODE_5_MINUTES:
204                 {
205                         discoveryTime = BLUETOOTH_DISCOVERABLE_TIME_5_MINUTES;
206                         discoverablemode = BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE;
207                 }
208                 break;
209
210         case BLUETOOTH_VISIBLE_MODE_1_HOUR:
211                 {
212                         discoveryTime = BLUETOOTH_DISCOVERABLE_TIME_1_HOUR;
213                         discoverablemode = BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE;
214                 }
215                 break;
216
217         case BLUETOOTH_VISIBLE_MODE_ALWAYS_ON:
218                 {
219                         discoverablemode = BT_DISC_MODE_DISCOVERABLE;
220                 }
221                 break;
222
223         default:
224                 break;
225         }
226
227         return __pBluetoothMgr->SetDiscoverableMode(discoverablemode, discoveryTime);
228 }
229
230 BluetoothVisibleMode
231 BluetoothPresentationModel::GetBluetoothVisibleMode(void)
232 {
233         BluetoothVisibleMode visibleMode = BLUETOOTH_VISIBLE_MODE_BASE;
234
235         BluetoothDiscoverableMode discoverableMode = __pBluetoothMgr->GetDiscoverableMode();
236         switch (discoverableMode)
237         {
238         case BT_DISC_MODE_NOT_DISCOVERABLE:
239                 {
240                         visibleMode = BLUETOOTH_VISIBLE_MODE_OFF;
241                 }
242                 break;
243
244         case BT_DISC_MODE_DISCOVERABLE:
245                 {
246                         visibleMode = BLUETOOTH_VISIBLE_MODE_ALWAYS_ON;
247                 }
248                 break;
249
250         default:
251                 break;
252         }
253
254         return visibleMode;
255 }
256
257 Tizen::Base::String
258 BluetoothPresentationModel::GetBluetoothRemainingVisibleTime(void)
259 {
260         String remainingTime;
261         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
262
263         BluetoothDiscoverableMode mode = __pBluetoothMgr->GetDiscoverableMode();
264         switch (mode)
265         {
266         case BT_DISC_MODE_NOT_DISCOVERABLE:
267                 {
268                         pAppResource->GetString(L"IDS_ST_BODY_OFF", remainingTime);
269                 }
270                 break;
271
272         case BT_DISC_MODE_DISCOVERABLE:
273                 {
274                         pAppResource->GetString(L"IDS_ST_BODY_ALWAYS_ON", remainingTime);
275                 }
276                 break;
277
278         case BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE:
279                 {
280                         int remainingSec = __pBluetoothMgr->GetRemainingTimeAsDiscoverable();
281                         TimeSpan timeSpan(0, 0, remainingSec);
282
283                         remainingTime.Append(Integer::ToString(timeSpan.GetMinutes()));
284                         remainingTime.Append(L":");
285                         remainingTime.Append(Integer::ToString(timeSpan.GetSeconds()));
286                 }
287                 break;
288
289         default:
290                 break;
291         }
292
293         return remainingTime;
294 }
295
296 void
297 BluetoothPresentationModel::SetEventListener(const IBluetoothPresentationModelEventListener* pEventListener)
298 {
299         __pBluetoothPresentationModelEventListener = pEventListener;
300 }
301
302 result
303 BluetoothPresentationModel::ActivateBluetooth(void)
304 {
305         result r = __pBluetoothMgr->Activate();
306         if (r == E_SUCCESS)
307         {
308                 SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_ACTIVATING);
309         }
310
311         return r;
312 }
313
314 result
315 BluetoothPresentationModel::DeactivateBluetooth(void)
316 {
317         if (__pBluetoothMgr->IsActivated() == false)
318         {
319                 AppLogDebug("Already is Deactivated");
320                 return E_INVALID_OPERATION;
321         }
322
323         result r = __pBluetoothMgr->Deactivate();
324         if (!IsFailed(r))
325         {
326                 SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_DEACTIVATING);
327         }
328
329         return r;
330 }
331
332 result
333 BluetoothPresentationModel::StartBluetoothDiscovery(void)
334 {
335         result r = __pBluetoothMgr->StartDiscovery();
336         if (!IsFailed(r))
337         {
338                 SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_STARTING);
339         }
340
341         return r;
342 }
343
344 result
345 BluetoothPresentationModel::CancelBluetoothDiscovery(void)
346 {
347         if (__pBluetoothMgr->IsDiscoveryInProgress() == false)
348         {
349                 AppLogDebug("__pBluetoothMgr is not perform to Discovery");
350                 return E_FAILURE;
351         }
352
353         result r = __pBluetoothMgr->CancelDiscovery();
354         if (!IsFailed(r))
355         {
356                 if (__bluetoothEventInProgress != BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_EXIT)
357                 {
358                         SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_CANCEL_DISCOVERYING);
359                 }
360         }
361
362         return r;
363 }
364
365 result
366 BluetoothPresentationModel::PairToFoundBluetoothDeviceAt(int index)
367 {
368         if (__pFoundRemoteDeviceList == null)
369         {
370                 AppLogDebug("__pFoundRemoteDeviceList is null");
371                 return E_FAILURE;
372         }
373
374         BluetoothDevice* pRemoteDevice = static_cast<BluetoothDevice*>(__pFoundRemoteDeviceList->GetAt(index));
375         if (pRemoteDevice == null)
376         {
377                 AppLogDebug("GetAt fail[%d]", index);
378                 return E_FAILURE;
379         }
380
381         result r = __pBluetoothMgr->Pair(*pRemoteDevice);
382         if (r == E_SUCCESS)
383         {
384                 SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIRING);
385         }
386
387         return r;
388 }
389
390 result
391 BluetoothPresentationModel::UnpairToPairedBluetoothDeviceAt(int index)
392 {
393         if (__pPairedRemoteDeviceList == null)
394         {
395                 AppLogDebug("__pPairedRemoteDeviceList is null");
396                 return E_FAILURE;
397         }
398
399         BluetoothDevice* pRemoteDevice = static_cast<BluetoothDevice*>(__pPairedRemoteDeviceList->GetAt(index));
400         if (pRemoteDevice == null)
401         {
402                 AppLogDebug("GetAt fail[%d]", index);
403                 return E_FAILURE;
404         }
405
406         result r = __pBluetoothMgr->Unpair(*pRemoteDevice);
407         if (r == E_SUCCESS)
408         {
409                 SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_UNPAIRING);
410         }
411
412         return r;
413 }
414
415 result
416 BluetoothPresentationModel::SetBluetoothDiscoverableMode(Tizen::Net::Bluetooth::BluetoothDiscoverableMode discoverableMode, int seconds)
417 {
418         result r = __pBluetoothMgr->SetDiscoverableMode(discoverableMode, seconds);
419         if (!IsFailed(r))
420         {
421                 SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_VISIBLE_MODE_CHANGING);
422         }
423
424         return r;
425 }
426
427 result
428 BluetoothPresentationModel::CancelBluetoothPair(void)
429 {
430         if (GetBluetoothEventInProgress() != BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIRING)
431         {
432                 AppLogDebug("__pBluetoothMgr is not pairing");
433                 return E_FAILURE;
434         }
435
436         result r = __pBluetoothMgr->CancelPair();
437         if (!IsFailed(r))
438         {
439                 SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIR_CANCELLING);
440         }
441
442         return r;
443 }
444
445 Tizen::Base::String
446 BluetoothPresentationModel::GetBluetoothLocalMacAddress(void)
447 {
448         String localMacAddress;
449
450         localMacAddress = __pBluetoothMgr->GetLocalDeviceAddress();
451         return localMacAddress;
452 }
453
454 bool
455 BluetoothPresentationModel::IsBluetoothActivated(void)
456 {
457         return __pBluetoothMgr->IsActivated();
458 }
459
460 bool
461 BluetoothPresentationModel::IsBluetoothDiscoveryDone(void)
462 {
463         return __pBluetoothMgr->IsDiscoveryInProgress();
464 }
465
466 Tizen::Base::String
467 BluetoothPresentationModel::GetBluetoothLocalDeviceName(void)
468 {
469         return __pBluetoothMgr->GetLocalDeviceName();
470 }
471
472 Tizen::Base::String
473 BluetoothPresentationModel::GetFoundDeviceListAt(int index)
474 {
475         String foundDevieName;
476         if ((IsBluetoothActivated() == false)
477                 || (__pFoundRemoteDeviceList == null))
478         {
479                 if (__pFoundRemoteDeviceList == null)
480                 {
481                         AppLogDebug("__pFoundRemoteDeviceList is null");
482                 }
483                 else
484                 {
485                         AppLogDebug("Bluetooth is Deactivated");
486                 }
487                 return foundDevieName;
488         }
489
490         BluetoothDevice* pRemoteDevice = static_cast<BluetoothDevice*>(__pFoundRemoteDeviceList->GetAt(index));
491         if (pRemoteDevice == null)
492         {
493                 AppLogDebug("GetAt fail[%d]", index);
494                 return foundDevieName;
495         }
496
497         return pRemoteDevice->GetName();
498 }
499
500 Tizen::Net::Bluetooth::BluetoothMajorDeviceClassType
501 BluetoothPresentationModel::GetMajorDeviceClasstypeInFoundDeviceAt(int index)
502 {
503         BluetoothMajorDeviceClassType majorDeviceClassType = BT_COD_MAJ_DEV_CLS_UNCLASSIFIED;
504         if ((IsBluetoothActivated() == false)
505                 || (__pFoundRemoteDeviceList == null))
506         {
507                 if (__pFoundRemoteDeviceList == null)
508                 {
509                         AppLogDebug("__pFoundRemoteDeviceList is null");
510                 }
511                 else
512                 {
513                         AppLogDebug("Bluetooth is Deactivated");
514                 }
515                 SetLastResult(E_FAILURE);
516                 return majorDeviceClassType;
517         }
518
519         BluetoothDevice* pRemoteDevice = static_cast<BluetoothDevice*>(__pFoundRemoteDeviceList->GetAt(index));
520         if (pRemoteDevice == null)
521         {
522                 AppLogDebug("GetAt fail[%d]", index);
523                 SetLastResult(E_FAILURE);
524                 return majorDeviceClassType;
525         }
526
527         return pRemoteDevice->GetMajorDeviceClassType();
528 }
529
530 Tizen::Base::String
531 BluetoothPresentationModel::GetPairedDeviceNameAt(int index)
532 {
533         String pairedDeviceName;
534         if (__pPairedRemoteDeviceList == null)
535         {
536                 AppLogDebug("__pPairedRemoteDeviceList is null");
537                 SetLastResult(E_FAILURE);
538                 return pairedDeviceName;
539         }
540
541         if (IsBluetoothActivated() == false)
542         {
543                 AppLogDebug("Bluetooth is Deactivated");
544                 SetLastResult(E_FAILURE);
545                 return pairedDeviceName;
546         }
547
548         BluetoothDevice* pRemoteDevice = static_cast<BluetoothDevice*>(__pPairedRemoteDeviceList->GetAt(index));
549         if (pRemoteDevice == null)
550         {
551                 AppLogDebug("GetAt fail[%d]", index);
552                 SetLastResult(E_FAILURE);
553                 return pairedDeviceName;
554         }
555
556         return pRemoteDevice->GetName();
557 }
558
559 Tizen::Net::Bluetooth::BluetoothMajorDeviceClassType
560 BluetoothPresentationModel::GetMajorDeviceClassTypeInPairedDeviceAt(int index)
561 {
562         BluetoothMajorDeviceClassType majorDeviceClassType = BT_COD_MAJ_DEV_CLS_UNCLASSIFIED;
563
564         if (IsBluetoothActivated() == false)
565         {
566                 AppLogDebug("Bluetooth is Deactivated");
567                 SetLastResult(E_FAILURE);
568                 return majorDeviceClassType;
569         }
570
571         BluetoothDevice* pRemoteDevice = static_cast<BluetoothDevice*>(__pPairedRemoteDeviceList->GetAt(index));
572         if (pRemoteDevice == null)
573         {
574                 AppLogDebug("GetAt fail[%d]", index);
575                 SetLastResult(E_FAILURE);
576                 return majorDeviceClassType;
577         }
578
579         return pRemoteDevice->GetMajorDeviceClassType();
580 }
581
582 int
583 BluetoothPresentationModel::GetPairedDeviceListCount(void)
584 {
585         int pairedDeviceListCount = 0;
586
587         if (IsBluetoothActivated() == false)
588         {
589                 AppLogDebug("Bluetooth is Deactivated");
590                 SetLastResult(E_FAILURE);
591                 return pairedDeviceListCount;
592         }
593
594         pairedDeviceListCount = __pPairedRemoteDeviceList->GetCount();
595         return pairedDeviceListCount;
596 }
597
598 result
599 BluetoothPresentationModel::FireIBluetoothPresentationModelEventListener(BluetoothPresentationModelEvent bluetoothEvent, result r, Tizen::Net::Bluetooth::BluetoothDevice* pDevice)
600 {
601         if (__pBluetoothPresentationModelEventListener == null)
602         {
603                 AppLogDebug("__pBluetoothPresentationModelEventListener is null");
604                 return E_FAILURE;
605         }
606
607         SetBluetoothEventInProgress(bluetoothEvent);
608         (const_cast <IBluetoothPresentationModelEventListener*>(__pBluetoothPresentationModelEventListener))->OnBluetoothPresentationModelEventCompletedN(bluetoothEvent, r, pDevice);
609
610         return E_SUCCESS;
611 }
612
613 void
614 BluetoothPresentationModel::SetBluetoothEventInProgress(BluetoothPresentationModelEvent lastbluetoothEvent)
615 {
616         __bluetoothEventInProgress = lastbluetoothEvent;
617 }
618
619 BluetoothPresentationModelEvent
620 BluetoothPresentationModel::GetBluetoothEventInProgress(void)
621 {
622         return __bluetoothEventInProgress;
623 }
624
625 void
626 BluetoothPresentationModel::OnBluetoothActivated(result r)
627 {
628         UpdatePairedRemoteDeviceList();
629         InitFoundRemoteDeviceList();
630         FireIBluetoothPresentationModelEventListener(BLUETOOTH_PRESENTATION_MODEL_EVENT_ACTIVATED, r);
631 }
632
633 void
634 BluetoothPresentationModel::OnBluetoothDeactivated(result r)
635 {
636         if (!IsFailed(r))
637         {
638                 RemoveFoundRemoteDeviceList();
639                 RemovePairedRemoteDeviceList();
640         }
641         FireIBluetoothPresentationModelEventListener(BLUETOOTH_PRESENTATION_MODEL_EVENT_DEACTIVATED, r);
642 }
643
644 void
645 BluetoothPresentationModel::OnBluetoothDiscoveryDone(bool isCompleted)
646 {
647         BluetoothPresentationModelEvent bluetoothPresentationModelEvent = BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_CANCELED;
648         if (isCompleted == true)
649         {
650                 bluetoothPresentationModelEvent = BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_DONE;
651         }
652
653         if (__bluetoothEventInProgress != BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_EXIT)
654         {
655                 FireIBluetoothPresentationModelEventListener(bluetoothPresentationModelEvent);
656         }
657 }
658
659 void
660 BluetoothPresentationModel::OnBluetoothDiscoveryStarted(result r)
661 {
662         InitFoundRemoteDeviceList();
663         if (__bluetoothEventInProgress != BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_EXIT)
664         {
665                 FireIBluetoothPresentationModelEventListener(BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_STARTED, r);
666         }
667 }
668
669 void
670 BluetoothPresentationModel::OnBluetoothPairingFailed(result r)
671 {
672         AppLogDebug("OnBluetoothPairingFailed [%s]", GetErrorMessage(r));
673         FireIBluetoothPresentationModelEventListener(BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIRING_FAILED, r);
674 }
675
676 void
677 BluetoothPresentationModel::OnBluetoothPaired(const Tizen::Net::Bluetooth::BluetoothDevice& pairedDevice)
678 {
679         AppLogDebug("OnBluetoothPaired");
680
681         if (__pFoundRemoteDeviceList != null)
682         {
683                 __pFoundRemoteDeviceList->Remove(pairedDevice, true);
684         }
685
686         UpdatePairedRemoteDeviceList();
687         FireIBluetoothPresentationModelEventListener(BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIRED);
688 }
689
690 void
691 BluetoothPresentationModel::OnBluetoothRemoteDeviceFoundN(Tizen::Net::Bluetooth::BluetoothDevice* pFoundDevice)
692 {
693         result r = E_FAILURE;
694         bool isExistDevice = false;
695         if (__pFoundRemoteDeviceList != null)
696         {
697                 if (__pPairedRemoteDeviceList != null)
698                 {
699                         isExistDevice = __pPairedRemoteDeviceList->Contains(*pFoundDevice);
700                 }
701
702                 if (isExistDevice == false)
703                 {
704                         r = __pFoundRemoteDeviceList->Add(*pFoundDevice);
705                         if (IsFailed(r))
706                         {
707                                 delete pFoundDevice;
708                                 AppLogDebug("Add fail[%s]", GetErrorMessage(r));
709                         }
710                 }
711                 else
712                 {
713                         AppLogDebug("Already paired device[%ls]", pFoundDevice->GetName().GetPointer());
714                         delete pFoundDevice;
715                 }
716         }
717
718         FireIBluetoothPresentationModelEventListener(BLUETOOTH_PRESENTATION_MODEL_EVENT_REMOTE_DEVICE_FOUND, r);
719 }
720
721 void
722 BluetoothPresentationModel::OnBluetoothUnpaired(const Tizen::Net::Bluetooth::BluetoothDevice& unpairedDevice)
723 {
724         if (__pFoundRemoteDeviceList == null)
725         {
726                 InitFoundRemoteDeviceList();
727         }
728
729         BluetoothDevice* pDevice = new (std::nothrow) BluetoothDevice(unpairedDevice);
730         if (pDevice != null)
731         {
732                 __pFoundRemoteDeviceList->Add(*pDevice);
733         }
734
735         UpdatePairedRemoteDeviceList();
736         FireIBluetoothPresentationModelEventListener(BLUETOOTH_PRESENTATION_MODEL_EVENT_UNPAIRED);
737 }
738
739 void
740 BluetoothPresentationModel::OnBluetoothDiscoverableModeChanged(Tizen::Net::Bluetooth::BluetoothDiscoverableMode mode)
741 {
742         FireIBluetoothPresentationModelEventListener(BLUETOOTH_PRESENTATION_MODEL_EVENT_VISIBLE_MODE_CHANGED);
743 }