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

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

Powered by Google App Engine
This is Rietveld 408576698