OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 |
| 5 #ifndef DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_APPLICATION_SERVICE_PROVIDER_IMPL_H
_ |
| 6 #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_APPLICATION_SERVICE_PROVIDER_IMPL_H
_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/platform_thread.h" |
| 16 #include "dbus/bus.h" |
| 17 #include "dbus/exported_object.h" |
| 18 #include "dbus/message.h" |
| 19 #include "dbus/object_path.h" |
| 20 #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h" |
| 21 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h" |
| 22 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider.h
" |
| 23 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.h" |
| 24 #include "device/bluetooth/dbus/bluetooth_gatt_service_service_provider.h" |
| 25 |
| 26 namespace bluez { |
| 27 |
| 28 class BluetoothLocalGattServiceBlueZ; |
| 29 |
| 30 // The BluetoothGattApplicationServiceProvider implementation used in |
| 31 // production. |
| 32 class BluetoothGattApplicationServiceProviderImpl |
| 33 : public BluetoothGattApplicationServiceProvider { |
| 34 public: |
| 35 BluetoothGattApplicationServiceProviderImpl( |
| 36 dbus::Bus* bus, |
| 37 const dbus::ObjectPath& object_path, |
| 38 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& |
| 39 services); |
| 40 ~BluetoothGattApplicationServiceProviderImpl() override; |
| 41 |
| 42 private: |
| 43 // Returns true if the current thread is on the origin thread. |
| 44 bool OnOriginThread(); |
| 45 |
| 46 template <typename Attribute> |
| 47 void WriteObjectStruct(dbus::MessageWriter* writer, |
| 48 const std::string& attribute_interface, |
| 49 Attribute* attribute); |
| 50 template <typename Attribute> |
| 51 void WriteInterfaceStruct(dbus::MessageWriter* writer, |
| 52 const std::string& attribute_interface, |
| 53 Attribute* attribute); |
| 54 |
| 55 void WriteAttributeProperties( |
| 56 dbus::MessageWriter* writer, |
| 57 BluetoothGattServiceServiceProvider* service_provider); |
| 58 void WriteAttributeProperties( |
| 59 dbus::MessageWriter* writer, |
| 60 BluetoothGattCharacteristicServiceProvider* characteristic_provider); |
| 61 void WriteAttributeProperties( |
| 62 dbus::MessageWriter* writer, |
| 63 BluetoothGattDescriptorServiceProvider* descriptor_provider); |
| 64 |
| 65 // Called by dbus:: when the Bluetooth daemon wants to fetch all the objects |
| 66 // managed by this object manager. |
| 67 void GetManagedObjects(dbus::MethodCall* method_call, |
| 68 dbus::ExportedObject::ResponseSender response_sender); |
| 69 |
| 70 // Called by dbus:: when a method is exported. |
| 71 void OnExported(const std::string& interface_name, |
| 72 const std::string& method_name, |
| 73 bool success); |
| 74 |
| 75 // Origin thread (i.e. the UI thread in production). |
| 76 base::PlatformThreadId origin_thread_id_; |
| 77 |
| 78 // List of GATT Service service providers managed by this object manager. |
| 79 std::vector<std::unique_ptr<BluetoothGattServiceServiceProvider>> |
| 80 service_providers_; |
| 81 // List of GATT Characteristic service providers managed by this object |
| 82 // manager. |
| 83 std::vector<std::unique_ptr<BluetoothGattCharacteristicServiceProvider>> |
| 84 characteristic_providers_; |
| 85 // List of GATT Descriptor service providers managed by this object manager. |
| 86 std::vector<std::unique_ptr<BluetoothGattDescriptorServiceProvider>> |
| 87 descriptor_providers_; |
| 88 |
| 89 // D-Bus bus object is exported on, not owned by this object and must |
| 90 // outlive it. |
| 91 dbus::Bus* bus_; |
| 92 |
| 93 // D-Bus object path of object we are exporting, kept so we can unregister |
| 94 // again in our destructor. |
| 95 dbus::ObjectPath object_path_; |
| 96 |
| 97 // D-Bus object we are exporting, owned by this object. |
| 98 scoped_refptr<dbus::ExportedObject> exported_object_; |
| 99 |
| 100 // Weak pointer factory for generating 'this' pointers that might live longer |
| 101 // than we do. |
| 102 // Note: This should remain the last member so it'll be destroyed and |
| 103 // invalidate its weak pointers before any other members are destroyed. |
| 104 base::WeakPtrFactory<BluetoothGattApplicationServiceProviderImpl> |
| 105 weak_ptr_factory_; |
| 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(BluetoothGattApplicationServiceProviderImpl); |
| 108 }; |
| 109 |
| 110 } // namespace bluez |
| 111 |
| 112 #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_APPLICATION_SERVICE_PROVIDER_IMP
L_H_ |
OLD | NEW |