Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: device/bluetooth/bluetooth_socket_win.h

Issue 320463002: Bluetooth: Implement socket API for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DeviceWin return SDRWin to avoid cast Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « device/bluetooth/bluetooth_profile_win.cc ('k') | device/bluetooth/bluetooth_socket_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_
7 7
8 #include <WinSock2.h> 8 #include <WinSock2.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "device/bluetooth/bluetooth_service_record_win.h" 13 #include "device/bluetooth/bluetooth_service_record_win.h"
14 #include "device/bluetooth/bluetooth_socket.h" 14 #include "device/bluetooth/bluetooth_socket.h"
15 #include "device/bluetooth/bluetooth_socket_net.h" 15 #include "device/bluetooth/bluetooth_socket_net.h"
16 #include "device/bluetooth/bluetooth_uuid.h"
16 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
17 #include "net/socket/tcp_socket.h" 18 #include "net/socket/tcp_socket.h"
18 19
19 namespace device { 20 namespace device {
20 21
21 class BluetoothServiceRecord; 22 class BluetoothAdapter;
23 class BluetoothDeviceWin;
22 24
23 // The BluetoothSocketWin class implements BluetoothSocket for the Microsoft 25 // The BluetoothSocketWin class implements BluetoothSocket for the Microsoft
24 // Windows platform. 26 // Windows platform.
25 class BluetoothSocketWin : public BluetoothSocketNet { 27 class BluetoothSocketWin : public BluetoothSocketNet {
26 public: 28 public:
27 typedef base::Callback<void(scoped_refptr<BluetoothSocketWin>,
28 const net::IPEndPoint&)> OnNewConnectionCallback;
29
30 static scoped_refptr<BluetoothSocketWin> CreateBluetoothSocket( 29 static scoped_refptr<BluetoothSocketWin> CreateBluetoothSocket(
31 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 30 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
32 scoped_refptr<BluetoothSocketThread> socket_thread, 31 scoped_refptr<BluetoothSocketThread> socket_thread,
33 net::NetLog* net_log, 32 net::NetLog* net_log,
34 const net::NetLog::Source& source); 33 const net::NetLog::Source& source);
35 34
36 // Starts a service with the given uuid, name and rfcomm_channel. 35 // Connect to the peer device and calls |success_callback| when the
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.
41 void StartService(
42 const BluetoothUUID& uuid,
43 const std::string& name,
44 int rfcomm_channel,
45 const base::Closure& success_callback,
46 const ErrorCompletionCallback& error_callback,
47 const OnNewConnectionCallback& new_connection_callback);
48
49 // connection has been established successfully. If an error occurs, calls 36 // connection has been established successfully. If an error occurs, calls
50 // |error_callback| with a system error message. 37 // |error_callback| with a system error message.
51 void Connect(const BluetoothServiceRecord& service_record, 38 void Connect(const BluetoothDeviceWin* device,
39 const BluetoothUUID& uuid,
52 const base::Closure& success_callback, 40 const base::Closure& success_callback,
53 const ErrorCompletionCallback& error_callback); 41 const ErrorCompletionCallback& error_callback);
54 42
43 // Listens using this socket using an RFCOMM service published as UUID |uuid|
44 // with Channel |channel|. |success_callback| will be called if the service
45 // is successfully registered, |error_callback| on failure with a message
46 // explaining the cause.
47 void Listen(scoped_refptr<BluetoothAdapter> adapter,
48 const BluetoothUUID& uuid,
49 int rfcomm_channel,
50 const base::Closure& success_callback,
51 const ErrorCompletionCallback& error_callback);
52
55 // BluetoothSocketNet: 53 // BluetoothSocketNet:
56 void ResetData(); 54 void ResetData();
57 55
58 // BluetoothSocket: 56 // BluetoothSocket:
59 virtual void Accept(const AcceptCompletionCallback& success_callback, 57 virtual void Accept(const AcceptCompletionCallback& success_callback,
60 const ErrorCompletionCallback& error_callback) OVERRIDE; 58 const ErrorCompletionCallback& error_callback) OVERRIDE;
61 59
62
63 protected: 60 protected:
64 virtual ~BluetoothSocketWin(); 61 virtual ~BluetoothSocketWin();
65 62
66 private: 63 private:
67 struct ServiceRegData; 64 struct ServiceRegData;
68 65
69 BluetoothSocketWin(scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 66 BluetoothSocketWin(scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
70 scoped_refptr<BluetoothSocketThread> socket_thread, 67 scoped_refptr<BluetoothSocketThread> socket_thread,
71 net::NetLog* net_log, 68 net::NetLog* net_log,
72 const net::NetLog::Source& source); 69 const net::NetLog::Source& source);
73 70
74 71
75 void DoConnect(const base::Closure& success_callback, 72 void DoConnect(const base::Closure& success_callback,
76 const ErrorCompletionCallback& error_callback); 73 const ErrorCompletionCallback& error_callback);
77 void DoStartService(const BluetoothUUID& uuid, 74 void DoListen(const BluetoothUUID& uuid,
78 const std::string& name,
79 int rfcomm_channel, 75 int rfcomm_channel,
80 const base::Closure& success_callback, 76 const base::Closure& success_callback,
81 const ErrorCompletionCallback& error_callback, 77 const ErrorCompletionCallback& error_callback);
82 const OnNewConnectionCallback& new_connection_callback); 78 void DoAccept(const AcceptCompletionCallback& success_callback,
83 void DoAccept(); 79 const ErrorCompletionCallback& error_callback);
84 void OnAcceptOnSocketThread(int accept_result); 80 void OnAcceptOnSocketThread(const AcceptCompletionCallback& success_callback,
81 const ErrorCompletionCallback& error_callback,
82 int accept_result);
85 void OnAcceptOnUI(scoped_ptr<net::TCPSocket> accept_socket, 83 void OnAcceptOnUI(scoped_ptr<net::TCPSocket> accept_socket,
86 const net::IPEndPoint& peer_address); 84 const net::IPEndPoint& peer_address,
85 const AcceptCompletionCallback& success_callback,
86 const ErrorCompletionCallback& error_callback);
87 87
88 std::string device_address_; 88 std::string device_address_;
89 bool supports_rfcomm_; 89 bool supports_rfcomm_;
90 uint8 rfcomm_channel_; 90 uint8 rfcomm_channel_;
91 BTH_ADDR bth_addr_; 91 BTH_ADDR bth_addr_;
92 92
93 // Data members below are only used when listening.
94 scoped_refptr<device::BluetoothAdapter> adapter_;
93 scoped_ptr<ServiceRegData> service_reg_data_; 95 scoped_ptr<ServiceRegData> service_reg_data_;
94 scoped_ptr<net::TCPSocket> accept_socket_; 96 scoped_ptr<net::TCPSocket> accept_socket_;
95 net::IPEndPoint accept_address_; 97 net::IPEndPoint accept_address_;
96 OnNewConnectionCallback on_new_connection_callback_;
97 98
98 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin); 99 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin);
99 }; 100 };
100 101
101 } // namespace device 102 } // namespace device
102 103
103 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_ 104 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_profile_win.cc ('k') | device/bluetooth/bluetooth_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698