forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbluetooth_remote_gatt_characteristic_bluez.h
152 lines (123 loc) · 5.86 KB
/
bluetooth_remote_gatt_characteristic_bluez.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
#define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
#include <stddef.h>
#include <stdint.h>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "dbus/object_path.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_remote_gatt_service.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h"
#include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h"
namespace device {
class BluetoothRemoteGattDescriptor;
class BluetoothRemoteGattService;
} // namespace device
namespace bluez {
class BluetoothRemoteGattDescriptorBlueZ;
class BluetoothRemoteGattServiceBlueZ;
// The BluetoothRemoteGattCharacteristicBlueZ class implements
// BluetoothRemoteGattCharacteristic for remote GATT characteristics for
// platforms
// that use BlueZ.
class BluetoothRemoteGattCharacteristicBlueZ
: public BluetoothGattCharacteristicBlueZ,
public BluetoothGattDescriptorClient::Observer,
public device::BluetoothRemoteGattCharacteristic {
public:
// device::BluetoothGattCharacteristic overrides.
device::BluetoothUUID GetUUID() const override;
Properties GetProperties() const override;
Permissions GetPermissions() const override;
// device::BluetoothRemoteGattCharacteristic overrides.
const std::vector<uint8_t>& GetValue() const override;
device::BluetoothRemoteGattService* GetService() const override;
bool IsNotifying() const override;
std::vector<device::BluetoothRemoteGattDescriptor*> GetDescriptors()
const override;
device::BluetoothRemoteGattDescriptor* GetDescriptor(
const std::string& identifier) const override;
void ReadRemoteCharacteristic(const ValueCallback& callback,
const ErrorCallback& error_callback) override;
void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
protected:
void SubscribeToNotifications(
device::BluetoothRemoteGattDescriptor* ccc_descriptor,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
void UnsubscribeFromNotifications(
device::BluetoothRemoteGattDescriptor* ccc_descriptor,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
private:
friend class BluetoothRemoteGattServiceBlueZ;
BluetoothRemoteGattCharacteristicBlueZ(
BluetoothRemoteGattServiceBlueZ* service,
const dbus::ObjectPath& object_path);
~BluetoothRemoteGattCharacteristicBlueZ() override;
// bluez::BluetoothGattDescriptorClient::Observer overrides.
void GattDescriptorAdded(const dbus::ObjectPath& object_path) override;
void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override;
void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path,
const std::string& property_name) override;
// Called by dbus:: on successful completion of a request to start
// notifications.
void OnStartNotifySuccess(const base::Closure& callback);
// Called by dbus:: on unsuccessful completion of a request to start
// notifications.
void OnStartNotifyError(const ErrorCallback& error_callback,
const std::string& error_name,
const std::string& error_message);
// Called by dbus:: on successful completion of a request to stop
// notifications.
void OnStopNotifySuccess(const base::Closure& callback);
// Called by dbus:: on unsuccessful completion of a request to stop
// notifications.
void OnStopNotifyError(const base::Closure& callback,
const std::string& error_name,
const std::string& error_message);
// Called by dbus:: on unsuccessful completion of a request to read
// the characteristic value.
void OnReadError(const ErrorCallback& error_callback,
const std::string& error_name,
const std::string& error_message);
// Called by dbus:: on unsuccessful completion of a request to write
// the characteristic value.
void OnWriteError(const ErrorCallback& error_callback,
const std::string& error_name,
const std::string& error_message);
// True, if there exists a Bluez notify session.
bool has_notify_session_;
// TODO(rkc): Investigate and fix ownership of the descriptor objects in this
// map. See crbug.com/604166.
using DescriptorMap =
std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorBlueZ*>;
// Mapping from GATT descriptor object paths to descriptor objects owned by
// this characteristic. Since the BlueZ implementation uses object paths
// as unique identifiers, we also use this mapping to return descriptors by
// identifier.
DescriptorMap descriptors_;
// The GATT service this GATT characteristic belongs to.
BluetoothRemoteGattServiceBlueZ* service_;
// Number of gatt read requests in progress.
int num_of_characteristic_value_read_in_progress_;
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ>
weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ);
};
} // namespace bluez
#endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_