bluetooth_profile_service_provider.h 4.7 KB

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