| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "device/bluetooth/bluetooth_gatt_service_bluez.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/strings/stringprintf.h" |
| 9 #include "device/bluetooth/bluetooth_adapter_bluez.h" |
| 10 #include "device/bluetooth/bluetooth_device_bluez.h" |
| 11 #include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h" |
| 12 #include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h" |
| 13 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" |
| 14 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| 15 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 16 |
| 17 namespace bluez { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // TODO(jamuraa) move these to cros_system_api later |
| 22 const char kErrorFailed[] = "org.bluez.Error.Failed"; |
| 23 const char kErrorInProgress[] = "org.bluez.Error.InProgress"; |
| 24 const char kErrorInvalidValueLength[] = "org.bluez.Error.InvalidValueLength"; |
| 25 const char kErrorNotAuthorized[] = "org.bluez.Error.NotAuthorized"; |
| 26 const char kErrorNotPaired[] = "org.bluez.Error.NotPaired"; |
| 27 const char kErrorNotSupported[] = "org.bluez.Error.NotSupported"; |
| 28 const char kErrorNotPermitted[] = "org.bluez.Error.NotPermitted"; |
| 29 |
| 30 } // namespace |
| 31 |
| 32 BluetoothGattServiceBlueZ::BluetoothGattServiceBlueZ( |
| 33 BluetoothAdapterBlueZ* adapter, |
| 34 const dbus::ObjectPath& object_path) |
| 35 : adapter_(adapter), object_path_(object_path) { |
| 36 DCHECK(adapter_); |
| 37 } |
| 38 |
| 39 BluetoothGattServiceBlueZ::~BluetoothGattServiceBlueZ() {} |
| 40 |
| 41 std::vector<device::BluetoothGattCharacteristic*> |
| 42 BluetoothGattServiceBlueZ::GetCharacteristics() const { |
| 43 std::vector<device::BluetoothGattCharacteristic*> characteristics; |
| 44 for (CharacteristicMap::const_iterator iter = characteristics_.begin(); |
| 45 iter != characteristics_.end(); ++iter) { |
| 46 characteristics.push_back(iter->second); |
| 47 } |
| 48 return characteristics; |
| 49 } |
| 50 |
| 51 std::string BluetoothGattServiceBlueZ::GetIdentifier() const { |
| 52 return object_path_.value(); |
| 53 } |
| 54 |
| 55 std::vector<device::BluetoothGattService*> |
| 56 BluetoothGattServiceBlueZ::GetIncludedServices() const { |
| 57 // TODO(armansito): Return the actual included services here. |
| 58 return std::vector<device::BluetoothGattService*>(); |
| 59 } |
| 60 |
| 61 device::BluetoothGattCharacteristic* |
| 62 BluetoothGattServiceBlueZ::GetCharacteristic( |
| 63 const std::string& identifier) const { |
| 64 CharacteristicMap::const_iterator iter = |
| 65 characteristics_.find(dbus::ObjectPath(identifier)); |
| 66 if (iter == characteristics_.end()) |
| 67 return nullptr; |
| 68 return iter->second; |
| 69 } |
| 70 |
| 71 // static |
| 72 device::BluetoothGattService::GattErrorCode |
| 73 BluetoothGattServiceBlueZ::DBusErrorToServiceError(std::string error_name) { |
| 74 device::BluetoothGattService::GattErrorCode code = GATT_ERROR_UNKNOWN; |
| 75 if (error_name == kErrorFailed) { |
| 76 code = GATT_ERROR_FAILED; |
| 77 } else if (error_name == kErrorInProgress) { |
| 78 code = GATT_ERROR_IN_PROGRESS; |
| 79 } else if (error_name == kErrorInvalidValueLength) { |
| 80 code = GATT_ERROR_INVALID_LENGTH; |
| 81 } else if (error_name == kErrorNotPermitted) { |
| 82 code = GATT_ERROR_NOT_PERMITTED; |
| 83 } else if (error_name == kErrorNotAuthorized) { |
| 84 code = GATT_ERROR_NOT_AUTHORIZED; |
| 85 } else if (error_name == kErrorNotPaired) { |
| 86 code = GATT_ERROR_NOT_PAIRED; |
| 87 } else if (error_name == kErrorNotSupported) { |
| 88 code = GATT_ERROR_NOT_SUPPORTED; |
| 89 } |
| 90 return code; |
| 91 } |
| 92 |
| 93 BluetoothAdapterBlueZ* BluetoothGattServiceBlueZ::GetAdapter() const { |
| 94 return adapter_; |
| 95 } |
| 96 |
| 97 } // namespace bluez |
| OLD | NEW |