2 // Open Service Platform
3 // Copyright (c) 2012-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.
17 // @file FNetBt_BluetoothDeviceEvent.cpp
18 // @brief This is the implementation file for the _BluetoothDeviceEvent class.
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"
30 using namespace Tizen::Base;
32 namespace Tizen { namespace Net { namespace Bluetooth
35 _BluetoothDeviceEvent::_BluetoothDeviceEvent(void)
39 _BluetoothDeviceEvent::~_BluetoothDeviceEvent(void)
44 _BluetoothDeviceEvent::Construct(void)
46 return _Event::Initialize();
50 _BluetoothDeviceEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
52 const BluetoothDevice* pDevice = null;
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.");
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.");
61 _BluetoothDeviceEventType eventType = pEventArg->GetEventType();
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());
70 case _BT_DEVICE_EVENT_DEVICE_FOUND:
71 pDevice = pEventArg->GetRemoteDevice();
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.");
78 SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_DEVICE_FOUND)");
79 pEventListener->OnBluetoothRemoteDeviceFoundN(pFoundDevice);
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());
88 case _BT_DEVICE_EVENT_SVCLIST_RECEIVED:
89 pDevice = pEventArg->GetRemoteDevice();
92 SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_SVCLIST_RECEIVED)");
93 pEventListener->OnBluetoothServiceListReceived(*pDevice, pEventArg->GetServiceList(), pEventArg->GetErrorResult());
97 case _BT_DEVICE_EVENT_PAIRED:
98 SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_PAIRED)");
99 pDevice = pEventArg->GetRemoteDevice();
102 pEventListener->OnBluetoothPaired(*pDevice);
106 pEventListener->OnBluetoothPairingFailed(pEventArg->GetErrorResult());
110 case _BT_DEVICE_EVENT_UNPAIRED:
111 pDevice = pEventArg->GetRemoteDevice();
114 SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_UNPAIRED)");
115 pEventListener->OnBluetoothUnpaired(*pDevice);
124 } } } // Tizen::Net::Bluetooth