Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / device / bluetooth / bluetooth_device_win.cc
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "device/bluetooth/bluetooth_device_win.h"
6
7 #include <string>
8
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/sequenced_task_runner.h"
13 #include "base/strings/stringprintf.h"
14 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
15 #include "device/bluetooth/bluetooth_profile_win.h"
16 #include "device/bluetooth/bluetooth_service_record_win.h"
17 #include "device/bluetooth/bluetooth_socket_thread.h"
18 #include "device/bluetooth/bluetooth_socket_win.h"
19 #include "device/bluetooth/bluetooth_task_manager_win.h"
20 #include "device/bluetooth/bluetooth_uuid.h"
21
22 namespace {
23
24 const int kSdpBytesBufferSize = 1024;
25
26 }  // namespace
27
28 namespace device {
29
30 BluetoothDeviceWin::BluetoothDeviceWin(
31     const BluetoothTaskManagerWin::DeviceState& state,
32     scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
33     scoped_refptr<BluetoothSocketThread> socket_thread,
34     net::NetLog* net_log,
35     const net::NetLog::Source& net_log_source)
36     : BluetoothDevice(),
37       ui_task_runner_(ui_task_runner),
38       socket_thread_(socket_thread),
39       net_log_(net_log),
40       net_log_source_(net_log_source) {
41   name_ = state.name;
42   address_ = state.address;
43   bluetooth_class_ = state.bluetooth_class;
44   visible_ = state.visible;
45   connected_ = state.connected;
46   paired_ = state.authenticated;
47
48   for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
49        iter = state.service_record_states.begin();
50        iter != state.service_record_states.end();
51        ++iter) {
52     uint8 sdp_bytes_buffer[kSdpBytesBufferSize];
53     std::copy((*iter)->sdp_bytes.begin(),
54               (*iter)->sdp_bytes.end(),
55               sdp_bytes_buffer);
56     BluetoothServiceRecord* service_record = new BluetoothServiceRecordWin(
57         (*iter)->name,
58         (*iter)->address,
59         (*iter)->sdp_bytes.size(),
60         sdp_bytes_buffer);
61     service_record_list_.push_back(service_record);
62     uuids_.push_back(service_record->uuid());
63   }
64 }
65
66 BluetoothDeviceWin::~BluetoothDeviceWin() {
67 }
68
69 void BluetoothDeviceWin::SetVisible(bool visible) {
70   visible_ = visible;
71 }
72
73 void BluetoothDeviceWin::AddObserver(
74     device::BluetoothDevice::Observer* observer) {
75   DCHECK(observer);
76   observers_.AddObserver(observer);
77 }
78
79 void BluetoothDeviceWin::RemoveObserver(
80     device::BluetoothDevice::Observer* observer) {
81   DCHECK(observer);
82   observers_.RemoveObserver(observer);
83 }
84
85
86 uint32 BluetoothDeviceWin::GetBluetoothClass() const {
87   return bluetooth_class_;
88 }
89
90 std::string BluetoothDeviceWin::GetDeviceName() const {
91   return name_;
92 }
93
94 std::string BluetoothDeviceWin::GetAddress() const {
95   return address_;
96 }
97
98 BluetoothDevice::VendorIDSource
99 BluetoothDeviceWin::GetVendorIDSource() const {
100   return VENDOR_ID_UNKNOWN;
101 }
102
103 uint16 BluetoothDeviceWin::GetVendorID() const {
104   return 0;
105 }
106
107 uint16 BluetoothDeviceWin::GetProductID() const {
108   return 0;
109 }
110
111 uint16 BluetoothDeviceWin::GetDeviceID() const {
112   return 0;
113 }
114
115 int BluetoothDeviceWin::GetRSSI() const {
116   NOTIMPLEMENTED();
117   return kUnknownPower;
118 }
119
120 int BluetoothDeviceWin::GetCurrentHostTransmitPower() const {
121   NOTIMPLEMENTED();
122   return kUnknownPower;
123 }
124
125 int BluetoothDeviceWin::GetMaximumHostTransmitPower() const {
126   NOTIMPLEMENTED();
127   return kUnknownPower;
128 }
129
130 bool BluetoothDeviceWin::IsPaired() const {
131   return paired_;
132 }
133
134 bool BluetoothDeviceWin::IsConnected() const {
135   return connected_;
136 }
137
138 bool BluetoothDeviceWin::IsConnectable() const {
139   return false;
140 }
141
142 bool BluetoothDeviceWin::IsConnecting() const {
143   return false;
144 }
145
146 BluetoothDevice::UUIDList BluetoothDeviceWin::GetUUIDs() const {
147   return uuids_;
148 }
149
150 bool BluetoothDeviceWin::ExpectingPinCode() const {
151   NOTIMPLEMENTED();
152   return false;
153 }
154
155 bool BluetoothDeviceWin::ExpectingPasskey() const {
156   NOTIMPLEMENTED();
157   return false;
158 }
159
160 bool BluetoothDeviceWin::ExpectingConfirmation() const {
161   NOTIMPLEMENTED();
162   return false;
163 }
164
165 void BluetoothDeviceWin::Connect(
166     PairingDelegate* pairing_delegate,
167     const base::Closure& callback,
168     const ConnectErrorCallback& error_callback) {
169   NOTIMPLEMENTED();
170 }
171
172 void BluetoothDeviceWin::SetPinCode(const std::string& pincode) {
173   NOTIMPLEMENTED();
174 }
175
176 void BluetoothDeviceWin::SetPasskey(uint32 passkey) {
177   NOTIMPLEMENTED();
178 }
179
180 void BluetoothDeviceWin::ConfirmPairing() {
181   NOTIMPLEMENTED();
182 }
183
184 void BluetoothDeviceWin::RejectPairing() {
185   NOTIMPLEMENTED();
186 }
187
188 void BluetoothDeviceWin::CancelPairing() {
189   NOTIMPLEMENTED();
190 }
191
192 void BluetoothDeviceWin::Disconnect(
193     const base::Closure& callback,
194     const ErrorCallback& error_callback) {
195   NOTIMPLEMENTED();
196 }
197
198 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) {
199   NOTIMPLEMENTED();
200 }
201
202 void BluetoothDeviceWin::ConnectToProfile(
203     device::BluetoothProfile* profile,
204     const base::Closure& callback,
205     const ConnectToProfileErrorCallback& error_callback) {
206   DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
207   static_cast<BluetoothProfileWin*>(profile)->Connect(this,
208                                                       ui_task_runner_,
209                                                       socket_thread_,
210                                                       net_log_,
211                                                       net_log_source_,
212                                                       callback,
213                                                       error_callback);
214 }
215
216 void BluetoothDeviceWin::ConnectToService(
217     const BluetoothUUID& uuid,
218     const ConnectToServiceCallback& callback,
219     const ConnectToServiceErrorCallback& error_callback) {
220   // TODO(keybuk): implement
221   NOTIMPLEMENTED();
222 }
223
224 void BluetoothDeviceWin::SetOutOfBandPairingData(
225     const BluetoothOutOfBandPairingData& data,
226     const base::Closure& callback,
227     const ErrorCallback& error_callback) {
228   NOTIMPLEMENTED();
229 }
230
231 void BluetoothDeviceWin::ClearOutOfBandPairingData(
232     const base::Closure& callback,
233     const ErrorCallback& error_callback) {
234   NOTIMPLEMENTED();
235 }
236
237 void BluetoothDeviceWin::StartConnectionMonitor(
238     const base::Closure& callback,
239     const ErrorCallback& error_callback) {
240   NOTIMPLEMENTED();
241 }
242
243 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord(
244     const device::BluetoothUUID& uuid) const {
245   for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
246        iter != service_record_list_.end();
247        ++iter) {
248     if ((*iter)->uuid() == uuid)
249       return *iter;
250   }
251   return NULL;
252 }
253
254 }  // namespace device