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

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

Issue 236203018: win: Implement Bluetooth server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 <queue> 10 #include <queue>
11 #include <string> 11 #include <string>
12 12
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "device/bluetooth/bluetooth_service_record_win.h" 16 #include "device/bluetooth/bluetooth_service_record_win.h"
17 #include "device/bluetooth/bluetooth_socket.h" 17 #include "device/bluetooth/bluetooth_socket.h"
18 #include "net/base/ip_endpoint.h"
18 #include "net/base/net_log.h" 19 #include "net/base/net_log.h"
19 #include "net/socket/tcp_socket.h" 20 #include "net/socket/tcp_socket.h"
20 21
21 namespace net { 22 namespace net {
22 class IOBuffer; 23 class IOBuffer;
23 class IOBufferWithSize; 24 class IOBufferWithSize;
24 } // namespace net 25 } // namespace net
25 26
26 namespace device { 27 namespace device {
27 28
28 class BluetoothServiceRecord; 29 class BluetoothServiceRecord;
29 class BluetoothSocketThreadWin; 30 class BluetoothSocketThreadWin;
30 31
31 // This class is an implementation of BluetoothSocket class for the Windows 32 // This class is an implementation of BluetoothSocket class for the Windows
32 // platform. All public methods (including the factory method) must be called 33 // platform. All public methods (including the factory method) must be called
33 // on the UI thread, while underlying socket operations are performed on a 34 // on the UI thread, while underlying socket operations are performed on a
34 // separated thread. 35 // separated thread.
35 class BluetoothSocketWin : public BluetoothSocket { 36 class BluetoothSocketWin : public BluetoothSocket {
36 public: 37 public:
37 static scoped_refptr<BluetoothSocketWin> CreateBluetoothSocket( 38 static scoped_refptr<BluetoothSocketWin> CreateBluetoothSocket(
38 const BluetoothServiceRecord& service_record, 39 const BluetoothServiceRecord& service_record,
39 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 40 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
40 scoped_refptr<BluetoothSocketThreadWin> socket_thread, 41 scoped_refptr<BluetoothSocketThreadWin> socket_thread,
41 net::NetLog* net_log, 42 net::NetLog* net_log,
42 const net::NetLog::Source& source); 43 const net::NetLog::Source& source);
43 44
44 // Connect to the peer device and calls |success_callback| when the 45 static scoped_refptr<BluetoothSocketWin> CreateBluetoothSocket(
46 scoped_ptr<net::TCPSocket> existing,
47 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
48 scoped_refptr<BluetoothSocketThreadWin> socket_thread,
49 net::NetLog* net_log,
50 const net::NetLog::Source& source);
keybuk 2014/04/16 08:06:17 It seems that the BluetoothProfileWin implementati
xiyuan 2014/04/23 17:42:55 Done.
51
45 // connection has been established successfully. If an error occurs, calls 52 // connection has been established successfully. If an error occurs, calls
46 // |error_callback| with a system error message. 53 // |error_callback| with a system error message.
47 void Connect(const base::Closure& success_callback, 54 void Connect(const base::Closure& success_callback,
48 const ErrorCompletionCallback& error_callback); 55 const ErrorCompletionCallback& error_callback);
49 56
50 // Overriden from BluetoothSocket: 57 // Overriden from BluetoothSocket:
51 virtual void Close() OVERRIDE; 58 virtual void Close() OVERRIDE;
52 59
53 virtual void Disconnect(const base::Closure& callback) OVERRIDE; 60 virtual void Disconnect(const base::Closure& callback) OVERRIDE;
54 61
55 virtual void Receive(int count, 62 virtual void Receive(int count,
56 const ReceiveCompletionCallback& success_callback, 63 const ReceiveCompletionCallback& success_callback,
57 const ReceiveErrorCompletionCallback& error_callback) 64 const ReceiveErrorCompletionCallback& error_callback)
58 OVERRIDE; 65 OVERRIDE;
59 virtual void Send(scoped_refptr<net::IOBuffer> buffer, 66 virtual void Send(scoped_refptr<net::IOBuffer> buffer,
60 int buffer_size, 67 int buffer_size,
61 const SendCompletionCallback& success_callback, 68 const SendCompletionCallback& success_callback,
62 const ErrorCompletionCallback& error_callback) OVERRIDE; 69 const ErrorCompletionCallback& error_callback) OVERRIDE;
63 70
71 typedef base::Callback<void(scoped_refptr<BluetoothSocketWin>,
72 const net::IPEndPoint&)> OnAcceptCallback;
73 void Accept(const OnAcceptCallback& on_accept_callback);
74
64 protected: 75 protected:
65 virtual ~BluetoothSocketWin(); 76 virtual ~BluetoothSocketWin();
66 77
67 private: 78 private:
68 struct WriteRequest { 79 struct WriteRequest {
69 scoped_refptr<net::IOBuffer> buffer; 80 scoped_refptr<net::IOBuffer> buffer;
70 int buffer_size; 81 int buffer_size;
71 SendCompletionCallback success_callback; 82 SendCompletionCallback success_callback;
72 ErrorCompletionCallback error_callback; 83 ErrorCompletionCallback error_callback;
73 }; 84 };
(...skipping 30 matching lines...) Expand all
104 115
105 void SendFrontWriteRequest(); 116 void SendFrontWriteRequest();
106 void OnSocketWriteComplete(const SendCompletionCallback& success_callback, 117 void OnSocketWriteComplete(const SendCompletionCallback& success_callback,
107 const ErrorCompletionCallback& error_callback, 118 const ErrorCompletionCallback& error_callback,
108 int net_status); 119 int net_status);
109 void OnSocketReadComplete( 120 void OnSocketReadComplete(
110 const ReceiveCompletionCallback& success_callback, 121 const ReceiveCompletionCallback& success_callback,
111 const ReceiveErrorCompletionCallback& error_callback, 122 const ReceiveErrorCompletionCallback& error_callback,
112 int send_result); 123 int send_result);
113 124
125 void DoAccept();
126 void OnAcceptOnSocketThread(int accept_result);
127 void OnAcceptOnUI(scoped_ptr<net::TCPSocket> accept_socket,
128 const net::IPEndPoint& peer_address);
129
114 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; 130 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
115 scoped_refptr<BluetoothSocketThreadWin> socket_thread_; 131 scoped_refptr<BluetoothSocketThreadWin> socket_thread_;
116 net::NetLog* net_log_; 132 net::NetLog* net_log_;
117 const net::NetLog::Source source_; 133 const net::NetLog::Source source_;
118 std::string device_address_; 134 std::string device_address_;
119 bool supports_rfcomm_; 135 bool supports_rfcomm_;
120 uint8 rfcomm_channel_; 136 uint8 rfcomm_channel_;
121 BTH_ADDR bth_addr_; 137 BTH_ADDR bth_addr_;
122 scoped_ptr<net::TCPSocket> tcp_socket_; 138 scoped_ptr<net::TCPSocket> tcp_socket_;
123 // Queue of pending writes. The buffer at the front of the queue is the one 139 // Queue of pending writes. The buffer at the front of the queue is the one
124 // being written. 140 // being written.
125 std::queue<linked_ptr<WriteRequest> > write_queue_; 141 std::queue<linked_ptr<WriteRequest> > write_queue_;
126 scoped_refptr<net::IOBufferWithSize> read_buffer_; 142 scoped_refptr<net::IOBufferWithSize> read_buffer_;
127 143
144 scoped_ptr<net::TCPSocket> accept_socket_;
145 net::IPEndPoint accept_address_;
146 OnAcceptCallback on_accept_callback_;
147
128 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin); 148 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin);
129 }; 149 };
130 150
131 } // namespace device 151 } // namespace device
132 152
133 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_ 153 #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