summaryrefslogtreecommitdiff
path: root/src/FNetBtBluetoothSppAcceptor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/FNetBtBluetoothSppAcceptor.cpp')
-rw-r--r--src/FNetBtBluetoothSppAcceptor.cpp168
1 files changed, 168 insertions, 0 deletions
diff --git a/src/FNetBtBluetoothSppAcceptor.cpp b/src/FNetBtBluetoothSppAcceptor.cpp
new file mode 100644
index 0000000..658c6ca
--- /dev/null
+++ b/src/FNetBtBluetoothSppAcceptor.cpp
@@ -0,0 +1,168 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// @file FNetBtBluetoothSppAcceptor.cpp
+// @brief This is the implementation file for the BluetoothSppAcceptor class.
+//
+
+#include <FNetBtBluetoothSppAcceptor.h>
+#include <FNetBtIBluetoothSppAcceptorEventListener.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseUuId.h>
+#include <FBaseSysLog.h>
+#include <FSec_AccessController.h>
+#include <FSys_SystemInfoImpl.h>
+#include "FNetBt_BluetoothSppAcceptorImpl.h"
+
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+BluetoothSppAcceptor::BluetoothSppAcceptor(void)
+ : __pImpl(null)
+{
+}
+
+BluetoothSppAcceptor::~BluetoothSppAcceptor(void)
+{
+ delete __pImpl;
+}
+
+result
+BluetoothSppAcceptor::Construct(IBluetoothSppAcceptorEventListener& listener)
+{
+ result r = E_SUCCESS;
+ bool isBtSupported = false;
+
+ Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
+ SysTryReturnResult(NID_NET_BT, isBtSupported == true, E_UNSUPPORTED_OPERATION, "Bluetooth is not supported.");
+
+ SysAssertf(__pImpl == null,
+ "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
+
+ __pImpl = new (std::nothrow) _BluetoothSppAcceptorImpl;
+ SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a _BluetoothSppAcceptorImpl instance failed.");
+
+ r = __pImpl->Construct(listener);
+
+ if (r != E_SUCCESS)
+ {
+ delete __pImpl;
+ __pImpl = null;
+ }
+
+ return r;
+}
+
+result
+BluetoothSppAcceptor::AcceptConnection(void)
+{
+ result r = E_SUCCESS;
+
+ // Privilege check
+ r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+ SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ // Check Construct
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->AcceptConnection();
+}
+
+result
+BluetoothSppAcceptor::RejectConnection()
+{
+ result r = E_SUCCESS;
+
+ // Privilege check
+ r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+ SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ // Check Construct
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->RejectConnection();
+}
+
+result
+BluetoothSppAcceptor::StartService(void)
+{
+ // Actually, E_INVALID_ARG never occur because the fixed SPP UUID is used.
+ return StartService(Tizen::Base::UuId(BT_SVC_UUID_SPP));
+}
+
+result
+BluetoothSppAcceptor::StartService(const Tizen::Base::UuId& serviceUuid)
+{
+ result r = E_SUCCESS;
+
+ // Privilege check
+ r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+ SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ // Check Construct
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->StartService(serviceUuid);
+}
+
+result
+BluetoothSppAcceptor::StopService(void)
+{
+ result r = E_SUCCESS;
+
+ // Privilege check
+ r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+ SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ // Check Construct
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->StopService();
+}
+
+result
+BluetoothSppAcceptor::SendData(const Tizen::Base::ByteBuffer& buffer)
+{
+ result r = E_SUCCESS;
+
+ // Privilege check
+ r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+ SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ // Check Construct
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->SendData(buffer);
+}
+
+result
+BluetoothSppAcceptor::Disconnect(void)
+{
+ result r = E_SUCCESS;
+
+ // Privilege check
+ r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+ SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ // Check Construct
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->Disconnect();
+}
+
+} } } // Tizen::Net::Bluetooth