Chromium Code Reviews| Index: device/bluetooth/bluetooth_gatt_service_bluez.cc |
| diff --git a/device/bluetooth/bluetooth_gatt_service_bluez.cc b/device/bluetooth/bluetooth_gatt_service_bluez.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6f501c44e22008be143133647484fba1a91198f6 |
| --- /dev/null |
| +++ b/device/bluetooth/bluetooth_gatt_service_bluez.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
ortuno
2016/04/14 17:42:35
It's 2016!
rkc
2016/04/14 19:27:27
Indeed it is. Which is why I have changed this in
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "device/bluetooth/bluetooth_gatt_service_bluez.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "device/bluetooth/bluetooth_adapter_bluez.h" |
| +#include "device/bluetooth/bluetooth_device_bluez.h" |
| +#include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h" |
| +#include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h" |
| +#include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" |
| +#include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| +#include "device/bluetooth/dbus/bluez_dbus_manager.h" |
|
ortuno
2016/04/14 17:42:35
Please clean up includes.
rkc
2016/04/14 19:27:27
Done.
|
| + |
| +namespace bluez { |
| + |
| +namespace { |
| + |
| +// TODO(jamuraa) move these to cros_system_api later |
| +const char kErrorFailed[] = "org.bluez.Error.Failed"; |
| +const char kErrorInProgress[] = "org.bluez.Error.InProgress"; |
| +const char kErrorInvalidValueLength[] = "org.bluez.Error.InvalidValueLength"; |
| +const char kErrorNotAuthorized[] = "org.bluez.Error.NotAuthorized"; |
| +const char kErrorNotPaired[] = "org.bluez.Error.NotPaired"; |
| +const char kErrorNotSupported[] = "org.bluez.Error.NotSupported"; |
| +const char kErrorNotPermitted[] = "org.bluez.Error.NotPermitted"; |
| + |
| +} // namespace |
| + |
| +BluetoothGattServiceBlueZ::BluetoothGattServiceBlueZ( |
| + BluetoothAdapterBlueZ* adapter, |
| + const dbus::ObjectPath& object_path) |
| + : adapter_(adapter), object_path_(object_path) { |
| + DCHECK(adapter_); |
| +} |
| + |
| +BluetoothGattServiceBlueZ::~BluetoothGattServiceBlueZ() {} |
| + |
| +std::vector<device::BluetoothGattCharacteristic*> |
| +BluetoothGattServiceBlueZ::GetCharacteristics() const { |
| + std::vector<device::BluetoothGattCharacteristic*> characteristics; |
| + for (CharacteristicMap::const_iterator iter = characteristics_.begin(); |
|
ortuno
2016/04/14 17:42:35
optional: use for(const auto& pair : characteristi
rkc
2016/04/14 19:27:27
Please see my comments elsewhere about this being
|
| + iter != characteristics_.end(); ++iter) { |
| + characteristics.push_back(iter->second); |
| + } |
| + return characteristics; |
| +} |
| + |
| +std::string BluetoothGattServiceBlueZ::GetIdentifier() const { |
| + return object_path_.value(); |
| +} |
| + |
| +std::vector<device::BluetoothGattService*> |
| +BluetoothGattServiceBlueZ::GetIncludedServices() const { |
| + // TODO(armansito): Return the actual included services here. |
| + return std::vector<device::BluetoothGattService*>(); |
| +} |
| + |
| +device::BluetoothGattCharacteristic* |
| +BluetoothGattServiceBlueZ::GetCharacteristic( |
| + const std::string& identifier) const { |
| + CharacteristicMap::const_iterator iter = |
| + characteristics_.find(dbus::ObjectPath(identifier)); |
| + if (iter == characteristics_.end()) |
| + return nullptr; |
| + return iter->second; |
| +} |
| + |
| +// static |
| +device::BluetoothGattService::GattErrorCode |
| +BluetoothGattServiceBlueZ::DBusErrorToServiceError(std::string error_name) { |
| + device::BluetoothGattService::GattErrorCode code = GATT_ERROR_UNKNOWN; |
| + if (error_name == kErrorFailed) { |
| + code = GATT_ERROR_FAILED; |
| + } else if (error_name == kErrorInProgress) { |
| + code = GATT_ERROR_IN_PROGRESS; |
| + } else if (error_name == kErrorInvalidValueLength) { |
| + code = GATT_ERROR_INVALID_LENGTH; |
| + } else if (error_name == kErrorNotPermitted) { |
| + code = GATT_ERROR_NOT_PERMITTED; |
| + } else if (error_name == kErrorNotAuthorized) { |
| + code = GATT_ERROR_NOT_AUTHORIZED; |
| + } else if (error_name == kErrorNotPaired) { |
| + code = GATT_ERROR_NOT_PAIRED; |
| + } else if (error_name == kErrorNotSupported) { |
| + code = GATT_ERROR_NOT_SUPPORTED; |
| + } |
| + return code; |
| +} |
| + |
| +BluetoothAdapterBlueZ* BluetoothGattServiceBlueZ::GetAdapter() const { |
| + return adapter_; |
| +} |
| + |
| +} // namespace bluez |