Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2089)

Unified Diff: device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl.h

Issue 1914893002: DBus changes for implementing local GATT attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_classes
Patch Set: test leak fix Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl.h
diff --git a/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl.h b/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..46874bb670e1a641d56a059846625f8f61911f4f
--- /dev/null
+++ b/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl.h
@@ -0,0 +1,140 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_DESCRIPTOR_SERVICE_PROVIDER_IMPL_H_
+#define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_DESCRIPTOR_SERVICE_PROVIDER_IMPL_H_
+
+#include <stdint.h>
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/platform_thread.h"
+#include "dbus/bus.h"
+#include "dbus/exported_object.h"
+#include "dbus/message.h"
+#include "dbus/object_path.h"
+#include "device/bluetooth/dbus/bluetooth_gatt_attribute_value_delegate.h"
+#include "device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.h"
+
+namespace bluez {
+
+// The BluetoothGattDescriptorServiceProvider implementation used in production.
+class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptorServiceProviderImpl
+ : public BluetoothGattDescriptorServiceProvider {
+ public:
+ BluetoothGattDescriptorServiceProviderImpl(
+ dbus::Bus* bus,
+ const dbus::ObjectPath& object_path,
+ std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate,
+ const std::string& uuid,
+ const std::vector<std::string>& permissions,
+ const dbus::ObjectPath& characteristic_path);
+ ~BluetoothGattDescriptorServiceProviderImpl() override;
+
+ // For testing.
+ BluetoothGattDescriptorServiceProviderImpl(
+ const dbus::ObjectPath& object_path,
+ const std::string& uuid,
+ const dbus::ObjectPath& characteristic_path);
+
+ // BluetoothGattDescriptorServiceProvider override.
+ void SendValueChanged(const std::vector<uint8_t>& value) override;
+
+ private:
+ // Returns true if the current thread is on the origin thread.
+ bool OnOriginThread();
+
+ // Called by dbus:: when the Bluetooth daemon fetches a single property of
+ // the descriptor.
+ void Get(dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender);
+
+ // Called by dbus:: when the Bluetooth daemon sets a single property of the
+ // descriptor.
+ void Set(dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender);
+
+ // Called by dbus:: when the Bluetooth daemon fetches all properties of the
+ // descriptor.
+ void GetAll(dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender);
+
+ // Called by dbus:: when a method is exported.
+ void OnExported(const std::string& interface_name,
+ const std::string& method_name,
+ bool success);
+
+ // Called by the Delegate in response to a method to call to get all
+ // properties, in which the delegate has successfully returned the
+ // descriptor value.
+ void OnGetAll(dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender,
+ const std::vector<uint8_t>& value);
+
+ // Writes the characteristics's properties into the provided writer. If
+ // value is not null, it is written also, otherwise no value property is
+ // written.
+ void WriteProperties(dbus::MessageWriter* writer,
+ const std::vector<uint8_t>* value) override;
+
+ // Called by the Delegate in response to a successful method call to get the
+ // descriptor value.
+ void OnGet(dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender,
+ const std::vector<uint8_t>& value);
+
+ // Called by the Delegate in response to a successful method call to set the
+ // descriptor value.
+ void OnSet(dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender);
+
+ // Called by the Delegate in response to a failed method call to get or set
+ // the descriptor value.
+ void OnFailure(dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender);
+
+ const dbus::ObjectPath& object_path() const override;
+
+ // Origin thread (i.e. the UI thread in production).
+ base::PlatformThreadId origin_thread_id_;
+
+ // 128-bit descriptor UUID of this object.
+ std::string uuid_;
+
+ // D-Bus bus object is exported on, not owned by this object and must
+ // outlive it.
+ dbus::Bus* bus_;
+
+ // Incoming methods to get and set the "Value" property are passed on to the
+ // delegate and callbacks passed to generate a reply. |delegate_| is generally
+ // the object that owns this one and must outlive it.
+ std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate_;
+
+ // D-Bus object path of object we are exporting, kept so we can unregister
+ // again in our destructor.
+ dbus::ObjectPath object_path_;
+
+ // Object path of the GATT characteristic that the exported descriptor belongs
+ // to.
+ dbus::ObjectPath characteristic_path_;
+
+ // D-Bus object we are exporting, owned by this object.
+ scoped_refptr<dbus::ExportedObject> exported_object_;
+
+ // Weak pointer factory for generating 'this' pointers that might live longer
+ // than we do.
+ // Note: This should remain the last member so it'll be destroyed and
+ // invalidate its weak pointers before any other members are destroyed.
+ base::WeakPtrFactory<BluetoothGattDescriptorServiceProviderImpl>
+ weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptorServiceProviderImpl);
+};
+
+} // namespace bluez
+
+#endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_DESCRIPTOR_SERVICE_PROVIDER_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698