Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / device / bluetooth / bluetooth_profile.h
blob30f2a1a0a36cbeaed2861058ddbda869b548ae29
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_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "device/bluetooth/bluetooth_uuid.h"
14 namespace device {
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
23 // standards).
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
32 // pointers to them.
33 class BluetoothProfile {
34 public:
35 // Options used to register a BluetoothProfile object.
36 struct Options {
37 Options();
38 ~Options();
40 // Human readable name of the Profile, e.g. "Health Device".
41 // Exported in the adapter's SDP or GATT tables where relevant.
42 std::string name;
44 // RFCOMM channel used by the profile.
45 // Exported in the adapter's SDP or GATT tables where relevant.
46 uint16 channel;
48 // L2CAP PSM number.
49 // Exported in the adapter's SDP or GATT tables where relevant.
50 uint16 psm;
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.
57 // Defaults to false.
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.
62 // Defaults to false.
63 bool auto_connect;
65 // Implemented version of the profile.
66 // Exported in the adapter's SDP or GATT tables where relevant.
67 uint16 version;
69 // Implemented feature set of the profile.
70 // Exported in the adapter's SDP or GATT tables where relevant.
71 uint16 features;
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
93 // to this callback.
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;
103 protected:
104 BluetoothProfile();
105 virtual ~BluetoothProfile();
108 } // namespace device
110 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_