1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "device/bluetooth/bluetooth_uuid.h"
16 class BluetoothDevice
;
17 class BluetoothProfileMac
;
18 class BluetoothSocket
;
19 class MockBluetoothProfile
;
21 // BluetoothProfile represents an implementation of either a client or server
22 // of a particular specified profile (aka service or protocol in other
25 // Profile implementations are created by registering them through the static
26 // BluetoothProfile::Register() method and are always identified by a UUID
27 // which in any method may be specified in the short or long form.
29 // The lifecycle of BluetoothProfile instances is managed by the implementation
30 // but they are guaranteed to exist once provided to a Register() callback until
31 // the instance's Unregister() method is called, so others may hold on to
33 class BluetoothProfile
{
35 // Options used to register a BluetoothProfile object.
40 // Human readable name of the Profile, e.g. "Health Device".
41 // Exported in the adapter's SDP or GATT tables where relevant.
44 // RFCOMM channel used by the profile.
45 // Exported in the adapter's SDP or GATT tables where relevant.
49 // Exported in the adapter's SDP or GATT tables where relevant.
52 // Specifies whether pairing (and encryption) is required to be able to
53 // connect. Defaults to false.
54 bool require_authentication
;
56 // Specifies whether user authorization is required to be able to connect.
58 bool require_authorization
;
60 // Specifies whether this profile will be automatically connected if any
61 // other profile of a device conects to the host.
65 // Implemented version of the profile.
66 // Exported in the adapter's SDP or GATT tables where relevant.
69 // Implemented feature set of the profile.
70 // Exported in the adapter's SDP or GATT tables where relevant.
74 // Register an implementation of the profile with UUID |uuid| and
75 // additional details specified in |options|. The corresponding profile
76 // object will be created and returned by |callback|. If the profile cannot
77 // be registered, NULL will be passed.
79 // This pointer is not owned by the receiver, but will not be freed unless
80 // its Unregister() method is called.
81 typedef base::Callback
<void(BluetoothProfile
*)> ProfileCallback
;
82 static void Register(const BluetoothUUID
& uuid
,
83 const Options
& options
,
84 const ProfileCallback
& callback
);
86 // Unregister the profile. This deletes the profile object so, once called,
87 // any pointers to the profile should be discarded.
88 virtual void Unregister() = 0;
90 // Set the connection callback for the profile to |callback|, any successful
91 // connection initiated by BluetoothDevice::ConnectToProfile() or incoming
92 // connections from devices, will have a BluetoothSocket created and passed
95 // The socket will be closed when all references are released; none of the
96 // BluetoothProfile, or BluetoothAdapter or BluetoothDevice objects are
97 // guaranteed to hold a reference so this may outlive all of them.
98 typedef base::Callback
<void(
99 const BluetoothDevice
*,
100 scoped_refptr
<BluetoothSocket
>)> ConnectionCallback
;
101 virtual void SetConnectionCallback(const ConnectionCallback
& callback
) = 0;
105 virtual ~BluetoothProfile();
108 } // namespace device
110 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_