Commit 2862df46 authored by keybuk@chromium.org's avatar keybuk@chromium.org

Add abstract BluetoothProfile class

This class will form the base of the 4.0 BR+LE compatible API,
allowing for both incoming connections for profiles we're clients
for and implementing services within Chrome.

BUG=229636
TEST=none

Review URL: https://chromiumcodereview.appspot.com/13862023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195280 0039d316-1c4b-4281-b951-d872f2087c98
parent 79f92dfa
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
namespace device { namespace device {
class BluetoothProfile;
class BluetoothServiceRecord; class BluetoothServiceRecord;
class BluetoothSocket; class BluetoothSocket;
...@@ -318,6 +319,12 @@ class BluetoothDevice { ...@@ -318,6 +319,12 @@ class BluetoothDevice {
virtual void ConnectToService(const std::string& service_uuid, virtual void ConnectToService(const std::string& service_uuid,
const SocketCallback& callback) = 0; const SocketCallback& callback) = 0;
// Attempts to initiate an outgoing connection to this device for the profile
// identified by |profile|, on success the profile's connection callback
// wil be called; on failure |error_callback| will be called.
virtual void ConnectToProfile(BluetoothProfile* profile,
const ErrorCallback& error_callback) = 0;
// Sets the Out Of Band pairing data for this device to |data|. Exactly one // Sets the Out Of Band pairing data for this device to |data|. Exactly one
// of |callback| or |error_callback| will be run. // of |callback| or |error_callback| will be run.
virtual void SetOutOfBandPairingData( virtual void SetOutOfBandPairingData(
......
...@@ -325,6 +325,12 @@ void BluetoothDeviceChromeOS::ConnectToService(const std::string& service_uuid, ...@@ -325,6 +325,12 @@ void BluetoothDeviceChromeOS::ConnectToService(const std::string& service_uuid,
callback)); callback));
} }
void BluetoothDeviceChromeOS::ConnectToProfile(
device::BluetoothProfile* profile,
const ErrorCallback& error_callback) {
// TODO(keybuk): implement
}
void BluetoothDeviceChromeOS::SetOutOfBandPairingData( void BluetoothDeviceChromeOS::SetOutOfBandPairingData(
const BluetoothOutOfBandPairingData& data, const BluetoothOutOfBandPairingData& data,
const base::Closure& callback, const base::Closure& callback,
......
...@@ -71,6 +71,9 @@ class BluetoothDeviceChromeOS ...@@ -71,6 +71,9 @@ class BluetoothDeviceChromeOS
virtual void ConnectToService( virtual void ConnectToService(
const std::string& service_uuid, const std::string& service_uuid,
const SocketCallback& callback) OVERRIDE; const SocketCallback& callback) OVERRIDE;
virtual void ConnectToProfile(
device::BluetoothProfile* profile,
const ErrorCallback& error_callback) OVERRIDE;
virtual void SetOutOfBandPairingData( virtual void SetOutOfBandPairingData(
const device::BluetoothOutOfBandPairingData& data, const device::BluetoothOutOfBandPairingData& data,
const base::Closure& callback, const base::Closure& callback,
......
...@@ -257,6 +257,13 @@ void BluetoothDeviceExperimentalChromeOS::ConnectToService( ...@@ -257,6 +257,13 @@ void BluetoothDeviceExperimentalChromeOS::ConnectToService(
callback.Run(scoped_refptr<device::BluetoothSocket>()); callback.Run(scoped_refptr<device::BluetoothSocket>());
} }
void BluetoothDeviceExperimentalChromeOS::ConnectToProfile(
device::BluetoothProfile* profile,
const ErrorCallback& error_callback) {
// TODO(keybuk): implement
error_callback.Run();
}
void BluetoothDeviceExperimentalChromeOS::SetOutOfBandPairingData( void BluetoothDeviceExperimentalChromeOS::SetOutOfBandPairingData(
const device::BluetoothOutOfBandPairingData& data, const device::BluetoothOutOfBandPairingData& data,
const base::Closure& callback, const base::Closure& callback,
......
...@@ -58,6 +58,9 @@ class BluetoothDeviceExperimentalChromeOS ...@@ -58,6 +58,9 @@ class BluetoothDeviceExperimentalChromeOS
virtual void ConnectToService( virtual void ConnectToService(
const std::string& service_uuid, const std::string& service_uuid,
const SocketCallback& callback) OVERRIDE; const SocketCallback& callback) OVERRIDE;
virtual void ConnectToProfile(
device::BluetoothProfile* profile,
const ErrorCallback& error_callback) OVERRIDE;
virtual void SetOutOfBandPairingData( virtual void SetOutOfBandPairingData(
const device::BluetoothOutOfBandPairingData& data, const device::BluetoothOutOfBandPairingData& data,
const base::Closure& callback, const base::Closure& callback,
......
...@@ -55,6 +55,9 @@ class BluetoothDeviceMac : public BluetoothDevice { ...@@ -55,6 +55,9 @@ class BluetoothDeviceMac : public BluetoothDevice {
virtual void ConnectToService( virtual void ConnectToService(
const std::string& service_uuid, const std::string& service_uuid,
const SocketCallback& callback) OVERRIDE; const SocketCallback& callback) OVERRIDE;
virtual void ConnectToProfile(
device::BluetoothProfile* profile,
const ErrorCallback& error_callback) OVERRIDE;
virtual void SetOutOfBandPairingData( virtual void SetOutOfBandPairingData(
const BluetoothOutOfBandPairingData& data, const BluetoothOutOfBandPairingData& data,
const base::Closure& callback, const base::Closure& callback,
......
...@@ -196,6 +196,12 @@ void BluetoothDeviceMac::ConnectToService( ...@@ -196,6 +196,12 @@ void BluetoothDeviceMac::ConnectToService(
} }
} }
void BluetoothDeviceMac::ConnectToProfile(
device::BluetoothProfile* profile,
const ErrorCallback& error_callback) {
// TODO(keybuk): implement
}
void BluetoothDeviceMac::SetOutOfBandPairingData( void BluetoothDeviceMac::SetOutOfBandPairingData(
const BluetoothOutOfBandPairingData& data, const BluetoothOutOfBandPairingData& data,
const base::Closure& callback, const base::Closure& callback,
......
...@@ -181,6 +181,12 @@ void BluetoothDeviceWin::ConnectToService( ...@@ -181,6 +181,12 @@ void BluetoothDeviceWin::ConnectToService(
} }
} }
void BluetoothDeviceWin::ConnectToProfile(
device::BluetoothProfile* profile,
const ErrorCallback& error_callback) {
// TODO(keybuk): implement
}
void BluetoothDeviceWin::SetOutOfBandPairingData( void BluetoothDeviceWin::SetOutOfBandPairingData(
const BluetoothOutOfBandPairingData& data, const BluetoothOutOfBandPairingData& data,
const base::Closure& callback, const base::Closure& callback,
......
...@@ -54,6 +54,9 @@ class BluetoothDeviceWin : public BluetoothDevice { ...@@ -54,6 +54,9 @@ class BluetoothDeviceWin : public BluetoothDevice {
virtual void ConnectToService( virtual void ConnectToService(
const std::string& service_uuid, const std::string& service_uuid,
const SocketCallback& callback) OVERRIDE; const SocketCallback& callback) OVERRIDE;
virtual void ConnectToProfile(
device::BluetoothProfile* profile,
const ErrorCallback& error_callback) OVERRIDE;
virtual void SetOutOfBandPairingData( virtual void SetOutOfBandPairingData(
const BluetoothOutOfBandPairingData& data, const BluetoothOutOfBandPairingData& data,
const base::Closure& callback, const base::Closure& callback,
......
// Copyright (c) 2013 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 "device/bluetooth/bluetooth_profile.h"
#include <string>
namespace device {
BluetoothProfile::Options::Options()
: channel(0),
psm(0),
require_authentication(false),
require_authorization(false),
version(0),
features(0) {
}
BluetoothProfile::Options::~Options() {
}
BluetoothProfile::BluetoothProfile() {
}
BluetoothProfile::~BluetoothProfile() {
}
// static
void BluetoothProfile::Register(const std::string& uuid,
const Options& options,
const ProfileCallback& callback) {
// TODO(keybuk): Implement selection of the appropriate BluetoothProfile
// subclass just like BluetoothAdapterFactory
callback.Run(NULL);
}
} // namespace device
// Copyright (c) 2013 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.
#ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_
#include <string>
#include "base/callback.h"
#include "base/memory/ref_counted.h"
namespace device {
class BluetoothSocket;
// BluetoothProfile represents an implementation of either a client or server
// of a particular specified profile (aka service or protocol in other
// standards).
//
// Profile implementations are created by registering them through the static
// BluetoothProfile::Register() method and are always identified by a UUID
// which in any method may be specified in the short or long form.
//
// The lifecycle of BluetoothProfile instances is managed by the implementation
// but they are guaranteed to exist once provided to a Register() callback until
// the instance's Unregister() method is called, so others may hold on to
// pointers to them.
class BluetoothProfile {
public:
// Options used to register a BluetoothProfile object.
struct Options {
Options();
~Options();
// Human readable name of the Profile, e.g. "Health Device".
// Exported in the adapter's SDP or GATT tables where relevant.
std::string name;
// RFCOMM channel used by the profile.
// Exported in the adapter's SDP or GATT tables where relevant.
uint16 channel;
// L2CAP PSM number.
// Exported in the adapter's SDP or GATT tables where relevant.
uint16 psm;
// Specifies whether pairing (and encryption) is required to be able to
// connect. Defaults to false.
bool require_authentication;
// Specifies whether user authorization is required to be able to connect.
// Defaults to false.
bool require_authorization;
// Implemented version of the profile.
// Exported in the adapter's SDP or GATT tables where relevant.
uint16 version;
// Implemented feature set of the profile.
// Exported in the adapter's SDP or GATT tables where relevant.
uint16 features;
};
// Register an implementation of the profile with UUID |uuid| and
// additional details specified in |options|. The corresponding profile
// object will be created and returned by |callback|. If the profile cannot
// be registered, NULL will be passed.
//
// This pointer is not owned by the receiver, but will not be freed unless
// its Unregister() method is called.
typedef base::Callback<void(BluetoothProfile*)> ProfileCallback;
static void Register(const std::string& uuid,
const Options& options,
const ProfileCallback& callback);
// Unregister the profile. This deletes the profile object so, once called,
// any pointers to the profile should be discarded.
virtual void Unregister() = 0;
// Set the connection callback for the profile to |callback|, any successful
// connection initiated by BluetoothDevice::ConnectToProfile() or incoming
// connections from devices, will have a BluetoothSocket created and passed
// to this callback.
//
// The socket will be closed when all references are released; none of the
// BluetoothProfile, or BluetoothAdapter or BluetoothDevice objects are
// guaranteed to hold a reference so this may outlive all of them.
typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> SocketCallback;
virtual void SetConnectionCallback(const SocketCallback& callback) = 0;
private:
BluetoothProfile();
virtual ~BluetoothProfile();
};
} // namespace device
#endif /* DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_ */
...@@ -47,7 +47,7 @@ class MockBluetoothDevice : public BluetoothDevice { ...@@ -47,7 +47,7 @@ class MockBluetoothDevice : public BluetoothDevice {
MOCK_CONST_METHOD0(ExpectingPasskey, bool()); MOCK_CONST_METHOD0(ExpectingPasskey, bool());
MOCK_CONST_METHOD0(ExpectingConfirmation, bool()); MOCK_CONST_METHOD0(ExpectingConfirmation, bool());
MOCK_METHOD3(Connect, MOCK_METHOD3(Connect,
void(BluetoothDevice::PairingDelegate* pairnig_delegate, void(BluetoothDevice::PairingDelegate* pairing_delegate,
const base::Closure& callback, const base::Closure& callback,
const BluetoothDevice::ConnectErrorCallback& const BluetoothDevice::ConnectErrorCallback&
error_callback)); error_callback));
...@@ -63,6 +63,9 @@ class MockBluetoothDevice : public BluetoothDevice { ...@@ -63,6 +63,9 @@ class MockBluetoothDevice : public BluetoothDevice {
MOCK_METHOD2(ConnectToService, MOCK_METHOD2(ConnectToService,
void(const std::string&, void(const std::string&,
const BluetoothDevice::SocketCallback&)); const BluetoothDevice::SocketCallback&));
MOCK_METHOD2(ConnectToProfile,
void(BluetoothProfile*,
const BluetoothDevice::ErrorCallback&));
MOCK_METHOD3(SetOutOfBandPairingData, MOCK_METHOD3(SetOutOfBandPairingData,
void(const BluetoothOutOfBandPairingData& data, void(const BluetoothOutOfBandPairingData& data,
......
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
'bluetooth/bluetooth_init_win.cc', 'bluetooth/bluetooth_init_win.cc',
'bluetooth/bluetooth_init_win.h', 'bluetooth/bluetooth_init_win.h',
'bluetooth/bluetooth_out_of_band_pairing_data.h', 'bluetooth/bluetooth_out_of_band_pairing_data.h',
'bluetooth/bluetooth_profile.cc',
'bluetooth/bluetooth_profile.h',
'bluetooth/bluetooth_service_record.cc', 'bluetooth/bluetooth_service_record.cc',
'bluetooth/bluetooth_service_record.h', 'bluetooth/bluetooth_service_record.h',
'bluetooth/bluetooth_service_record_chromeos.cc', 'bluetooth/bluetooth_service_record_chromeos.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment