| OLD | NEW | 
|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h" | 
| 6 | 6 | 
| 7 #include "base/callback.h" |  | 
| 8 #include "base/guid.h" |  | 
| 9 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 10 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" | 
| 11 #include "base/strings/string_util.h" |  | 
| 12 #include "dbus/object_path.h" | 9 #include "dbus/object_path.h" | 
| 13 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" | 10 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" | 
| 14 | 11 | 
| 15 namespace bluez { | 12 namespace bluez { | 
| 16 | 13 | 
| 17 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ( | 14 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ( | 
| 18     BluetoothAdapterBlueZ* adapter, | 15     BluetoothAdapterBlueZ* adapter, | 
| 19     const device::BluetoothUUID& uuid, | 16     const device::BluetoothUUID& uuid, | 
| 20     bool is_primary, | 17     bool is_primary, | 
| 21     device::BluetoothLocalGattService::Delegate* delegate) | 18     device::BluetoothLocalGattService::Delegate* delegate) | 
| 22     : BluetoothGattServiceBlueZ(adapter), | 19     : BluetoothGattServiceBlueZ(adapter), | 
| 23       uuid_(uuid), | 20       uuid_(uuid), | 
| 24       is_primary_(is_primary), | 21       is_primary_(is_primary), | 
| 25       delegate_(delegate), | 22       delegate_(delegate), | 
| 26       weak_ptr_factory_(this) { | 23       weak_ptr_factory_(this) { | 
| 27   // TODO(rkc): Move this code in a common location. It is used by | 24   object_path_ = GenerateAttributeObjectPath("service"); | 
| 28   // BluetoothAdvertisementBlueZ() also. |  | 
| 29   std::string GuidString = base::GenerateGUID(); |  | 
| 30   base::RemoveChars(GuidString, "-", &GuidString); |  | 
| 31   object_path_ = dbus::ObjectPath(adapter_->object_path().value() + |  | 
| 32                                   "/service/" + GuidString); |  | 
| 33   VLOG(1) << "Creating local GATT service with identifier: " | 25   VLOG(1) << "Creating local GATT service with identifier: " | 
| 34           << object_path_.value(); | 26           << object_path_.value(); | 
| 35 } | 27 } | 
| 36 | 28 | 
| 37 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {} | 29 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {} | 
| 38 | 30 | 
| 39 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const { | 31 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const { | 
| 40   return uuid_; | 32   return uuid_; | 
| 41 } | 33 } | 
| 42 | 34 | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 56       static_cast<BluetoothAdapterBlueZ*>(adapter); | 48       static_cast<BluetoothAdapterBlueZ*>(adapter); | 
| 57   BluetoothLocalGattServiceBlueZ* service = new BluetoothLocalGattServiceBlueZ( | 49   BluetoothLocalGattServiceBlueZ* service = new BluetoothLocalGattServiceBlueZ( | 
| 58       adapter_bluez, uuid, is_primary, delegate); | 50       adapter_bluez, uuid, is_primary, delegate); | 
| 59   adapter_bluez->AddLocalGattService(base::WrapUnique(service)); | 51   adapter_bluez->AddLocalGattService(base::WrapUnique(service)); | 
| 60   return service->weak_ptr_factory_.GetWeakPtr(); | 52   return service->weak_ptr_factory_.GetWeakPtr(); | 
| 61 } | 53 } | 
| 62 | 54 | 
| 63 void BluetoothLocalGattServiceBlueZ::Register( | 55 void BluetoothLocalGattServiceBlueZ::Register( | 
| 64     const base::Closure& callback, | 56     const base::Closure& callback, | 
| 65     const ErrorCallback& error_callback) { | 57     const ErrorCallback& error_callback) { | 
| 66   // TODO(rkc): Call adapter_->RegisterGattService. | 58   GetAdapter()->RegisterGattService(this, callback, error_callback); | 
| 67 } | 59 } | 
| 68 | 60 | 
| 69 void BluetoothLocalGattServiceBlueZ::Unregister( | 61 void BluetoothLocalGattServiceBlueZ::Unregister( | 
| 70     const base::Closure& callback, | 62     const base::Closure& callback, | 
| 71     const ErrorCallback& error_callback) { | 63     const ErrorCallback& error_callback) { | 
| 72   // TODO(rkc): Call adapter_->UnregisterGattService. | 64   DCHECK(GetAdapter()); | 
|  | 65   GetAdapter()->UnregisterGattService(this, callback, error_callback); | 
| 73 } | 66 } | 
| 74 | 67 | 
| 75 void BluetoothLocalGattServiceBlueZ::OnRegistrationError( | 68 const std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>>& | 
| 76     const ErrorCallback& error_callback, | 69 BluetoothLocalGattServiceBlueZ::GetCharacteristics() const { | 
| 77     const std::string& error_name, | 70   return characteristics_; | 
| 78     const std::string& error_message) { | 71 } | 
| 79   VLOG(1) << "[Un]Register Service failed: " << error_name | 72 | 
| 80           << ", message: " << error_message; | 73 void BluetoothLocalGattServiceBlueZ::AddCharacteristic( | 
| 81   error_callback.Run( | 74     std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic) { | 
| 82       BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); | 75   characteristics_.push_back(std::move(characteristic)); | 
| 83 } | 76 } | 
| 84 | 77 | 
| 85 }  // namespace bluez | 78 }  // namespace bluez | 
| OLD | NEW | 
|---|