1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Copyright 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_DBUS_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
#define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "dbus/bus.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"
#include "device/bluetooth/bluetooth_export.h"
namespace bluez {
// BluetoothProfileServiceProvider is used to provide a D-Bus object that the
// Bluetooth daemon can communicate with to connect application profiles.
//
// Instantiate with a chosen D-Bus object path and delegate object, and pass
// the D-Bus object path as the |agent_path| argument to the
// bluez::BluetoothProfileManagerClient::RegisterProfile() method.
//
// When an incoming profile connection occurs, or after initiating a connection
// using the bluez::BluetoothDeviceClient::ConnectProfile() method, the
// Bluetooth daemon will make calls to this profile object and they will be
// passed on to your Delegate object for handling. Responses should be returned
// using the callbacks supplied to those methods.
class DEVICE_BLUETOOTH_EXPORT BluetoothProfileServiceProvider {
public:
// Interface for reacting to profile requests.
class Delegate {
public:
virtual ~Delegate() {}
// Possible status values that may be returned to callbacks on a new
// connection or a requested disconnection. Success indicates acceptance,
// reject indicates the user rejected or denied the request; cancelled
// means the user cancelled the request without confirming either way.
enum Status { SUCCESS, REJECTED, CANCELLED };
// Connection-specific options.
struct DEVICE_BLUETOOTH_EXPORT Options {
Options() {}
~Options() {}
// Profile version.
uint16 version;
// Profile features.
uint16 features;
};
// The ConfirmationCallback is used for methods which require confirmation;
// it should be called with one argument, the |status| of the request
// (success, rejected or cancelled).
typedef base::Callback<void(Status)> ConfirmationCallback;
// This method will be called when the profile is unregistered from the
// Bluetooth daemon, generally at shutdown or at the applications' request.
// It may be used to perform cleanup tasks. This corresponds to the
// org.bluez.Profile1.Release method and is renamed to avoid a conflict
// with base::Refcounted<T>.
virtual void Released() = 0;
// This method will be called when a profile connection to the device
// with object path |device_path| is established. |callback| must be called
// to confirm the connection, or indicate rejection or cancellation.
//
// A file descriptor for the connection socket is provided in |fd|, and
// details about the specific implementation of the profile in |options|.
//
// IMPORTANT: Ownership of the file descriptor object |fd| is passed to
// the delegate by this call. The delegate is responsible for checking the
// validity of |fd| on a thread where I/O is permitted before taking the
// value. If the value is not taken, the file descriptor is closed.
//
// Ownership of |options| is NOT passed so information out of it must be
// copied if required.
virtual void NewConnection(const dbus::ObjectPath& device_path,
scoped_ptr<dbus::FileDescriptor> fd,
const Options& options,
const ConfirmationCallback& callback) = 0;
// This method will be called when a profile connection to the device
// with object path |device_path| is disconnected. Any file descriptors
// owned by the service should be cleaned up and |callback| called to
// confirm, or indicate rejection or cancellation of the disconnection.
virtual void RequestDisconnection(const dbus::ObjectPath& device_path,
const ConfirmationCallback& callback) = 0;
// This method will be called by the Bluetooth daemon to indicate that
// a profile request failed before a reply was returned from the device.
virtual void Cancel() = 0;
};
virtual ~BluetoothProfileServiceProvider();
// Creates the instance where |bus| is the D-Bus bus connection to export
// the object onto, |object_path| is the object path that it should have
// and |delegate| is the object to which all method calls will be passed
// and responses generated from.
static BluetoothProfileServiceProvider* Create(
dbus::Bus* bus,
const dbus::ObjectPath& object_path,
Delegate* delegate);
protected:
BluetoothProfileServiceProvider();
private:
DISALLOW_COPY_AND_ASSIGN(BluetoothProfileServiceProvider);
};
} // namespace bluez
#endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
|