update the header for Doxygen
[platform/framework/native/bluetooth.git] / src / FNetBt_BluetoothDeviceEvent.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-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 // @file    FNetBt_BluetoothDeviceEvent.cpp
18 // @brief   This is the implementation file for the _BluetoothDeviceEvent class.
19 //
20
21 #include <FBaseRtIEventListener.h>
22 #include <FBaseSysLog.h>
23 #include <FBaseRtIEventArg.h>
24 #include <FNetBtBluetoothDevice.h>
25 #include "FNetBt_BluetoothDeviceEvent.h"
26 #include "FNetBt_BluetoothDeviceEventArg.h"
27 #include "FNetBtIBluetoothDeviceEventListener.h"
28
29
30 using namespace Tizen::Base;
31
32 namespace Tizen { namespace Net { namespace Bluetooth
33 {
34
35 _BluetoothDeviceEvent::_BluetoothDeviceEvent(void)
36 {
37 }
38
39 _BluetoothDeviceEvent::~_BluetoothDeviceEvent(void)
40 {
41 }
42
43 result
44 _BluetoothDeviceEvent::Construct(void)
45 {
46         return _Event::Initialize();
47 }
48
49 void
50 _BluetoothDeviceEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
51 {
52         const BluetoothDevice* pDevice = null;
53
54         IBluetoothDeviceEventListener* pEventListener = dynamic_cast <IBluetoothDeviceEventListener*>(&listener);
55         SysTryReturnVoidResult(NID_NET_BT, pEventListener != null, E_INVALID_ARG,
56                                 "[E_INVALID_ARG] The listener argument is invalid.");
57
58         const _BluetoothDeviceEventArg* pEventArg = dynamic_cast <const _BluetoothDeviceEventArg*>(&arg);
59         SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
60
61         _BluetoothDeviceEventType eventType = pEventArg->GetEventType();
62
63         switch (eventType)
64         {
65         case _BT_DEVICE_EVENT_DISCOVERY_STARTED:
66                 SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_DEVDISCOVERY_STARTED)");
67                 pEventListener->OnBluetoothDiscoveryStarted(pEventArg->GetErrorResult());
68                 break;
69
70         case _BT_DEVICE_EVENT_DEVICE_FOUND:
71                 pDevice = pEventArg->GetRemoteDevice();
72                 if (pDevice != null)
73                 {
74                         BluetoothDevice* pFoundDevice = new (std::nothrow) BluetoothDevice(*pDevice);
75                         SysTryReturnVoidResult(NID_NET_BT, pFoundDevice != null, E_SYSTEM,
76                                         "[E_SYSTEM] Failed to copy the BluetoothDevice instance.");
77
78                         SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_DEVICE_FOUND)");
79                         pEventListener->OnBluetoothRemoteDeviceFoundN(pFoundDevice);
80                 }
81                 break;
82
83         case _BT_DEVICE_EVENT_DISCOVERY_DONE:
84                 SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_DEVDISCOVERY_DONE)");
85                 pEventListener->OnBluetoothDiscoveryDone(pEventArg->IsDiscoveryCompleted());
86                 break;
87
88         case _BT_DEVICE_EVENT_SVCLIST_RECEIVED:
89                 pDevice = pEventArg->GetRemoteDevice();
90                 if (pDevice != null)
91                 {
92                         SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_SVCLIST_RECEIVED)");
93                         pEventListener->OnBluetoothServiceListReceived(*pDevice, pEventArg->GetServiceList(), pEventArg->GetErrorResult());
94                 }
95                 break;
96
97         case _BT_DEVICE_EVENT_PAIRED:
98                 SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_PAIRED)");
99                 pDevice = pEventArg->GetRemoteDevice();
100                 if (pDevice != null)
101                 {
102                         pEventListener->OnBluetoothPaired(*pDevice);
103                 }
104                 else
105                 {
106                         pEventListener->OnBluetoothPairingFailed(pEventArg->GetErrorResult());
107                 }
108                 break;
109
110         case _BT_DEVICE_EVENT_UNPAIRED:
111                 pDevice = pEventArg->GetRemoteDevice();
112                 if (pDevice != null)
113                 {
114                         SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_UNPAIRED)");
115                         pEventListener->OnBluetoothUnpaired(*pDevice);
116                 }
117                 break;
118
119         default:
120                 break;
121         }
122 }
123
124 } } } // Tizen::Net::Bluetooth