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

Unified Diff: device/bluetooth/bluetooth_socket_mac.h

Issue 229463003: MacOS implementation of BluetoothSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build error on OSX SDK < 10.7. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_profile_mac.mm ('k') | device/bluetooth/bluetooth_socket_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_socket_mac.h
diff --git a/device/bluetooth/bluetooth_socket_mac.h b/device/bluetooth/bluetooth_socket_mac.h
index 806eceb9f3ff99854ca7c83e3e1b081c16bfedf4..76e197ddf6f0798d930778ac2c102a56ea0339c5 100644
--- a/device/bluetooth/bluetooth_socket_mac.h
+++ b/device/bluetooth/bluetooth_socket_mac.h
@@ -5,9 +5,15 @@
#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_
+#include <queue>
#include <string>
+#include <IOKit/IOreturn.h>
+
+#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
+#include "base/sequenced_task_runner.h"
+#include "base/threading/thread_checker.h"
#include "device/bluetooth/bluetooth_socket.h"
#ifdef __OBJC__
@@ -21,8 +27,8 @@ class IOBluetoothSDPServiceRecord;
#endif
namespace net {
-class GrowableIOBuffer;
class IOBuffer;
+class IOBufferWithSize;
} // namespace net
namespace device {
@@ -30,16 +36,20 @@ namespace device {
class BluetoothServiceRecord;
// This class is an implementation of BluetoothSocket class for OSX platform.
+// All methods of this class must all be called on the UI thread, as per Chrome
+// guidelines on performing Async IO on UI thread on MacOS.
class BluetoothSocketMac : public BluetoothSocket {
public:
- // TODO(youngki): This method is deprecated; remove this method when
- // BluetoothServiceRecord is removed.
- static scoped_refptr<BluetoothSocket> CreateBluetoothSocket(
- const BluetoothServiceRecord& service_record);
-
- static scoped_refptr<BluetoothSocket> CreateBluetoothSocket(
+ static scoped_refptr<BluetoothSocketMac> CreateBluetoothSocket(
+ const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
IOBluetoothSDPServiceRecord* record);
+ // Connect to the peer device and calls |success_callback| when the
+ // connection has been established successfully. If an error occurs, calls
+ // |error_callback| with a system error message.
+ void Connect(const base::Closure& success_callback,
+ const ErrorCompletionCallback& error_callback);
+
// Overriden from BluetoothSocket:
virtual void Close() OVERRIDE;
virtual void Disconnect(const base::Closure& callback) OVERRIDE;
@@ -53,22 +63,77 @@ class BluetoothSocketMac : public BluetoothSocket {
const ErrorCompletionCallback& error_callback) OVERRIDE;
// called by BluetoothRFCOMMChannelDelegate.
- void OnDataReceived(IOBluetoothRFCOMMChannel* rfcomm_channel,
- void* data,
- size_t length);
+ void OnChannelOpened(IOBluetoothRFCOMMChannel* rfcomm_channel,
+ IOReturn status);
+
+ // called by BluetoothRFCOMMChannelDelegate.
+ void OnChannelClosed(IOBluetoothRFCOMMChannel* rfcomm_channel);
+
+ // called by BluetoothRFCOMMChannelDelegate.
+ void OnChannelDataReceived(IOBluetoothRFCOMMChannel* rfcomm_channel,
+ void* data,
+ size_t length);
+
+ // called by BluetoothRFCOMMChannelDelegate.
+ void OnChannelWriteComplete(IOBluetoothRFCOMMChannel* rfcomm_channel,
+ void* refcon,
+ IOReturn status);
protected:
virtual ~BluetoothSocketMac();
private:
- explicit BluetoothSocketMac(IOBluetoothRFCOMMChannel* rfcomm_channel);
-
- void ResetIncomingDataBuffer();
+ BluetoothSocketMac(
+ const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
+ IOBluetoothSDPServiceRecord* record);
- IOBluetoothRFCOMMChannel* rfcomm_channel_;
+ struct SendRequest {
+ SendRequest();
+ ~SendRequest();
+ int buffer_size;
+ SendCompletionCallback success_callback;
+ ErrorCompletionCallback error_callback;
+ IOReturn status;
+ int active_async_writes;
+ bool error_signaled;
+ };
+
+ struct ReceiveCallbacks {
+ ReceiveCallbacks();
+ ~ReceiveCallbacks();
+ ReceiveCompletionCallback success_callback;
+ ReceiveErrorCompletionCallback error_callback;
+ };
+
+ struct ConnectCallbacks {
+ ConnectCallbacks();
+ ~ConnectCallbacks();
+ base::Closure success_callback;
+ ErrorCompletionCallback error_callback;
+ };
+
+ void ReleaseChannel();
+
+ bool connecting() const { return connect_callbacks_; }
+
+ // Used to verify all methods are called on the same thread.
+ base::ThreadChecker thread_checker_;
+ // Task Runner for the UI thread, used to post tasks.
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
+ // (retained) The Bluetooth Service definition.
+ IOBluetoothSDPServiceRecord* record_;
+ // (weak) The RFCOMM channel delegate. Released when the channel is closed.
BluetoothRFCOMMChannelDelegate* delegate_;
- scoped_refptr<net::GrowableIOBuffer> incoming_data_buffer_;
- std::string error_message_;
+ // (retained) The IOBluetooth RFCOMM channel used to issue commands.
+ IOBluetoothRFCOMMChannel* rfcomm_channel_;
+ // Connection callbacks -- when a pending async connection is active.
+ scoped_ptr<ConnectCallbacks> connect_callbacks_;
+ // Packets received while there is no pending "receive" callback.
+ std::queue<scoped_refptr<net::IOBufferWithSize> > receive_queue_;
+ // Receive callbacks -- when a receive call is active.
+ scoped_ptr<ReceiveCallbacks> receive_callbacks_;
+ // Send queue -- one entry per pending send operation.
+ std::queue<linked_ptr<SendRequest> > send_queue_;
DISALLOW_COPY_AND_ASSIGN(BluetoothSocketMac);
};
« no previous file with comments | « device/bluetooth/bluetooth_profile_mac.mm ('k') | device/bluetooth/bluetooth_socket_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698