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