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