diff options
Diffstat (limited to 'src/FNetBt_BluetoothIpcProxy.cpp')
-rwxr-xr-x | src/FNetBt_BluetoothIpcProxy.cpp | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/src/FNetBt_BluetoothIpcProxy.cpp b/src/FNetBt_BluetoothIpcProxy.cpp new file mode 100755 index 0000000..5fa6056 --- /dev/null +++ b/src/FNetBt_BluetoothIpcProxy.cpp @@ -0,0 +1,158 @@ +// +// 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 FNetBt_BluetoothIpcProxy.cpp +// @brief This is the implementation file for the %_BluetoothIpcProxy class. +// +// This file contains the implementation of the %_BluetoothIpcProxy class. +// + +#include <pthread.h> +#include <FBaseSysLog.h> +#include <FIo_IpcClient.h> +#include "FNetBt_BluetoothIpcProxy.h" +#include "FNetBt_ConnectivityIpcMessages.h" + +using namespace Tizen::Base; +using namespace Tizen::Io; + +namespace Tizen { namespace Net { namespace Bluetooth +{ + +_BluetoothIpcProxy* _BluetoothIpcProxy::__pInstance = null; + +_BluetoothIpcProxy::_BluetoothIpcProxy(void) : + __pIpcClient(null) +{ +} + +_BluetoothIpcProxy::~_BluetoothIpcProxy(void) +{ + delete __pIpcClient; +} + +result +_BluetoothIpcProxy::Construct(void) +{ + result r = E_SUCCESS; + + __pIpcClient = new (std::nothrow) _IpcClient; + SysTryReturnResult(NID_NET_BT, __pIpcClient != null, E_OUT_OF_MEMORY, "The memory is insufficient."); + + r = __pIpcClient->Construct(BLUETOOTH_CONNECTIVITY_IPC_SERVER_NAME, null); + if (IsFailed(r)) + { + delete __pIpcClient; + __pIpcClient = null; + + SysLog(NID_NET_BT, "[%s] Construction of the IPC client for the Bluetooth proxy has failed.", GetErrorMessage(r)); + } + + return r; +} + +void +_BluetoothIpcProxy::InitSingleton(void) +{ + result r = E_SUCCESS; + static _BluetoothIpcProxy inst; + + r = inst.Construct(); + SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + __pInstance = &inst; +} + +_BluetoothIpcProxy* +_BluetoothIpcProxy::GetInstance(void) +{ + static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; + + if (__pInstance == null) + { + ClearLastResult(); + pthread_once(&onceBlock, InitSingleton); + result r = GetLastResult(); + if (IsFailed(r)) + { + onceBlock = PTHREAD_ONCE_INIT; + } + } + + return __pInstance; +} + +result +_BluetoothIpcProxy::GetLocalDeviceName(Tizen::Base::String& deviceName) const +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) ConnectivityBluetoothServiceMsg_getLocalDeviceName(&deviceName, &ret); + SysTryReturnResult(NID_NET_BT, pMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + SysTryReturnResult(NID_NET_BT, ret == E_SUCCESS, ret, "Propagating."); + + SysLog(NID_NET_BT, "The Bluetooth name obtained through IPC is [%ls].", deviceName.GetPointer()); + + return E_SUCCESS; +} + +result +_BluetoothIpcProxy::SetLocalDeviceName(const Tizen::Base::String& deviceName) const +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) ConnectivityBluetoothServiceMsg_setLocalDeviceName(deviceName, &ret); + SysTryReturnResult(NID_NET_BT, pMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + SysTryReturnResult(NID_NET_BT, ret == E_SUCCESS, ret, "Propagating."); + + SysLog(NID_NET_BT, "Setting the Bluetooth name through IPC is successful."); + + return E_SUCCESS; +} + +result +_BluetoothIpcProxy::SetDiscoverableMode(int mode, int seconds) const +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) ConnectivityBluetoothServiceMsg_setDiscoverableMode(mode, seconds, &ret); + SysTryReturnResult(NID_NET_BT, pMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + SysTryReturnResult(NID_NET_BT, ret == E_SUCCESS, ret, "Propagating."); + + SysLog(NID_NET_BT, "Setting the Bluetooth discoverable mode through IPC is successful."); + + return E_SUCCESS; +} + +} } } // Tizen::Net::Bluetooth |