summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc
diff options
context:
space:
mode:
authoryoungki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-02 01:56:45 +0000
committeryoungki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-02 01:56:45 +0000
commitcc1bc719c2fd37e710a5cdf55f4559801b98d9ba (patch)
tree49fd64a8674e54904d886546acfce2f7b636d980 /chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc
parentac22933cf0a514c841856e6274df8f2000ae8203 (diff)
downloadchromium_src-cc1bc719c2fd37e710a5cdf55f4559801b98d9ba.zip
chromium_src-cc1bc719c2fd37e710a5cdf55f4559801b98d9ba.tar.gz
chromium_src-cc1bc719c2fd37e710a5cdf55f4559801b98d9ba.tar.bz2
Renames the classes in chrome/browser/chromeos/bluetooth/ ChromeOs-specific (i.e. BluetoothAdapter => BluetoothAdapterChromeOs) and creating interfaces: BluetoothAdapter and BluetoothDevice.
This CL does the Step 1 & 2 of: 1) Renames the classes in chrome/browser/chromeos/bluetooth/ chromeos-specific (i.e. BluetoothAdapter => BluetoothAdapterChromeOs) 2) Create interfaces of the classes in chrome/browser/chromeos/bluetooth/. These interfaces will be used in the platform-independent logics. 3) Move everything out of chrome/browser/chromeos/bluetooth/ into devices/bluetooth/ since the code is no longer specific to linux/chromeos. 4) Add Windows implementations. (i.e. Create BluetoothAdapterWindows) BUG=135470 Review URL: https://chromiumcodereview.appspot.com/10899037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc')
-rw-r--r--chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc b/chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc
new file mode 100644
index 0000000..f86f9c5
--- /dev/null
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.cc
@@ -0,0 +1,68 @@
+// 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_chromeos.h"
+
+#include <vector>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/rfcomm.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "base/logging.h"
+#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h"
+#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h"
+
+namespace chromeos {
+
+BluetoothSocketChromeOs::BluetoothSocketChromeOs(
+ const std::string& address, int fd)
+ : address_(address),
+ fd_(fd) {
+}
+
+BluetoothSocketChromeOs::~BluetoothSocketChromeOs() {
+ close(fd_);
+}
+
+// static
+scoped_refptr<BluetoothSocket> BluetoothSocketChromeOs::CreateBluetoothSocket(
+ const BluetoothServiceRecord& service_record) {
+ BluetoothSocketChromeOs* 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();
+ bluetooth_utils::str2ba(service_record.address(),
+ &socket_address.rc_bdaddr);
+
+ int status = connect(socket_fd, (struct sockaddr *)&socket_address,
+ sizeof(socket_address));
+ int errsv = errno;
+ if (status == 0 || errno == EINPROGRESS) {
+ bluetooth_socket = new BluetoothSocketChromeOs(service_record.address(),
+ socket_fd);
+ } else {
+ LOG(ERROR) << "Failed to connect bluetooth socket "
+ << "(" << service_record.address() << "): "
+ << "(" << errsv << ") " << strerror(errsv);
+ close(socket_fd);
+ }
+ }
+ // TODO(bryeung): add support for L2CAP sockets as well.
+
+ return scoped_refptr<BluetoothSocketChromeOs>(bluetooth_socket);
+}
+
+int BluetoothSocketChromeOs::fd() const {
+ return fd_;
+}
+
+} // namespace chromeos