#include "device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.h"
#include <iterator>
#include <limits>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
#include "dbus/property.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_gatt_notify_session.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
#include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
#include "device/bluetooth/bluez/bluetooth_remote_gatt_descriptor_bluez.h"
#include "device/bluetooth/bluez/bluetooth_remote_gatt_service_bluez.h"
#include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "third_party/cros_system_api/dbus/bluetooth/dbus-constants.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace bluez {
namespace {
std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t> bytes) { … }
}
BluetoothRemoteGattCharacteristicBlueZ::BluetoothRemoteGattCharacteristicBlueZ(
BluetoothRemoteGattServiceBlueZ* service,
const dbus::ObjectPath& object_path)
: … { … }
BluetoothRemoteGattCharacteristicBlueZ::
~BluetoothRemoteGattCharacteristicBlueZ() { … }
device::BluetoothUUID BluetoothRemoteGattCharacteristicBlueZ::GetUUID() const { … }
device::BluetoothRemoteGattCharacteristic::Properties
BluetoothRemoteGattCharacteristicBlueZ::GetProperties() const { … }
device::BluetoothRemoteGattCharacteristic::Permissions
BluetoothRemoteGattCharacteristicBlueZ::GetPermissions() const { … }
const std::vector<uint8_t>& BluetoothRemoteGattCharacteristicBlueZ::GetValue()
const { … }
device::BluetoothRemoteGattService*
BluetoothRemoteGattCharacteristicBlueZ::GetService() const { … }
bool BluetoothRemoteGattCharacteristicBlueZ::IsNotifying() const { … }
void BluetoothRemoteGattCharacteristicBlueZ::ReadRemoteCharacteristic(
ValueCallback callback) { … }
void BluetoothRemoteGattCharacteristicBlueZ::WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) { … }
void BluetoothRemoteGattCharacteristicBlueZ::
DeprecatedWriteRemoteCharacteristic(const std::vector<uint8_t>& value,
base::OnceClosure callback,
ErrorCallback error_callback) { … }
#if BUILDFLAG(IS_CHROMEOS)
void BluetoothRemoteGattCharacteristicBlueZ::PrepareWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::OnceClosure callback,
ErrorCallback error_callback) {
DVLOG(1) << "Sending GATT characteristic prepare write request to "
<< "characteristic: " << GetIdentifier()
<< ", UUID: " << GetUUID().canonical_value()
<< ", with value: " << value << ".";
bluez::BluezDBusManager::Get()
->GetBluetoothGattCharacteristicClient()
->PrepareWriteValue(
object_path(), value, std::move(callback),
base::BindOnce(&BluetoothRemoteGattCharacteristicBlueZ::OnWriteError,
weak_ptr_factory_.GetWeakPtr(),
std::move(error_callback)));
}
#endif
void BluetoothRemoteGattCharacteristicBlueZ::SubscribeToNotifications(
device::BluetoothRemoteGattDescriptor* ccc_descriptor,
#if BUILDFLAG(IS_CHROMEOS)
NotificationType notification_type,
#endif
base::OnceClosure callback,
ErrorCallback error_callback) { … }
void BluetoothRemoteGattCharacteristicBlueZ::UnsubscribeFromNotifications(
device::BluetoothRemoteGattDescriptor* ccc_descriptor,
base::OnceClosure callback,
ErrorCallback error_callback) { … }
void BluetoothRemoteGattCharacteristicBlueZ::GattDescriptorAdded(
const dbus::ObjectPath& object_path) { … }
void BluetoothRemoteGattCharacteristicBlueZ::GattDescriptorRemoved(
const dbus::ObjectPath& object_path) { … }
void BluetoothRemoteGattCharacteristicBlueZ::GattDescriptorPropertyChanged(
const dbus::ObjectPath& object_path,
const std::string& property_name) { … }
void BluetoothRemoteGattCharacteristicBlueZ::OnStartNotifySuccess(
base::OnceClosure callback) { … }
void BluetoothRemoteGattCharacteristicBlueZ::OnStartNotifyError(
ErrorCallback error_callback,
const std::string& error_name,
const std::string& error_message) { … }
void BluetoothRemoteGattCharacteristicBlueZ::OnStopNotifySuccess(
base::OnceClosure callback) { … }
void BluetoothRemoteGattCharacteristicBlueZ::OnStopNotifyError(
base::OnceClosure callback,
const std::string& error_name,
const std::string& error_message) { … }
void BluetoothRemoteGattCharacteristicBlueZ::OnReadError(
ValueCallback callback,
const std::string& error_name,
const std::string& error_message) { … }
void BluetoothRemoteGattCharacteristicBlueZ::OnWriteError(
ErrorCallback error_callback,
const std::string& error_name,
const std::string& error_message) { … }
}