summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_socket_mac.mm
diff options
context:
space:
mode:
authoryoungki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-24 09:06:51 +0000
committeryoungki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-24 09:06:51 +0000
commit476f29d45584c022e523b81708775e19df7ab48e (patch)
treeaa83f7e77ceca8bc3037fd99fbad5297ce4f60b9 /device/bluetooth/bluetooth_socket_mac.mm
parentd95e9d1f3d5a55f65c0150735afd7ca291813034 (diff)
downloadchromium_src-476f29d45584c022e523b81708775e19df7ab48e.zip
chromium_src-476f29d45584c022e523b81708775e19df7ab48e.tar.gz
chromium_src-476f29d45584c022e523b81708775e19df7ab48e.tar.bz2
Implemented BluetoothDeviceMac::ConnectToProfile().
This CL implements BluetoothProfileMac::Connect(), which makes an explicit outgoing connection to the device. I will add unittests once I get a preliminary review from reviewers. BUG=229636 Review URL: https://chromiumcodereview.appspot.com/14405008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196099 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth/bluetooth_socket_mac.mm')
-rw-r--r--device/bluetooth/bluetooth_socket_mac.mm39
1 files changed, 39 insertions, 0 deletions
diff --git a/device/bluetooth/bluetooth_socket_mac.mm b/device/bluetooth/bluetooth_socket_mac.mm
index 31a797c..036f6f1 100644
--- a/device/bluetooth/bluetooth_socket_mac.mm
+++ b/device/bluetooth/bluetooth_socket_mac.mm
@@ -6,16 +6,29 @@
#import <IOBluetooth/objc/IOBluetoothDevice.h>
#import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
+#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
#include <limits>
#include <string>
+#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/stringprintf.h"
+#include "base/strings/sys_string_conversions.h"
#include "device/bluetooth/bluetooth_service_record.h"
#include "device/bluetooth/bluetooth_service_record_mac.h"
#include "net/base/io_buffer.h"
+// Replicate specific 10.7 SDK declarations for building with prior SDKs.
+#if !defined(MAC_OS_X_VERSION_10_7) || \
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
+
+@interface IOBluetoothDevice (LionSDKDeclarations)
+- (NSString*)addressString;
+@end
+
+#endif // MAC_OS_X_VERSION_10_7
+
@interface BluetoothRFCOMMChannelDelegate
: NSObject <IOBluetoothRFCOMMChannelDelegate> {
@private
@@ -84,6 +97,32 @@ scoped_refptr<BluetoothSocket> BluetoothSocketMac::CreateBluetoothSocket(
return scoped_refptr<BluetoothSocketMac>(bluetooth_socket);
}
+// static
+scoped_refptr<BluetoothSocket> BluetoothSocketMac::CreateBluetoothSocket(
+ IOBluetoothSDPServiceRecord* record) {
+ BluetoothSocketMac* bluetooth_socket = NULL;
+ uint8 rfcomm_channel_id;
+ if ([record getRFCOMMChannelID:&rfcomm_channel_id] == kIOReturnSuccess) {
+ IOBluetoothDevice* device = [record device];
+ IOBluetoothRFCOMMChannel* rfcomm_channel;
+ IOReturn status =
+ [device openRFCOMMChannelAsync:&rfcomm_channel
+ withChannelID:rfcomm_channel_id
+ delegate:nil];
+ if (status == kIOReturnSuccess) {
+ bluetooth_socket = new BluetoothSocketMac(rfcomm_channel);
+ } else {
+ LOG(ERROR) << "Failed to connect bluetooth socket ("
+ << base::SysNSStringToUTF8([device addressString]) << "): (" << status
+ << ")";
+ }
+ }
+
+ // TODO(youngki): Add support for L2CAP sockets as well.
+
+ return scoped_refptr<BluetoothSocketMac>(bluetooth_socket);
+}
+
bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) {
CHECK(buffer->offset() == 0);
int length = incoming_data_buffer_->offset();