OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
11 #include "dbus/object_manager.h" | 11 #include "dbus/object_manager.h" |
12 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
13 | 13 |
14 namespace chromeos { | 14 namespace bluez { |
15 | 15 |
16 BluetoothGattServiceClient::Properties::Properties( | 16 BluetoothGattServiceClient::Properties::Properties( |
17 dbus::ObjectProxy* object_proxy, | 17 dbus::ObjectProxy* object_proxy, |
18 const std::string& interface_name, | 18 const std::string& interface_name, |
19 const PropertyChangedCallback&callback) | 19 const PropertyChangedCallback& callback) |
20 : dbus::PropertySet(object_proxy, interface_name, callback) { | 20 : dbus::PropertySet(object_proxy, interface_name, callback) { |
21 RegisterProperty(bluetooth_gatt_service::kUUIDProperty, &uuid); | 21 RegisterProperty(bluetooth_gatt_service::kUUIDProperty, &uuid); |
22 RegisterProperty(bluetooth_gatt_service::kIncludesProperty, &includes); | 22 RegisterProperty(bluetooth_gatt_service::kIncludesProperty, &includes); |
23 RegisterProperty(bluetooth_gatt_service::kDeviceProperty, &device); | 23 RegisterProperty(bluetooth_gatt_service::kDeviceProperty, &device); |
24 RegisterProperty(bluetooth_gatt_service::kPrimaryProperty, &primary); | 24 RegisterProperty(bluetooth_gatt_service::kPrimaryProperty, &primary); |
25 RegisterProperty(bluetooth_gatt_service::kCharacteristicsProperty, | 25 RegisterProperty(bluetooth_gatt_service::kCharacteristicsProperty, |
26 &characteristics); | 26 &characteristics); |
27 } | 27 } |
28 | 28 |
29 BluetoothGattServiceClient::Properties::~Properties() { | 29 BluetoothGattServiceClient::Properties::~Properties() {} |
30 } | |
31 | 30 |
32 // The BluetoothGattServiceClient implementation used in production. | 31 // The BluetoothGattServiceClient implementation used in production. |
33 class BluetoothGattServiceClientImpl : public BluetoothGattServiceClient, | 32 class BluetoothGattServiceClientImpl : public BluetoothGattServiceClient, |
34 public dbus::ObjectManager::Interface { | 33 public dbus::ObjectManager::Interface { |
35 public: | 34 public: |
36 BluetoothGattServiceClientImpl() | 35 BluetoothGattServiceClientImpl() |
37 : object_manager_(NULL), | 36 : object_manager_(NULL), weak_ptr_factory_(this) {} |
38 weak_ptr_factory_(this) { | |
39 } | |
40 | 37 |
41 ~BluetoothGattServiceClientImpl() override { | 38 ~BluetoothGattServiceClientImpl() override { |
42 object_manager_->UnregisterInterface( | 39 object_manager_->UnregisterInterface( |
43 bluetooth_gatt_service::kBluetoothGattServiceInterface); | 40 bluetooth_gatt_service::kBluetoothGattServiceInterface); |
44 } | 41 } |
45 | 42 |
46 // BluetoothGattServiceClientImpl override. | 43 // BluetoothGattServiceClientImpl override. |
47 void AddObserver(BluetoothGattServiceClient::Observer* observer) override { | 44 void AddObserver(BluetoothGattServiceClient::Observer* observer) override { |
48 DCHECK(observer); | 45 DCHECK(observer); |
49 observers_.AddObserver(observer); | 46 observers_.AddObserver(observer); |
50 } | 47 } |
51 | 48 |
52 // BluetoothGattServiceClientImpl override. | 49 // BluetoothGattServiceClientImpl override. |
53 void RemoveObserver(BluetoothGattServiceClient::Observer* observer) override { | 50 void RemoveObserver(BluetoothGattServiceClient::Observer* observer) override { |
54 DCHECK(observer); | 51 DCHECK(observer); |
55 observers_.RemoveObserver(observer); | 52 observers_.RemoveObserver(observer); |
56 } | 53 } |
57 | 54 |
58 // BluetoothGattServiceClientImpl override. | 55 // BluetoothGattServiceClientImpl override. |
59 std::vector<dbus::ObjectPath> GetServices() override { | 56 std::vector<dbus::ObjectPath> GetServices() override { |
60 DCHECK(object_manager_); | 57 DCHECK(object_manager_); |
61 return object_manager_->GetObjectsWithInterface( | 58 return object_manager_->GetObjectsWithInterface( |
62 bluetooth_gatt_service::kBluetoothGattServiceInterface); | 59 bluetooth_gatt_service::kBluetoothGattServiceInterface); |
63 } | 60 } |
64 | 61 |
65 // BluetoothGattServiceClientImpl override. | 62 // BluetoothGattServiceClientImpl override. |
66 Properties* GetProperties(const dbus::ObjectPath& object_path) override { | 63 Properties* GetProperties(const dbus::ObjectPath& object_path) override { |
67 DCHECK(object_manager_); | 64 DCHECK(object_manager_); |
68 return static_cast<Properties*>( | 65 return static_cast<Properties*>(object_manager_->GetProperties( |
69 object_manager_->GetProperties( | 66 object_path, bluetooth_gatt_service::kBluetoothGattServiceInterface)); |
70 object_path, | |
71 bluetooth_gatt_service::kBluetoothGattServiceInterface)); | |
72 } | 67 } |
73 | 68 |
74 // dbus::ObjectManager::Interface override. | 69 // dbus::ObjectManager::Interface override. |
75 dbus::PropertySet* CreateProperties( | 70 dbus::PropertySet* CreateProperties( |
76 dbus::ObjectProxy* object_proxy, | 71 dbus::ObjectProxy* object_proxy, |
77 const dbus::ObjectPath& object_path, | 72 const dbus::ObjectPath& object_path, |
78 const std::string& interface_name) override { | 73 const std::string& interface_name) override { |
79 Properties* properties = new Properties( | 74 Properties* properties = new Properties( |
80 object_proxy, | 75 object_proxy, interface_name, |
81 interface_name, | |
82 base::Bind(&BluetoothGattServiceClientImpl::OnPropertyChanged, | 76 base::Bind(&BluetoothGattServiceClientImpl::OnPropertyChanged, |
83 weak_ptr_factory_.GetWeakPtr(), | 77 weak_ptr_factory_.GetWeakPtr(), object_path)); |
84 object_path)); | |
85 return static_cast<dbus::PropertySet*>(properties); | 78 return static_cast<dbus::PropertySet*>(properties); |
86 } | 79 } |
87 | 80 |
88 // dbus::ObjectManager::Interface override. | 81 // dbus::ObjectManager::Interface override. |
89 void ObjectAdded(const dbus::ObjectPath& object_path, | 82 void ObjectAdded(const dbus::ObjectPath& object_path, |
90 const std::string& interface_name) override { | 83 const std::string& interface_name) override { |
91 VLOG(2) << "Remote GATT service added: " << object_path.value(); | 84 VLOG(2) << "Remote GATT service added: " << object_path.value(); |
92 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, | 85 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, |
93 GattServiceAdded(object_path)); | 86 GattServiceAdded(object_path)); |
94 } | 87 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 124 |
132 // Weak pointer factory for generating 'this' pointers that might live longer | 125 // Weak pointer factory for generating 'this' pointers that might live longer |
133 // than we do. | 126 // than we do. |
134 // Note: This should remain the last member so it'll be destroyed and | 127 // Note: This should remain the last member so it'll be destroyed and |
135 // invalidate its weak pointers before any other members are destroyed. | 128 // invalidate its weak pointers before any other members are destroyed. |
136 base::WeakPtrFactory<BluetoothGattServiceClientImpl> weak_ptr_factory_; | 129 base::WeakPtrFactory<BluetoothGattServiceClientImpl> weak_ptr_factory_; |
137 | 130 |
138 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceClientImpl); | 131 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceClientImpl); |
139 }; | 132 }; |
140 | 133 |
141 BluetoothGattServiceClient::BluetoothGattServiceClient() { | 134 BluetoothGattServiceClient::BluetoothGattServiceClient() {} |
142 } | |
143 | 135 |
144 BluetoothGattServiceClient::~BluetoothGattServiceClient() { | 136 BluetoothGattServiceClient::~BluetoothGattServiceClient() {} |
145 } | |
146 | 137 |
147 // static | 138 // static |
148 BluetoothGattServiceClient* BluetoothGattServiceClient::Create() { | 139 BluetoothGattServiceClient* BluetoothGattServiceClient::Create() { |
149 return new BluetoothGattServiceClientImpl(); | 140 return new BluetoothGattServiceClientImpl(); |
150 } | 141 } |
151 | 142 |
152 } // namespace chromeos | 143 } // namespace bluez |
OLD | NEW |