Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromeos / dbus / bluetooth_le_advertisement_service_provider.h
blob98622a2a1d658c23d18490c88a39046fe8d52cb3
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.
5 #ifndef CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
8 #include <stdint.h>
10 #include <map>
11 #include <string>
12 #include <vector>
14 #include "base/basictypes.h"
15 #include "base/callback.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "chromeos/chromeos_export.h"
18 #include "dbus/bus.h"
19 #include "dbus/file_descriptor.h"
20 #include "dbus/object_path.h"
22 namespace chromeos {
24 // BluetoothAdvertisementServiceProvider is used to provide a D-Bus object that
25 // the Bluetooth daemon can communicate with to advertise data.
26 class CHROMEOS_EXPORT BluetoothLEAdvertisementServiceProvider {
27 public:
28 using UUIDList = std::vector<std::string>;
29 using ManufacturerData = std::map<uint16_t, std::vector<uint8_t>>;
30 using ServiceData = std::map<std::string, std::vector<uint8_t>>;
32 // Type of advertisement.
33 enum AdvertisementType {
34 ADVERTISEMENT_TYPE_BROADCAST,
35 ADVERTISEMENT_TYPE_PERIPHERAL
38 // Interface for reacting to advertisement changes.
39 class Delegate {
40 public:
41 virtual ~Delegate() {}
43 // This method will be called when the advertisement is unregistered from
44 // the Bluetooth daemon, generally at shutdown or if the adapter goes away.
45 // It may be used to perform cleanup tasks. This corresponds to the
46 // org.bluez.LEAdvertisement1.Release method and is renamed to avoid a
47 // conflict with base::Refcounted<T>.
48 virtual void Released() = 0;
51 virtual ~BluetoothLEAdvertisementServiceProvider();
53 const dbus::ObjectPath& object_path() { return object_path_; }
55 // Creates the instance where |bus| is the D-Bus bus connection to export
56 // the object onto, |object_path| is the object path that it should have
57 // and |delegate| is the object to which all method calls will be passed
58 // and responses generated from.
59 static scoped_ptr<BluetoothLEAdvertisementServiceProvider> Create(
60 dbus::Bus* bus,
61 const dbus::ObjectPath& object_path,
62 Delegate* delegate,
63 AdvertisementType type,
64 scoped_ptr<UUIDList> service_uuids,
65 scoped_ptr<ManufacturerData> manufacturer_data,
66 scoped_ptr<UUIDList> solicit_uuids,
67 scoped_ptr<ServiceData> service_data);
69 protected:
70 BluetoothLEAdvertisementServiceProvider();
72 // D-Bus object path of object we are exporting, kept so we can unregister
73 // again in our destructor.
74 dbus::ObjectPath object_path_;
76 private:
77 DISALLOW_COPY_AND_ASSIGN(BluetoothLEAdvertisementServiceProvider);
80 } // namespace chromeos
82 #endif // CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_