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 "chromeos/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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 weak_ptr_factory_(this) { | 38 weak_ptr_factory_(this) { |
39 } | 39 } |
40 | 40 |
41 virtual ~BluetoothGattServiceClientImpl() { | 41 virtual ~BluetoothGattServiceClientImpl() { |
42 object_manager_->UnregisterInterface( | 42 object_manager_->UnregisterInterface( |
43 bluetooth_gatt_service::kBluetoothGattServiceInterface); | 43 bluetooth_gatt_service::kBluetoothGattServiceInterface); |
44 } | 44 } |
45 | 45 |
46 // BluetoothGattServiceClientImpl override. | 46 // BluetoothGattServiceClientImpl override. |
47 virtual void AddObserver( | 47 virtual void AddObserver( |
48 BluetoothGattServiceClient::Observer* observer) OVERRIDE { | 48 BluetoothGattServiceClient::Observer* observer) override { |
49 DCHECK(observer); | 49 DCHECK(observer); |
50 observers_.AddObserver(observer); | 50 observers_.AddObserver(observer); |
51 } | 51 } |
52 | 52 |
53 // BluetoothGattServiceClientImpl override. | 53 // BluetoothGattServiceClientImpl override. |
54 virtual void RemoveObserver( | 54 virtual void RemoveObserver( |
55 BluetoothGattServiceClient::Observer* observer) OVERRIDE { | 55 BluetoothGattServiceClient::Observer* observer) override { |
56 DCHECK(observer); | 56 DCHECK(observer); |
57 observers_.RemoveObserver(observer); | 57 observers_.RemoveObserver(observer); |
58 } | 58 } |
59 | 59 |
60 // BluetoothGattServiceClientImpl override. | 60 // BluetoothGattServiceClientImpl override. |
61 virtual std::vector<dbus::ObjectPath> GetServices() OVERRIDE { | 61 virtual std::vector<dbus::ObjectPath> GetServices() override { |
62 DCHECK(object_manager_); | 62 DCHECK(object_manager_); |
63 return object_manager_->GetObjectsWithInterface( | 63 return object_manager_->GetObjectsWithInterface( |
64 bluetooth_gatt_service::kBluetoothGattServiceInterface); | 64 bluetooth_gatt_service::kBluetoothGattServiceInterface); |
65 } | 65 } |
66 | 66 |
67 // BluetoothGattServiceClientImpl override. | 67 // BluetoothGattServiceClientImpl override. |
68 virtual Properties* GetProperties( | 68 virtual Properties* GetProperties( |
69 const dbus::ObjectPath& object_path) OVERRIDE { | 69 const dbus::ObjectPath& object_path) override { |
70 DCHECK(object_manager_); | 70 DCHECK(object_manager_); |
71 return static_cast<Properties*>( | 71 return static_cast<Properties*>( |
72 object_manager_->GetProperties( | 72 object_manager_->GetProperties( |
73 object_path, | 73 object_path, |
74 bluetooth_gatt_service::kBluetoothGattServiceInterface)); | 74 bluetooth_gatt_service::kBluetoothGattServiceInterface)); |
75 } | 75 } |
76 | 76 |
77 // dbus::ObjectManager::Interface override. | 77 // dbus::ObjectManager::Interface override. |
78 virtual dbus::PropertySet* CreateProperties( | 78 virtual dbus::PropertySet* CreateProperties( |
79 dbus::ObjectProxy *object_proxy, | 79 dbus::ObjectProxy *object_proxy, |
80 const dbus::ObjectPath& object_path, | 80 const dbus::ObjectPath& object_path, |
81 const std::string& interface_name) OVERRIDE { | 81 const std::string& interface_name) override { |
82 Properties* properties = new Properties( | 82 Properties* properties = new Properties( |
83 object_proxy, | 83 object_proxy, |
84 interface_name, | 84 interface_name, |
85 base::Bind(&BluetoothGattServiceClientImpl::OnPropertyChanged, | 85 base::Bind(&BluetoothGattServiceClientImpl::OnPropertyChanged, |
86 weak_ptr_factory_.GetWeakPtr(), | 86 weak_ptr_factory_.GetWeakPtr(), |
87 object_path)); | 87 object_path)); |
88 return static_cast<dbus::PropertySet*>(properties); | 88 return static_cast<dbus::PropertySet*>(properties); |
89 } | 89 } |
90 | 90 |
91 // dbus::ObjectManager::Interface override. | 91 // dbus::ObjectManager::Interface override. |
92 virtual void ObjectAdded(const dbus::ObjectPath& object_path, | 92 virtual void ObjectAdded(const dbus::ObjectPath& object_path, |
93 const std::string& interface_name) OVERRIDE { | 93 const std::string& interface_name) override { |
94 VLOG(2) << "Remote GATT service added: " << object_path.value(); | 94 VLOG(2) << "Remote GATT service added: " << object_path.value(); |
95 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, | 95 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, |
96 GattServiceAdded(object_path)); | 96 GattServiceAdded(object_path)); |
97 } | 97 } |
98 | 98 |
99 // dbus::ObjectManager::Interface override. | 99 // dbus::ObjectManager::Interface override. |
100 virtual void ObjectRemoved(const dbus::ObjectPath& object_path, | 100 virtual void ObjectRemoved(const dbus::ObjectPath& object_path, |
101 const std::string& interface_name) OVERRIDE { | 101 const std::string& interface_name) override { |
102 VLOG(2) << "Remote GATT service removed: " << object_path.value(); | 102 VLOG(2) << "Remote GATT service removed: " << object_path.value(); |
103 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, | 103 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, |
104 GattServiceRemoved(object_path)); | 104 GattServiceRemoved(object_path)); |
105 } | 105 } |
106 | 106 |
107 protected: | 107 protected: |
108 // chromeos::DBusClient override. | 108 // chromeos::DBusClient override. |
109 virtual void Init(dbus::Bus* bus) OVERRIDE { | 109 virtual void Init(dbus::Bus* bus) override { |
110 object_manager_ = bus->GetObjectManager( | 110 object_manager_ = bus->GetObjectManager( |
111 bluetooth_object_manager::kBluetoothObjectManagerServiceName, | 111 bluetooth_object_manager::kBluetoothObjectManagerServiceName, |
112 dbus::ObjectPath( | 112 dbus::ObjectPath( |
113 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); | 113 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); |
114 object_manager_->RegisterInterface( | 114 object_manager_->RegisterInterface( |
115 bluetooth_gatt_service::kBluetoothGattServiceInterface, this); | 115 bluetooth_gatt_service::kBluetoothGattServiceInterface, this); |
116 } | 116 } |
117 | 117 |
118 private: | 118 private: |
119 // Called by dbus::PropertySet when a property value is changed, either by | 119 // Called by dbus::PropertySet when a property value is changed, either by |
(...skipping 26 matching lines...) Expand all Loading... |
146 | 146 |
147 BluetoothGattServiceClient::~BluetoothGattServiceClient() { | 147 BluetoothGattServiceClient::~BluetoothGattServiceClient() { |
148 } | 148 } |
149 | 149 |
150 // static | 150 // static |
151 BluetoothGattServiceClient* BluetoothGattServiceClient::Create() { | 151 BluetoothGattServiceClient* BluetoothGattServiceClient::Create() { |
152 return new BluetoothGattServiceClientImpl(); | 152 return new BluetoothGattServiceClientImpl(); |
153 } | 153 } |
154 | 154 |
155 } // namespace chromeos | 155 } // namespace chromeos |
OLD | NEW |