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_DESCRIPTOR_SERVICE_PROVIDER_IMPL_H_ |
| 6 #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_DESCRIPTOR_SERVICE_PROVIDER_IMPL_H_ |
| 7 |
| 8 #include <stdint.h> |
| 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/dbus/bluetooth_gatt_attribute_value_delegate.h" |
| 21 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.h" |
| 22 |
| 23 namespace bluez { |
| 24 |
| 25 // The BluetoothGattDescriptorServiceProvider implementation used in production. |
| 26 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptorServiceProviderImpl |
| 27 : public BluetoothGattDescriptorServiceProvider { |
| 28 public: |
| 29 BluetoothGattDescriptorServiceProviderImpl( |
| 30 dbus::Bus* bus, |
| 31 const dbus::ObjectPath& object_path, |
| 32 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate, |
| 33 const std::string& uuid, |
| 34 const std::vector<std::string>& permissions, |
| 35 const dbus::ObjectPath& characteristic_path); |
| 36 ~BluetoothGattDescriptorServiceProviderImpl() override; |
| 37 |
| 38 // For testing. |
| 39 BluetoothGattDescriptorServiceProviderImpl( |
| 40 const dbus::ObjectPath& object_path, |
| 41 const std::string& uuid, |
| 42 const dbus::ObjectPath& characteristic_path); |
| 43 |
| 44 // BluetoothGattDescriptorServiceProvider override. |
| 45 void SendValueChanged(const std::vector<uint8_t>& value) override; |
| 46 |
| 47 private: |
| 48 // Returns true if the current thread is on the origin thread. |
| 49 bool OnOriginThread(); |
| 50 |
| 51 // Called by dbus:: when the Bluetooth daemon fetches a single property of |
| 52 // the descriptor. |
| 53 void Get(dbus::MethodCall* method_call, |
| 54 dbus::ExportedObject::ResponseSender response_sender); |
| 55 |
| 56 // Called by dbus:: when the Bluetooth daemon sets a single property of the |
| 57 // descriptor. |
| 58 void Set(dbus::MethodCall* method_call, |
| 59 dbus::ExportedObject::ResponseSender response_sender); |
| 60 |
| 61 // Called by dbus:: when the Bluetooth daemon fetches all properties of the |
| 62 // descriptor. |
| 63 void GetAll(dbus::MethodCall* method_call, |
| 64 dbus::ExportedObject::ResponseSender response_sender); |
| 65 |
| 66 // Called by dbus:: when a method is exported. |
| 67 void OnExported(const std::string& interface_name, |
| 68 const std::string& method_name, |
| 69 bool success); |
| 70 |
| 71 // Called by the Delegate in response to a method to call to get all |
| 72 // properties, in which the delegate has successfully returned the |
| 73 // descriptor value. |
| 74 void OnGetAll(dbus::MethodCall* method_call, |
| 75 dbus::ExportedObject::ResponseSender response_sender, |
| 76 const std::vector<uint8_t>& value); |
| 77 |
| 78 // Writes the characteristics's properties into the provided writer. If |
| 79 // value is not null, it is written also, otherwise no value property is |
| 80 // written. |
| 81 void WriteProperties(dbus::MessageWriter* writer, |
| 82 const std::vector<uint8_t>* value) override; |
| 83 |
| 84 // Called by the Delegate in response to a successful method call to get the |
| 85 // descriptor value. |
| 86 void OnGet(dbus::MethodCall* method_call, |
| 87 dbus::ExportedObject::ResponseSender response_sender, |
| 88 const std::vector<uint8_t>& value); |
| 89 |
| 90 // Called by the Delegate in response to a successful method call to set the |
| 91 // descriptor value. |
| 92 void OnSet(dbus::MethodCall* method_call, |
| 93 dbus::ExportedObject::ResponseSender response_sender); |
| 94 |
| 95 // Called by the Delegate in response to a failed method call to get or set |
| 96 // the descriptor value. |
| 97 void OnFailure(dbus::MethodCall* method_call, |
| 98 dbus::ExportedObject::ResponseSender response_sender); |
| 99 |
| 100 const dbus::ObjectPath& object_path() const override; |
| 101 |
| 102 // Origin thread (i.e. the UI thread in production). |
| 103 base::PlatformThreadId origin_thread_id_; |
| 104 |
| 105 // 128-bit descriptor UUID of this object. |
| 106 std::string uuid_; |
| 107 |
| 108 // D-Bus bus object is exported on, not owned by this object and must |
| 109 // outlive it. |
| 110 dbus::Bus* bus_; |
| 111 |
| 112 // Incoming methods to get and set the "Value" property are passed on to the |
| 113 // delegate and callbacks passed to generate a reply. |delegate_| is generally |
| 114 // the object that owns this one and must outlive it. |
| 115 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate_; |
| 116 |
| 117 // D-Bus object path of object we are exporting, kept so we can unregister |
| 118 // again in our destructor. |
| 119 dbus::ObjectPath object_path_; |
| 120 |
| 121 // Object path of the GATT characteristic that the exported descriptor belongs |
| 122 // to. |
| 123 dbus::ObjectPath characteristic_path_; |
| 124 |
| 125 // D-Bus object we are exporting, owned by this object. |
| 126 scoped_refptr<dbus::ExportedObject> exported_object_; |
| 127 |
| 128 // Weak pointer factory for generating 'this' pointers that might live longer |
| 129 // than we do. |
| 130 // Note: This should remain the last member so it'll be destroyed and |
| 131 // invalidate its weak pointers before any other members are destroyed. |
| 132 base::WeakPtrFactory<BluetoothGattDescriptorServiceProviderImpl> |
| 133 weak_ptr_factory_; |
| 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptorServiceProviderImpl); |
| 136 }; |
| 137 |
| 138 } // namespace bluez |
| 139 |
| 140 #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_DESCRIPTOR_SERVICE_PROVIDER_IMPL
_H_ |
OLD | NEW |