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 FNetBtBluetoothSppAcceptor.cpp
18 // @brief This is the implementation file for the BluetoothSppAcceptor class.
21 #include <FNetBtBluetoothSppAcceptor.h>
22 #include <FNetBtIBluetoothSppAcceptorEventListener.h>
23 #include <FBaseByteBuffer.h>
24 #include <FBaseUuId.h>
25 #include <FBaseSysLog.h>
26 #include <FSec_AccessController.h>
27 #include <FSys_SystemInfoImpl.h>
28 #include "FNetBt_BluetoothSppAcceptorImpl.h"
30 using namespace Tizen::Security;
32 namespace Tizen { namespace Net { namespace Bluetooth
35 BluetoothSppAcceptor::BluetoothSppAcceptor(void)
40 BluetoothSppAcceptor::~BluetoothSppAcceptor(void)
46 BluetoothSppAcceptor::Construct(IBluetoothSppAcceptorEventListener& listener)
49 bool isBtSupported = false;
51 Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
52 SysTryReturnResult(NID_NET_BT, isBtSupported == true, E_UNSUPPORTED_OPERATION, "Bluetooth is not supported.");
54 SysAssertf(__pImpl == null,
55 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57 __pImpl = new (std::nothrow) _BluetoothSppAcceptorImpl;
58 SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a _BluetoothSppAcceptorImpl instance failed.");
60 r = __pImpl->Construct(listener);
72 BluetoothSppAcceptor::AcceptConnection(void)
77 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
78 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
81 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
83 return __pImpl->AcceptConnection();
87 BluetoothSppAcceptor::RejectConnection()
92 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
93 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
96 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
98 return __pImpl->RejectConnection();
102 BluetoothSppAcceptor::StartService(void)
104 // Actually, E_INVALID_ARG never occur because the fixed SPP UUID is used.
105 return StartService(Tizen::Base::UuId(BT_SVC_UUID_SPP));
109 BluetoothSppAcceptor::StartService(const Tizen::Base::UuId& serviceUuid)
111 result r = E_SUCCESS;
114 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
115 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
118 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
120 return __pImpl->StartService(serviceUuid);
124 BluetoothSppAcceptor::StopService(void)
126 result r = E_SUCCESS;
129 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
130 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
133 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
135 return __pImpl->StopService();
139 BluetoothSppAcceptor::SendData(const Tizen::Base::ByteBuffer& buffer)
141 result r = E_SUCCESS;
144 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
145 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
148 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
150 return __pImpl->SendData(buffer);
154 BluetoothSppAcceptor::Disconnect(void)
156 result r = E_SUCCESS;
159 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
160 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
163 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
165 return __pImpl->Disconnect();
168 } } } // Tizen::Net::Bluetooth