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

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

Issue 328903002: Factor out a BluetoothChannelMac base class and a BluetoothRfcommChannelMac subclass. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git-add new files 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_MAC_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
11 #import <IOBluetooth/IOBluetooth.h> 11 #import <IOBluetooth/IOBluetooth.h>
12 #import <IOKit/IOReturn.h> 12 #import <IOKit/IOReturn.h>
13 13
14 #include "base/mac/scoped_nsobject.h" 14 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/threading/thread_checker.h" 18 #include "base/threading/thread_checker.h"
19 #include "device/bluetooth/bluetooth_socket.h" 19 #include "device/bluetooth/bluetooth_socket.h"
20 #include "device/bluetooth/bluetooth_uuid.h" 20 #include "device/bluetooth/bluetooth_uuid.h"
21 21
22 @class BluetoothRfcommChannelDelegate;
23 @class BluetoothRfcommConnectionListener; 22 @class BluetoothRfcommConnectionListener;
24 23
25 namespace net { 24 namespace net {
26 class IOBuffer; 25 class IOBuffer;
27 class IOBufferWithSize; 26 class IOBufferWithSize;
28 } 27 }
29 28
30 namespace device { 29 namespace device {
31 30
32 class BluetoothAdapter; 31 class BluetoothAdapter;
32 class BluetoothChannelMac;
33 33
34 // Implements the BluetoothSocket class for the Mac OS X platform. 34 // Implements the BluetoothSocket class for the Mac OS X platform.
35 class BluetoothSocketMac : public BluetoothSocket { 35 class BluetoothSocketMac : public BluetoothSocket {
36 public: 36 public:
37 static scoped_refptr<BluetoothSocketMac> CreateSocket(); 37 static scoped_refptr<BluetoothSocketMac> CreateSocket();
38 38
39 // Connects this socket to the service on |device| published as UUID |uuid|. 39 // Connects this socket to the service on |device| published as UUID |uuid|.
40 // The underlying protocol and PSM or Channel is obtained through service 40 // The underlying protocol and PSM or Channel is obtained through service
41 // discovery. On a successful connection, the socket properties will be 41 // discovery. On a successful connection, the socket properties will be
42 // updated and |success_callback| called. On failure, |error_callback| will be 42 // updated and |success_callback| called. On failure, |error_callback| will be
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // |status| is the returned status from the SDP query, |device| is the 86 // |status| is the returned status from the SDP query, |device| is the
87 // IOBluetoothDevice for which the query was made. The remaining 87 // IOBluetoothDevice for which the query was made. The remaining
88 // parameters are those from |Connect()|. 88 // parameters are those from |Connect()|.
89 void OnSDPQueryComplete( 89 void OnSDPQueryComplete(
90 IOReturn status, 90 IOReturn status,
91 IOBluetoothDevice* device, 91 IOBluetoothDevice* device,
92 const base::Closure& success_callback, 92 const base::Closure& success_callback,
93 const ErrorCompletionCallback& error_callback); 93 const ErrorCompletionCallback& error_callback);
94 94
95 // Called by BluetoothRfcommConnectionListener. 95 // Called by BluetoothRfcommConnectionListener.
96 void OnRfcommChannelOpened(IOBluetoothRFCOMMChannel* rfcomm_channel); 96 void OnChannelOpened(scoped_ptr<BluetoothChannelMac> channel);
97 97
98 // Called by BluetoothRfcommChannelDelegate. 98 // Called by |channel_|.
99 void OnRfcommChannelOpenComplete(IOBluetoothRFCOMMChannel* rfcomm_channel, 99 // Note: OnChannelOpenComplete might be called before the |channel_| is set.
100 IOReturn status); 100 void OnChannelOpenComplete(const std::string& device_address,
101 void OnRfcommChannelClosed(IOBluetoothRFCOMMChannel* rfcomm_channel); 101 IOReturn status);
102 void OnRfcommChannelDataReceived(IOBluetoothRFCOMMChannel* rfcomm_channel, 102 void OnChannelClosed();
103 void* data, 103 void OnChannelDataReceived(void* data, size_t length);
104 size_t length); 104 void OnChannelWriteComplete(void* refcon, IOReturn status);
105 void OnRfcommChannelWriteComplete(IOBluetoothRFCOMMChannel* rfcomm_channel,
106 void* refcon,
107 IOReturn status);
108 105
109 private: 106 private:
110 struct AcceptRequest { 107 struct AcceptRequest {
111 AcceptRequest(); 108 AcceptRequest();
112 ~AcceptRequest(); 109 ~AcceptRequest();
113 110
114 AcceptCompletionCallback success_callback; 111 AcceptCompletionCallback success_callback;
115 ErrorCompletionCallback error_callback; 112 ErrorCompletionCallback error_callback;
116 }; 113 };
117 114
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 scoped_refptr<BluetoothAdapter> adapter_; 156 scoped_refptr<BluetoothAdapter> adapter_;
160 157
161 // UUID of the profile being connected to, or that the socket is listening on. 158 // UUID of the profile being connected to, or that the socket is listening on.
162 device::BluetoothUUID uuid_; 159 device::BluetoothUUID uuid_;
163 160
164 // A simple helper that registers for OS notifications and forwards them to 161 // A simple helper that registers for OS notifications and forwards them to
165 // |this| profile. 162 // |this| profile.
166 base::scoped_nsobject<BluetoothRfcommConnectionListener> 163 base::scoped_nsobject<BluetoothRfcommConnectionListener>
167 rfcomm_connection_listener_; 164 rfcomm_connection_listener_;
168 165
169 // A simple delegate that forwards RFCOMM channel methods to |this| socket.
170 base::scoped_nsobject<BluetoothRfcommChannelDelegate>
171 rfcomm_channel_delegate_;
172
173 // A handle to the service record registered in the system SDP server. 166 // A handle to the service record registered in the system SDP server.
174 // Used to eventually unregister the service. 167 // Used to eventually unregister the service.
175 BluetoothSDPServiceRecordHandle service_record_handle_; 168 BluetoothSDPServiceRecordHandle service_record_handle_;
176 169
177 // The IOBluetooth RFCOMM channel used to issue commands. 170 // The channel used to issue commands.
178 base::scoped_nsobject<IOBluetoothRFCOMMChannel> rfcomm_channel_; 171 scoped_ptr<BluetoothChannelMac> channel_;
179 172
180 // Connection callbacks -- when a pending async connection is active. 173 // Connection callbacks -- when a pending async connection is active.
181 scoped_ptr<ConnectCallbacks> connect_callbacks_; 174 scoped_ptr<ConnectCallbacks> connect_callbacks_;
182 175
183 // Packets received while there is no pending "receive" callback. 176 // Packets received while there is no pending "receive" callback.
184 std::queue<scoped_refptr<net::IOBufferWithSize> > receive_queue_; 177 std::queue<scoped_refptr<net::IOBufferWithSize> > receive_queue_;
185 178
186 // Receive callbacks -- when a receive call is active. 179 // Receive callbacks -- when a receive call is active.
187 scoped_ptr<ReceiveCallbacks> receive_callbacks_; 180 scoped_ptr<ReceiveCallbacks> receive_callbacks_;
188 181
189 // Send queue -- one entry per pending send operation. 182 // Send queue -- one entry per pending send operation.
190 std::queue<linked_ptr<SendRequest>> send_queue_; 183 std::queue<linked_ptr<SendRequest>> send_queue_;
191 184
192 // The pending request to an Accept() call, or null if there is no pending 185 // The pending request to an Accept() call, or null if there is no pending
193 // request. 186 // request.
194 scoped_ptr<AcceptRequest> accept_request_; 187 scoped_ptr<AcceptRequest> accept_request_;
195 188
196 // Queue of incoming RFCOMM connections. 189 // Queue of incoming connections.
197 std::queue<base::scoped_nsobject<IOBluetoothRFCOMMChannel>> accept_queue_; 190 std::queue<linked_ptr<BluetoothChannelMac>> accept_queue_;
198 191
199 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketMac); 192 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketMac);
200 }; 193 };
201 194
202 } // namespace device 195 } // namespace device
203 196
204 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_ 197 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_rfcomm_channel_mac.mm ('k') | device/bluetooth/bluetooth_socket_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698