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

Unified Diff: chrome/browser/chromeos/bluetooth/bluetooth_socket.cc

Issue 10007008: Add support for creating bluetooth RFCOMM sockets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase diff to exclude extensions code Created 8 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
Index: chrome/browser/chromeos/bluetooth/bluetooth_socket.cc
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_socket.cc b/chrome/browser/chromeos/bluetooth/bluetooth_socket.cc
new file mode 100644
index 0000000000000000000000000000000000000000..40c96e4ba8413f9d29baac7945558408e2513bcf
--- /dev/null
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_socket.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h"
+
+#include <vector>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/rfcomm.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h"
+#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h"
+
+namespace chromeos {
+
+BluetoothSocket::BluetoothSocket(const std::string& address, int fd)
+ : address_(address),
+ fd_(fd) {
+}
+
+BluetoothSocket::~BluetoothSocket() {
+ close(fd_);
+}
+
+// static
+scoped_refptr<BluetoothSocket> BluetoothSocket::CreateBluetoothSocket(
+ const BluetoothServiceRecord& service_record) {
+ BluetoothSocket* bluetooth_socket = NULL;
+ if (service_record.SupportsRfcomm()) {
+ int socket_fd = socket(
+ AF_BLUETOOTH, SOCK_STREAM | SOCK_NONBLOCK, BTPROTO_RFCOMM);
+ struct sockaddr_rc socket_address = { 0 };
+ socket_address.rc_family = AF_BLUETOOTH;
+ socket_address.rc_channel = service_record.rfcomm_channel();
+ bdaddr_t bluetooth_address;
+ bluetooth_utils::str2ba(service_record.address(), &bluetooth_address);
+
+ int status = connect(socket_fd, (struct sockaddr *)&socket_address,
+ sizeof(socket_address));
+ if (status == 0 || errno == EINPROGRESS)
+ bluetooth_socket = new BluetoothSocket(service_record.address(),
+ socket_fd);
+ else
+ close(socket_fd);
+ } else {
+ // TODO(bryeung): add support for L2CAP sockets as well.
+ return NULL;
+ }
+
+ return scoped_refptr<BluetoothSocket>(bluetooth_socket);
+}
+
+} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/bluetooth/bluetooth_socket.h ('k') | chrome/browser/chromeos/bluetooth/bluetooth_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698