blob: 4ff2480c21d336171cca3335d9819f7375e840e1 [file] [log] [blame]
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +01001// 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.
4
5#ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_
6#define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_
7
8#include <string>
9
10#include "base/callback.h"
11#include "base/memory/ref_counted.h"
12
13namespace device {
14
15class BluetoothDevice;
16class BluetoothProfileMac;
17class BluetoothSocket;
18class MockBluetoothProfile;
19
20// BluetoothProfile represents an implementation of either a client or server
21// of a particular specified profile (aka service or protocol in other
22// standards).
23//
24// Profile implementations are created by registering them through the static
25// BluetoothProfile::Register() method and are always identified by a UUID
26// which in any method may be specified in the short or long form.
27//
28// The lifecycle of BluetoothProfile instances is managed by the implementation
29// but they are guaranteed to exist once provided to a Register() callback until
30// the instance's Unregister() method is called, so others may hold on to
31// pointers to them.
32class BluetoothProfile {
33 public:
34 // Options used to register a BluetoothProfile object.
35 struct Options {
36 Options();
37 ~Options();
38
39 // Human readable name of the Profile, e.g. "Health Device".
40 // Exported in the adapter's SDP or GATT tables where relevant.
41 std::string name;
42
43 // RFCOMM channel used by the profile.
44 // Exported in the adapter's SDP or GATT tables where relevant.
45 uint16 channel;
46
47 // L2CAP PSM number.
48 // Exported in the adapter's SDP or GATT tables where relevant.
49 uint16 psm;
50
51 // Specifies whether pairing (and encryption) is required to be able to
52 // connect. Defaults to false.
53 bool require_authentication;
54
55 // Specifies whether user authorization is required to be able to connect.
56 // Defaults to false.
57 bool require_authorization;
58
59 // Specifies whether this profile will be automatically connected if any
60 // other profile of a device conects to the host.
61 // Defaults to false.
62 bool auto_connect;
63
64 // Implemented version of the profile.
65 // Exported in the adapter's SDP or GATT tables where relevant.
66 uint16 version;
67
68 // Implemented feature set of the profile.
69 // Exported in the adapter's SDP or GATT tables where relevant.
70 uint16 features;
71 };
72
73 // Register an implementation of the profile with UUID |uuid| and
74 // additional details specified in |options|. The corresponding profile
75 // object will be created and returned by |callback|. If the profile cannot
76 // be registered, NULL will be passed.
77 //
78 // This pointer is not owned by the receiver, but will not be freed unless
79 // its Unregister() method is called.
80 typedef base::Callback<void(BluetoothProfile*)> ProfileCallback;
81 static void Register(const std::string& uuid,
82 const Options& options,
83 const ProfileCallback& callback);
84
85 // Unregister the profile. This deletes the profile object so, once called,
86 // any pointers to the profile should be discarded.
87 virtual void Unregister() = 0;
88
89 // Set the connection callback for the profile to |callback|, any successful
90 // connection initiated by BluetoothDevice::ConnectToProfile() or incoming
91 // connections from devices, will have a BluetoothSocket created and passed
92 // to this callback.
93 //
94 // The socket will be closed when all references are released; none of the
95 // BluetoothProfile, or BluetoothAdapter or BluetoothDevice objects are
96 // guaranteed to hold a reference so this may outlive all of them.
97 typedef base::Callback<void(
98 const BluetoothDevice*,
99 scoped_refptr<BluetoothSocket>)> ConnectionCallback;
100 virtual void SetConnectionCallback(const ConnectionCallback& callback) = 0;
101
102 protected:
103 BluetoothProfile();
104 virtual ~BluetoothProfile();
105};
106
107} // namespace device
108
109#endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_H_