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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_
12 #include "base/memory/ref_counted.h"
13 #include "device/bluetooth/bluetooth_service_record_win.h"
14 #include "device/bluetooth/bluetooth_socket.h"
15 #include "device/bluetooth/bluetooth_socket_net.h"
16 #include "net/base/ip_endpoint.h"
17 #include "net/socket/tcp_socket.h"
21 class BluetoothServiceRecord;
23 // The BluetoothSocketWin class implements BluetoothSocket for the Microsoft
25 class BluetoothSocketWin : public BluetoothSocketNet {
27 typedef base::Callback<void(scoped_refptr<BluetoothSocketWin>,
28 const net::IPEndPoint&)> OnNewConnectionCallback;
30 static scoped_refptr<BluetoothSocketWin> CreateBluetoothSocket(
31 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
32 scoped_refptr<BluetoothSocketThread> socket_thread,
34 const net::NetLog::Source& source);
36 // Starts a service with the given uuid, name and rfcomm_channel.
37 // |success_callback| is invoked when the underlying socket is created
38 // and the service is published successfully. Otherwise, |error_callback| is
39 // called with an error message. |new_connection_callback| is invoked when
40 // an incoming connection is accepted by the underlying socket.
42 const BluetoothUUID& uuid,
43 const std::string& name,
45 const base::Closure& success_callback,
46 const ErrorCompletionCallback& error_callback,
47 const OnNewConnectionCallback& new_connection_callback);
49 // connection has been established successfully. If an error occurs, calls
50 // |error_callback| with a system error message.
51 void Connect(const BluetoothServiceRecord& service_record,
52 const base::Closure& success_callback,
53 const ErrorCompletionCallback& error_callback);
55 // BluetoothSocketNet:
59 virtual ~BluetoothSocketWin();
62 struct ServiceRegData;
64 BluetoothSocketWin(scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
65 scoped_refptr<BluetoothSocketThread> socket_thread,
67 const net::NetLog::Source& source);
70 void DoConnect(const base::Closure& success_callback,
71 const ErrorCompletionCallback& error_callback);
72 void DoStartService(const BluetoothUUID& uuid,
73 const std::string& name,
75 const base::Closure& success_callback,
76 const ErrorCompletionCallback& error_callback,
77 const OnNewConnectionCallback& new_connection_callback);
79 void OnAcceptOnSocketThread(int accept_result);
80 void OnAcceptOnUI(scoped_ptr<net::TCPSocket> accept_socket,
81 const net::IPEndPoint& peer_address);
83 std::string device_address_;
84 bool supports_rfcomm_;
85 uint8 rfcomm_channel_;
88 scoped_ptr<ServiceRegData> service_reg_data_;
89 scoped_ptr<net::TCPSocket> accept_socket_;
90 net::IPEndPoint accept_address_;
91 OnNewConnectionCallback on_new_connection_callback_;
93 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin);
98 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_