| 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/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ( | 47 BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ( |
| 48 BluetoothAdapterBlueZ* adapter, | 48 BluetoothAdapterBlueZ* adapter, |
| 49 const device::BluetoothUUID& uuid, | 49 const device::BluetoothUUID& uuid, |
| 50 bool is_primary, | 50 bool is_primary, |
| 51 device::BluetoothLocalGattService::Delegate* delegate) | 51 device::BluetoothLocalGattService::Delegate* delegate) |
| 52 : BluetoothGattServiceBlueZ(adapter), | 52 : BluetoothGattServiceBlueZ(adapter), |
| 53 uuid_(uuid), | 53 uuid_(uuid), |
| 54 is_primary_(is_primary), | 54 is_primary_(is_primary), |
| 55 delegate_(delegate), | 55 delegate_(delegate), |
| 56 weak_ptr_factory_(this) { | 56 weak_ptr_factory_(this) { |
| 57 // TODO(rkc): Get base application path from adapter and prefix it here. | 57 object_path_ = AddGuidToObjectPath( |
| 58 object_path_ = AddGuidToObjectPath("/service"); | 58 adapter->GetApplicationObjectPath().value() + "/service"); |
| 59 VLOG(1) << "Creating local GATT service with identifier: " | 59 VLOG(1) << "Creating local GATT service with identifier: " |
| 60 << object_path_.value(); | 60 << object_path_.value(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {} | 63 BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() {} |
| 64 | 64 |
| 65 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const { | 65 device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const { |
| 66 return uuid_; | 66 return uuid_; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool BluetoothLocalGattServiceBlueZ::IsPrimary() const { | 69 bool BluetoothLocalGattServiceBlueZ::IsPrimary() const { |
| 70 return is_primary_; | 70 return is_primary_; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void BluetoothLocalGattServiceBlueZ::Register( | 73 void BluetoothLocalGattServiceBlueZ::Register( |
| 74 const base::Closure& callback, | 74 const base::Closure& callback, |
| 75 const ErrorCallback& error_callback) { | 75 const ErrorCallback& error_callback) { |
| 76 // GetAdapter()->RegisterGattService(this, callback, error_callback); | 76 GetAdapter()->RegisterGattService(this, callback, error_callback); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void BluetoothLocalGattServiceBlueZ::Unregister( | 79 void BluetoothLocalGattServiceBlueZ::Unregister( |
| 80 const base::Closure& callback, | 80 const base::Closure& callback, |
| 81 const ErrorCallback& error_callback) { | 81 const ErrorCallback& error_callback) { |
| 82 DCHECK(GetAdapter()); | 82 DCHECK(GetAdapter()); |
| 83 // GetAdapter()->UnregisterGattService(this, callback, error_callback); | 83 GetAdapter()->UnregisterGattService(this, callback, error_callback); |
| 84 } | 84 } |
| 85 | 85 |
| 86 const std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>>& | 86 const std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>>& |
| 87 BluetoothLocalGattServiceBlueZ::GetCharacteristics() const { | 87 BluetoothLocalGattServiceBlueZ::GetCharacteristics() const { |
| 88 return characteristics_; | 88 return characteristics_; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // static | 91 // static |
| 92 dbus::ObjectPath BluetoothLocalGattServiceBlueZ::AddGuidToObjectPath( | 92 dbus::ObjectPath BluetoothLocalGattServiceBlueZ::AddGuidToObjectPath( |
| 93 const std::string& path) { | 93 const std::string& path) { |
| 94 std::string GuidString = base::GenerateGUID(); | 94 std::string GuidString = base::GenerateGUID(); |
| 95 base::RemoveChars(GuidString, "-", &GuidString); | 95 base::RemoveChars(GuidString, "-", &GuidString); |
| 96 | 96 |
| 97 return dbus::ObjectPath(path + GuidString); | 97 return dbus::ObjectPath(path + GuidString); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void BluetoothLocalGattServiceBlueZ::AddCharacteristic( | 100 void BluetoothLocalGattServiceBlueZ::AddCharacteristic( |
| 101 std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic) { | 101 std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic) { |
| 102 characteristics_.push_back(std::move(characteristic)); | 102 characteristics_.push_back(std::move(characteristic)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace bluez | 105 } // namespace bluez |
| OLD | NEW |