bluetooth_le_advertisement_service_provider.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2015 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_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
  5. #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
  6. #include <stdint.h>
  7. #include <map>
  8. #include <memory>
  9. #include <string>
  10. #include <vector>
  11. #include "base/callback.h"
  12. #include "dbus/bus.h"
  13. #include "dbus/object_path.h"
  14. #include "device/bluetooth/bluetooth_export.h"
  15. namespace bluez {
  16. // BluetoothAdvertisementServiceProvider is used to provide a D-Bus object that
  17. // the Bluetooth daemon can communicate with to advertise data.
  18. class DEVICE_BLUETOOTH_EXPORT BluetoothLEAdvertisementServiceProvider {
  19. public:
  20. using UUIDList = std::vector<std::string>;
  21. using ManufacturerData = std::map<uint16_t, std::vector<uint8_t>>;
  22. using ServiceData = std::map<std::string, std::vector<uint8_t>>;
  23. using ScanResponseData = std::map<uint8_t, std::vector<uint8_t>>;
  24. // Type of advertisement.
  25. enum AdvertisementType {
  26. ADVERTISEMENT_TYPE_BROADCAST,
  27. ADVERTISEMENT_TYPE_PERIPHERAL
  28. };
  29. // Interface for reacting to advertisement changes.
  30. class Delegate {
  31. public:
  32. virtual ~Delegate() {}
  33. // This method will be called when the advertisement is unregistered from
  34. // the Bluetooth daemon, generally at shutdown or if the adapter goes away.
  35. // It may be used to perform cleanup tasks. This corresponds to the
  36. // org.bluez.LEAdvertisement1.Release method and is renamed to avoid a
  37. // conflict with base::Refcounted<T>.
  38. virtual void Released() = 0;
  39. };
  40. BluetoothLEAdvertisementServiceProvider(
  41. const BluetoothLEAdvertisementServiceProvider&) = delete;
  42. BluetoothLEAdvertisementServiceProvider& operator=(
  43. const BluetoothLEAdvertisementServiceProvider&) = delete;
  44. virtual ~BluetoothLEAdvertisementServiceProvider();
  45. const dbus::ObjectPath& object_path() { return object_path_; }
  46. // Creates the instance where |bus| is the D-Bus bus connection to export
  47. // the object onto, |object_path| is the object path that it should have
  48. // and |delegate| is the object to which all method calls will be passed
  49. // and responses generated from.
  50. static std::unique_ptr<BluetoothLEAdvertisementServiceProvider> Create(
  51. dbus::Bus* bus,
  52. const dbus::ObjectPath& object_path,
  53. Delegate* delegate,
  54. AdvertisementType type,
  55. std::unique_ptr<UUIDList> service_uuids,
  56. std::unique_ptr<ManufacturerData> manufacturer_data,
  57. std::unique_ptr<UUIDList> solicit_uuids,
  58. std::unique_ptr<ServiceData> service_data,
  59. std::unique_ptr<ScanResponseData> scan_response_data);
  60. protected:
  61. BluetoothLEAdvertisementServiceProvider();
  62. // D-Bus object path of object we are exporting, kept so we can unregister
  63. // again in our destructor.
  64. dbus::ObjectPath object_path_;
  65. };
  66. } // namespace bluez
  67. #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_