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 CHROMEOS_DBUS_EXPERIMENTAL_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
6 #define CHROMEOS_DBUS_EXPERIMENTAL_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
14 #include "dbus/file_descriptor.h"
15 #include "dbus/object_path.h"
19 // ExperimentalBluetoothProfileServiceProvider is used to provide a D-Bus
20 // object that BlueZ can communicate with to connect application profiles.
22 // Instantiate with a chosen D-Bus object path and delegate object, and pass
23 // the D-Bus object path as the |agent_path| argument to the
24 // chromeos::ExperimentalBluetoothProfileManagerClient::RegisterProfile()
27 // When an incoming profile connection occurs, or after initiating a connection
28 // using the chromeos::ExperimentalBluetoothDeviceClient::ConnectProfile()
29 // method, the Bluetooth daemon will make calls to this profile object and they
30 // will be passed on to your Delegate object for handling. Responses should be
31 // returned using the callbacks supplied to those methods.
32 class CHROMEOS_EXPORT ExperimentalBluetoothProfileServiceProvider
{
34 // Interface for reacting to profile requests.
37 virtual ~Delegate() {}
39 // Possible status values that may be returned to callbacks on a new
40 // connection or a requested disconnection. Success indicates acceptance,
41 // reject indicates the user rejected or denied the request; cancelled
42 // means the user cancelled the request without confirming either way.
49 // Connection-specific options.
50 struct CHROMEOS_EXPORT Options
{
61 // The ConfirmationCallback is used for methods which require confirmation;
62 // it should be called with one argument, the |status| of the request
63 // (success, rejected or cancelled).
64 typedef base::Callback
<void(Status
)> ConfirmationCallback
;
66 // This method will be called when the profile is unregistered from the
67 // Bluetooth daemon, generally at shutdown or at the applications' request.
68 // It may be used to perform cleanup tasks.
69 virtual void Release() = 0;
71 // This method will be called when a profile connection to the device
72 // with object path |device_path| is established. |callback| must be called
73 // to confirm the connection, or indicate rejection or cancellation.
75 // A file descriptor for the connection socket is provided in |fd|, and
76 // details about the specific implementation of the profile in |options|.
77 // The delegate should take the value and ownership
79 // The file descriptor is owned by the delegate after this call so must be
80 // cleaned up if the connection is cancelled or rejected, the |options|
81 // structure is not so information out of it must be copied if required.
82 virtual void NewConnection(const dbus::ObjectPath
& device_path
,
83 dbus::FileDescriptor
* fd
,
84 const Options
& options
,
85 const ConfirmationCallback
& callback
) = 0;
87 // This method will be called when a profile connection to the device
88 // with object path |device_path| is disconnected. Any file descriptors
89 // owned by the service should be cleaned up and |callback| called to
90 // confirm, or indicate rejection or cancellation of the disconnection.
91 virtual void RequestDisconnection(const dbus::ObjectPath
& device_path
,
92 const ConfirmationCallback
& callback
) = 0;
94 // This method will be called by the Bluetooth daemon to indicate that
95 // a profile request failed before a reply was returned from the device.
96 virtual void Cancel() = 0;
99 virtual ~ExperimentalBluetoothProfileServiceProvider();
101 // Creates the instance where |bus| is the D-Bus bus connection to export
102 // the object onto, |object_path| is the object path that it should have
103 // and |delegate| is the object to which all method calls will be passed
104 // and responses generated from.
105 static ExperimentalBluetoothProfileServiceProvider
* Create(
106 dbus::Bus
* bus
, const dbus::ObjectPath
& object_path
, Delegate
* delegate
);
109 ExperimentalBluetoothProfileServiceProvider();
112 DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothProfileServiceProvider
);
115 } // namespace chromeos
117 #endif // CHROMEOS_DBUS_EXPERIMENTAL_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_