OLD | NEW |
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 <queue> |
10 #include <string> | 11 #include <string> |
11 | 12 |
| 13 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/threading/thread_checker.h" |
| 16 #include "device/bluetooth/bluetooth_service_record_win.h" |
13 #include "device/bluetooth/bluetooth_socket.h" | 17 #include "device/bluetooth/bluetooth_socket.h" |
| 18 #include "net/base/net_log.h" |
14 | 19 |
15 namespace net { | 20 namespace net { |
16 | 21 |
| 22 class IOBufferWithSize; |
17 class DrainableIOBuffer; | 23 class DrainableIOBuffer; |
18 class GrowableIOBuffer; | 24 class TCPSocketWin; |
19 | 25 |
20 } // namespace net | 26 } // namespace net |
21 | 27 |
22 namespace device { | 28 namespace device { |
23 | 29 |
24 class BluetoothServiceRecord; | 30 class BluetoothServiceRecord; |
25 | 31 |
26 // This class is an implementation of BluetoothSocket class for Windows | 32 // This class is an implementation of BluetoothSocket class for Windows |
27 // platform. | 33 // platform. |
28 class BluetoothSocketWin : public BluetoothSocket { | 34 class BluetoothSocketWin : public BluetoothSocket { |
29 public: | 35 public: |
30 static scoped_refptr<BluetoothSocket> CreateBluetoothSocket( | 36 static scoped_refptr<BluetoothSocket> CreateBluetoothSocket( |
31 const BluetoothServiceRecord& service_record); | 37 const BluetoothServiceRecord& service_record, |
| 38 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 39 net::NetLog* net_log, |
| 40 const net::NetLog::Source& source); |
32 | 41 |
33 // BluetoothSocket override | 42 // Overriden from BluetoothSocket: |
34 virtual bool Receive(net::GrowableIOBuffer* buffer) OVERRIDE; | 43 virtual void Connect(const base::Closure& success_callback, |
35 virtual bool Send(net::DrainableIOBuffer* buffer) OVERRIDE; | 44 const ErrorCompletionCallback& error_callback) OVERRIDE; |
36 virtual std::string GetLastErrorMessage() const OVERRIDE; | 45 |
| 46 virtual void Disconnect(const base::Closure& callback) OVERRIDE; |
| 47 |
| 48 virtual void Receive(int count, |
| 49 const ReceiveCompletionCallback& success_callback, |
| 50 const ReceiveErrorCompletionCallback& error_callback) |
| 51 OVERRIDE; |
| 52 virtual void Send(scoped_refptr<net::DrainableIOBuffer> buffer, |
| 53 const SendCompletionCallback& success_callback, |
| 54 const ErrorCompletionCallback& error_callback) OVERRIDE; |
37 | 55 |
38 protected: | 56 protected: |
39 virtual ~BluetoothSocketWin(); | 57 virtual ~BluetoothSocketWin(); |
40 | 58 |
41 private: | 59 private: |
42 explicit BluetoothSocketWin(SOCKET fd); | 60 struct WriteRequest { |
| 61 scoped_refptr<net::DrainableIOBuffer> buffer; |
| 62 SendCompletionCallback success_callback; |
| 63 ErrorCompletionCallback error_callback; |
| 64 }; |
43 | 65 |
44 const SOCKET fd_; | 66 BluetoothSocketWin(scoped_refptr<base::SequencedTaskRunner> task_runner, |
45 std::string error_message_; | 67 net::NetLog* net_log, |
| 68 const net::NetLog::Source& source); |
| 69 |
| 70 void SendFrontWriteRequest(); |
| 71 void OnSocketWriteComplete(const SendCompletionCallback& success_callback, |
| 72 const ErrorCompletionCallback& error_callback, |
| 73 int net_status); |
| 74 void OnSocketReadComplete( |
| 75 const ReceiveCompletionCallback& success_callback, |
| 76 const ReceiveErrorCompletionCallback& error_callback, |
| 77 int send_result); |
| 78 |
| 79 base::ThreadChecker thread_checker_; |
| 80 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 81 net::NetLog* net_log_; |
| 82 const net::NetLog::Source source_; |
| 83 std::string device_address_; |
| 84 bool supports_rfcomm_; |
| 85 uint8 rfcomm_channel_; |
| 86 BTH_ADDR bth_addr_; |
| 87 scoped_ptr<net::TCPSocketWin> socket_win_; |
| 88 // Queue of pending writes. The buffer at the front of the queue is the one |
| 89 // being written. |
| 90 std::queue<linked_ptr<WriteRequest> > write_queue_; |
| 91 scoped_refptr<net::IOBufferWithSize> read_buffer_; |
46 | 92 |
47 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin); | 93 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin); |
48 }; | 94 }; |
49 | 95 |
50 } // namespace device | 96 } // namespace device |
51 | 97 |
52 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_ | 98 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_ |
OLD | NEW |