| 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_descriptor_client.h" |    5 #include "chromeos/dbus/bluetooth_gatt_descriptor_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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   43         weak_ptr_factory_(this) { |   43         weak_ptr_factory_(this) { | 
|   44   } |   44   } | 
|   45  |   45  | 
|   46   virtual ~BluetoothGattDescriptorClientImpl() { |   46   virtual ~BluetoothGattDescriptorClientImpl() { | 
|   47     object_manager_->UnregisterInterface( |   47     object_manager_->UnregisterInterface( | 
|   48         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface); |   48         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface); | 
|   49   } |   49   } | 
|   50  |   50  | 
|   51   // BluetoothGattDescriptorClientImpl override. |   51   // BluetoothGattDescriptorClientImpl override. | 
|   52   virtual void AddObserver( |   52   virtual void AddObserver( | 
|   53       BluetoothGattDescriptorClient::Observer* observer) OVERRIDE { |   53       BluetoothGattDescriptorClient::Observer* observer) override { | 
|   54     DCHECK(observer); |   54     DCHECK(observer); | 
|   55     observers_.AddObserver(observer); |   55     observers_.AddObserver(observer); | 
|   56   } |   56   } | 
|   57  |   57  | 
|   58   // BluetoothGattDescriptorClientImpl override. |   58   // BluetoothGattDescriptorClientImpl override. | 
|   59   virtual void RemoveObserver( |   59   virtual void RemoveObserver( | 
|   60       BluetoothGattDescriptorClient::Observer* observer) OVERRIDE { |   60       BluetoothGattDescriptorClient::Observer* observer) override { | 
|   61     DCHECK(observer); |   61     DCHECK(observer); | 
|   62     observers_.RemoveObserver(observer); |   62     observers_.RemoveObserver(observer); | 
|   63   } |   63   } | 
|   64  |   64  | 
|   65   // BluetoothGattDescriptorClientImpl override. |   65   // BluetoothGattDescriptorClientImpl override. | 
|   66   virtual std::vector<dbus::ObjectPath> GetDescriptors() OVERRIDE { |   66   virtual std::vector<dbus::ObjectPath> GetDescriptors() override { | 
|   67     DCHECK(object_manager_); |   67     DCHECK(object_manager_); | 
|   68     return object_manager_->GetObjectsWithInterface( |   68     return object_manager_->GetObjectsWithInterface( | 
|   69         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface); |   69         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface); | 
|   70   } |   70   } | 
|   71  |   71  | 
|   72   // BluetoothGattDescriptorClientImpl override. |   72   // BluetoothGattDescriptorClientImpl override. | 
|   73   virtual Properties* GetProperties( |   73   virtual Properties* GetProperties( | 
|   74       const dbus::ObjectPath& object_path) OVERRIDE { |   74       const dbus::ObjectPath& object_path) override { | 
|   75     DCHECK(object_manager_); |   75     DCHECK(object_manager_); | 
|   76     return static_cast<Properties*>( |   76     return static_cast<Properties*>( | 
|   77         object_manager_->GetProperties( |   77         object_manager_->GetProperties( | 
|   78             object_path, |   78             object_path, | 
|   79             bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface)); |   79             bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface)); | 
|   80   } |   80   } | 
|   81  |   81  | 
|   82   // BluetoothGattDescriptorClientImpl override. |   82   // BluetoothGattDescriptorClientImpl override. | 
|   83   virtual void ReadValue(const dbus::ObjectPath& object_path, |   83   virtual void ReadValue(const dbus::ObjectPath& object_path, | 
|   84                          const ValueCallback& callback, |   84                          const ValueCallback& callback, | 
|   85                          const ErrorCallback& error_callback) OVERRIDE { |   85                          const ErrorCallback& error_callback) override { | 
|   86     dbus::ObjectProxy* object_proxy = |   86     dbus::ObjectProxy* object_proxy = | 
|   87         object_manager_->GetObjectProxy(object_path); |   87         object_manager_->GetObjectProxy(object_path); | 
|   88     if (!object_proxy) { |   88     if (!object_proxy) { | 
|   89       error_callback.Run(kUnknownDescriptorError, ""); |   89       error_callback.Run(kUnknownDescriptorError, ""); | 
|   90       return; |   90       return; | 
|   91     } |   91     } | 
|   92  |   92  | 
|   93     dbus::MethodCall method_call( |   93     dbus::MethodCall method_call( | 
|   94         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, |   94         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, | 
|   95         bluetooth_gatt_descriptor::kReadValue); |   95         bluetooth_gatt_descriptor::kReadValue); | 
|   96  |   96  | 
|   97     object_proxy->CallMethodWithErrorCallback( |   97     object_proxy->CallMethodWithErrorCallback( | 
|   98         &method_call, |   98         &method_call, | 
|   99         dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |   99         dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 
|  100         base::Bind(&BluetoothGattDescriptorClientImpl::OnValueSuccess, |  100         base::Bind(&BluetoothGattDescriptorClientImpl::OnValueSuccess, | 
|  101                    weak_ptr_factory_.GetWeakPtr(), |  101                    weak_ptr_factory_.GetWeakPtr(), | 
|  102                    callback), |  102                    callback), | 
|  103         base::Bind(&BluetoothGattDescriptorClientImpl::OnError, |  103         base::Bind(&BluetoothGattDescriptorClientImpl::OnError, | 
|  104                    weak_ptr_factory_.GetWeakPtr(), |  104                    weak_ptr_factory_.GetWeakPtr(), | 
|  105                    error_callback)); |  105                    error_callback)); | 
|  106   } |  106   } | 
|  107  |  107  | 
|  108   // BluetoothGattDescriptorClientImpl override. |  108   // BluetoothGattDescriptorClientImpl override. | 
|  109   virtual void WriteValue(const dbus::ObjectPath& object_path, |  109   virtual void WriteValue(const dbus::ObjectPath& object_path, | 
|  110                           const std::vector<uint8>& value, |  110                           const std::vector<uint8>& value, | 
|  111                           const base::Closure& callback, |  111                           const base::Closure& callback, | 
|  112                           const ErrorCallback& error_callback) OVERRIDE { |  112                           const ErrorCallback& error_callback) override { | 
|  113     dbus::ObjectProxy* object_proxy = |  113     dbus::ObjectProxy* object_proxy = | 
|  114         object_manager_->GetObjectProxy(object_path); |  114         object_manager_->GetObjectProxy(object_path); | 
|  115     if (!object_proxy) { |  115     if (!object_proxy) { | 
|  116       error_callback.Run(kUnknownDescriptorError, ""); |  116       error_callback.Run(kUnknownDescriptorError, ""); | 
|  117       return; |  117       return; | 
|  118     } |  118     } | 
|  119  |  119  | 
|  120     dbus::MethodCall method_call( |  120     dbus::MethodCall method_call( | 
|  121         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, |  121         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, | 
|  122         bluetooth_gatt_descriptor::kWriteValue); |  122         bluetooth_gatt_descriptor::kWriteValue); | 
|  123     dbus::MessageWriter writer(&method_call); |  123     dbus::MessageWriter writer(&method_call); | 
|  124     writer.AppendArrayOfBytes(value.data(), value.size()); |  124     writer.AppendArrayOfBytes(value.data(), value.size()); | 
|  125  |  125  | 
|  126     object_proxy->CallMethodWithErrorCallback( |  126     object_proxy->CallMethodWithErrorCallback( | 
|  127         &method_call, |  127         &method_call, | 
|  128         dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |  128         dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 
|  129         base::Bind(&BluetoothGattDescriptorClientImpl::OnSuccess, |  129         base::Bind(&BluetoothGattDescriptorClientImpl::OnSuccess, | 
|  130                    weak_ptr_factory_.GetWeakPtr(), |  130                    weak_ptr_factory_.GetWeakPtr(), | 
|  131                    callback), |  131                    callback), | 
|  132         base::Bind(&BluetoothGattDescriptorClientImpl::OnError, |  132         base::Bind(&BluetoothGattDescriptorClientImpl::OnError, | 
|  133                    weak_ptr_factory_.GetWeakPtr(), |  133                    weak_ptr_factory_.GetWeakPtr(), | 
|  134                    error_callback)); |  134                    error_callback)); | 
|  135   } |  135   } | 
|  136  |  136  | 
|  137   // dbus::ObjectManager::Interface override. |  137   // dbus::ObjectManager::Interface override. | 
|  138   virtual dbus::PropertySet* CreateProperties( |  138   virtual dbus::PropertySet* CreateProperties( | 
|  139       dbus::ObjectProxy *object_proxy, |  139       dbus::ObjectProxy *object_proxy, | 
|  140       const dbus::ObjectPath& object_path, |  140       const dbus::ObjectPath& object_path, | 
|  141       const std::string& interface_name) OVERRIDE { |  141       const std::string& interface_name) override { | 
|  142     Properties* properties = new Properties( |  142     Properties* properties = new Properties( | 
|  143         object_proxy, |  143         object_proxy, | 
|  144         interface_name, |  144         interface_name, | 
|  145         base::Bind(&BluetoothGattDescriptorClientImpl::OnPropertyChanged, |  145         base::Bind(&BluetoothGattDescriptorClientImpl::OnPropertyChanged, | 
|  146                    weak_ptr_factory_.GetWeakPtr(), |  146                    weak_ptr_factory_.GetWeakPtr(), | 
|  147                    object_path)); |  147                    object_path)); | 
|  148     return static_cast<dbus::PropertySet*>(properties); |  148     return static_cast<dbus::PropertySet*>(properties); | 
|  149   } |  149   } | 
|  150  |  150  | 
|  151   // dbus::ObjectManager::Interface override. |  151   // dbus::ObjectManager::Interface override. | 
|  152   virtual void ObjectAdded(const dbus::ObjectPath& object_path, |  152   virtual void ObjectAdded(const dbus::ObjectPath& object_path, | 
|  153                            const std::string& interface_name) OVERRIDE { |  153                            const std::string& interface_name) override { | 
|  154     VLOG(2) << "Remote GATT descriptor added: " << object_path.value(); |  154     VLOG(2) << "Remote GATT descriptor added: " << object_path.value(); | 
|  155     FOR_EACH_OBSERVER(BluetoothGattDescriptorClient::Observer, observers_, |  155     FOR_EACH_OBSERVER(BluetoothGattDescriptorClient::Observer, observers_, | 
|  156                       GattDescriptorAdded(object_path)); |  156                       GattDescriptorAdded(object_path)); | 
|  157   } |  157   } | 
|  158  |  158  | 
|  159   // dbus::ObjectManager::Interface override. |  159   // dbus::ObjectManager::Interface override. | 
|  160   virtual void ObjectRemoved(const dbus::ObjectPath& object_path, |  160   virtual void ObjectRemoved(const dbus::ObjectPath& object_path, | 
|  161                              const std::string& interface_name) OVERRIDE { |  161                              const std::string& interface_name) override { | 
|  162     VLOG(2) << "Remote GATT descriptor removed: " << object_path.value(); |  162     VLOG(2) << "Remote GATT descriptor removed: " << object_path.value(); | 
|  163     FOR_EACH_OBSERVER(BluetoothGattDescriptorClient::Observer, observers_, |  163     FOR_EACH_OBSERVER(BluetoothGattDescriptorClient::Observer, observers_, | 
|  164                       GattDescriptorRemoved(object_path)); |  164                       GattDescriptorRemoved(object_path)); | 
|  165   } |  165   } | 
|  166  |  166  | 
|  167  protected: |  167  protected: | 
|  168   // chromeos::DBusClient override. |  168   // chromeos::DBusClient override. | 
|  169   virtual void Init(dbus::Bus* bus) OVERRIDE { |  169   virtual void Init(dbus::Bus* bus) override { | 
|  170     object_manager_ = bus->GetObjectManager( |  170     object_manager_ = bus->GetObjectManager( | 
|  171         bluetooth_object_manager::kBluetoothObjectManagerServiceName, |  171         bluetooth_object_manager::kBluetoothObjectManagerServiceName, | 
|  172         dbus::ObjectPath( |  172         dbus::ObjectPath( | 
|  173             bluetooth_object_manager::kBluetoothObjectManagerServicePath)); |  173             bluetooth_object_manager::kBluetoothObjectManagerServicePath)); | 
|  174     object_manager_->RegisterInterface( |  174     object_manager_->RegisterInterface( | 
|  175         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, |  175         bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, | 
|  176         this); |  176         this); | 
|  177   } |  177   } | 
|  178  |  178  | 
|  179  private: |  179  private: | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  251  |  251  | 
|  252 BluetoothGattDescriptorClient::~BluetoothGattDescriptorClient() { |  252 BluetoothGattDescriptorClient::~BluetoothGattDescriptorClient() { | 
|  253 } |  253 } | 
|  254  |  254  | 
|  255 // static |  255 // static | 
|  256 BluetoothGattDescriptorClient* BluetoothGattDescriptorClient::Create() { |  256 BluetoothGattDescriptorClient* BluetoothGattDescriptorClient::Create() { | 
|  257   return new BluetoothGattDescriptorClientImpl(); |  257   return new BluetoothGattDescriptorClientImpl(); | 
|  258 } |  258 } | 
|  259  |  259  | 
|  260 }  // namespace chromeos |  260 }  // namespace chromeos | 
| OLD | NEW |