| OLD | NEW |
| (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 #include <iostream> |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 9 #include "base/logging.h" |
| 10 #include "device/bluetooth/bluetooth_adapter_bluez.h" |
| 11 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 12 #include "device/bluetooth/bluetooth_local_gatt_service_bluez.h" |
| 13 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" |
| 14 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 15 |
| 16 namespace bluez { |
| 17 |
| 18 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ( |
| 19 BluetoothAdapterBlueZ* adapter, |
| 20 const dbus::ObjectPath& object_path) |
| 21 : BluetoothGattServiceBlueZ(adapter, object_path), weak_ptr_factory_(this) { |
| 22 VLOG(1) << "Creating local GATT service with identifier: " |
| 23 << object_path.value(); |
| 24 } |
| 25 |
| 26 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {} |
| 27 |
| 28 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const { |
| 29 NOTIMPLEMENTED(); |
| 30 return device::BluetoothUUID(); |
| 31 } |
| 32 |
| 33 bool BluetoothLocalGattServiceBlueZ::IsLocal() const { |
| 34 return true; |
| 35 } |
| 36 |
| 37 bool BluetoothLocalGattServiceBlueZ::IsPrimary() const { |
| 38 NOTIMPLEMENTED(); |
| 39 return false; |
| 40 } |
| 41 |
| 42 device::BluetoothDevice* BluetoothLocalGattServiceBlueZ::GetDevice() const { |
| 43 return nullptr; |
| 44 } |
| 45 |
| 46 bool BluetoothLocalGattServiceBlueZ::AddCharacteristic( |
| 47 device::BluetoothGattCharacteristic* characteristic) { |
| 48 NOTIMPLEMENTED(); |
| 49 return false; |
| 50 } |
| 51 |
| 52 bool BluetoothLocalGattServiceBlueZ::AddIncludedService( |
| 53 device::BluetoothGattService* service) { |
| 54 NOTIMPLEMENTED(); |
| 55 return false; |
| 56 } |
| 57 |
| 58 void BluetoothLocalGattServiceBlueZ::Register( |
| 59 const base::Closure& callback, |
| 60 const ErrorCallback& error_callback) { |
| 61 DCHECK(bluez::BluezDBusManager::Get()); |
| 62 bluez::BluezDBusManager::Get() |
| 63 ->GetBluetoothGattManagerClient() |
| 64 ->RegisterService( |
| 65 object_path(), BluetoothGattManagerClient::Options(), callback, |
| 66 base::Bind(&BluetoothLocalGattServiceBlueZ::OnRegistrationError, |
| 67 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 68 } |
| 69 |
| 70 void BluetoothLocalGattServiceBlueZ::Unregister( |
| 71 const base::Closure& callback, |
| 72 const ErrorCallback& error_callback) { |
| 73 DCHECK(bluez::BluezDBusManager::Get()); |
| 74 bluez::BluezDBusManager::Get() |
| 75 ->GetBluetoothGattManagerClient() |
| 76 ->UnregisterService( |
| 77 object_path(), callback, |
| 78 base::Bind(&BluetoothLocalGattServiceBlueZ::OnRegistrationError, |
| 79 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 80 } |
| 81 |
| 82 void BluetoothLocalGattServiceBlueZ::OnRegistrationError( |
| 83 const ErrorCallback& error_callback, |
| 84 const std::string& error_name, |
| 85 const std::string& error_message) { |
| 86 VLOG(1) << "[Un]Register Service failed: " << error_name |
| 87 << ", message: " << error_message; |
| 88 error_callback.Run( |
| 89 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); |
| 90 } |
| 91 |
| 92 } // namespace bluez |
| OLD | NEW |