1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
//
// 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;
std::unique_ptr<_BluetoothIpcProxy> pInst;
pInst.reset(new (std::nothrow) _BluetoothIpcProxy());
r = pInst->Construct();
SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
__pInstance = pInst.release();
}
_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.");
SysSecureLog(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
|