File: floss_gatt_manager_client.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (709 lines) | stat: -rw-r--r-- 28,707 bytes parent folder | download | duplicates (6)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_BLUETOOTH_FLOSS_FLOSS_GATT_MANAGER_CLIENT_H_
#define DEVICE_BLUETOOTH_FLOSS_FLOSS_GATT_MANAGER_CLIENT_H_

#include <string>

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "device/bluetooth/bluetooth_export.h"
#include "device/bluetooth/floss/exported_callback_manager.h"
#include "device/bluetooth/floss/floss_dbus_client.h"
#include "device/bluetooth/public/cpp/bluetooth_uuid.h"

namespace floss {

// Authentication requirements for GATT.
enum class DEVICE_BLUETOOTH_EXPORT AuthRequired {
  kNoAuth = 0,  // No authentication required.
  kNoMitm,      // Encrypted but not authenticated.
  kReqMitm,     // Encrypted and authenticated.

  // Same as above but signed + encrypted.
  kSignedNoMitm,
  kSignedReqMitm,
};

enum class DEVICE_BLUETOOTH_EXPORT WriteType {
  kInvalid = 0,
  kWriteNoResponse,
  kWrite,
  kWritePrepare,
};

enum class DEVICE_BLUETOOTH_EXPORT LeDiscoverableMode {
  kInvalid = 0,
  kNonDiscoverable = 1,
  kLimitedDiscoverable = 2,
  kGeneralDiscoverable = 3,
};

enum class DEVICE_BLUETOOTH_EXPORT LePhy {
  kInvalid = 0,
  kPhy1m = 1,
  kPhy2m = 2,
  kPhyCoded = 3,
};

// Status for many GATT apis. Due to complexity here, only kSuccess should be
// used for comparisons.
enum class DEVICE_BLUETOOTH_EXPORT GattStatus {
  kSuccess = 0,
  kInvalidHandle,
  kReadNotPermitted,
  kWriteNotPermitted,
  kInvalidPdu,
  kInsufficientAuthentication,
  kReqNotSupported,
  kInvalidOffset,
  kInsufficientAuthorization,
  kPrepareQueueFull,
  kNotFound,
  kNotLong,
  kInsufficientKeySize,
  kInvalidAttributeLen,
  kUnlikelyError,
  kInsufficientEncryption,
  kUnsupportedGroupType,
  kInsufficientResources,
  kDatabaseOutOfSync,
  kValueNotAllowed,
  // Big jump here
  kTooShort = 0x7f,
  kNoResources,
  kInternalError,
  kWrongState,
  kDbFull,
  kBusy,
  kError,
  kCommandStarted,
  kIllegalParameter,
  kPending,
  kAuthFailed,
  kMore,
  kInvalidConfig,
  kServiceStarted,
  kEncryptedNoMitm,
  kNotEncrypted,
  kCongested,
  kDupReg,
  kAlreadyOpen,
  kCancel,
  // 0xE0 - 0xFC reserved for future use.
  kCccCfgErr = 0xFD,
  kPrcInProgress = 0xFE,
  kOutOfRange = 0xFF,
};

// GATT WriteCharacteristic D-Bus method results.
enum class DEVICE_BLUETOOTH_EXPORT GattWriteRequestStatus {
  kSuccess = 0,
  kFail = 1,
  kBusy = 2,
};

struct DEVICE_BLUETOOTH_EXPORT GattDescriptor {
  device::BluetoothUUID uuid;
  int32_t instance_id;
  int32_t permissions;

  GattDescriptor();
  ~GattDescriptor();
};

struct DEVICE_BLUETOOTH_EXPORT GattCharacteristic {
  enum Property {
    GATT_CHAR_PROP_BIT_BROADCAST = (1 << 0),
    GATT_CHAR_PROP_BIT_READ = (1 << 1),
    GATT_CHAR_PROP_BIT_WRITE_NR = (1 << 2),
    GATT_CHAR_PROP_BIT_WRITE = (1 << 3),
    GATT_CHAR_PROP_BIT_NOTIFY = (1 << 4),
    GATT_CHAR_PROP_BIT_INDICATE = (1 << 5),
    GATT_CHAR_PROP_BIT_AUTH = (1 << 6),
    GATT_CHAR_PROP_BIT_EXT_PROP = (1 << 7),
  };

  enum Permission {
    GATT_PERM_READ = (1 << 0),
    GATT_PERM_READ_ENCRYPTED = (1 << 1),
    GATT_PERM_READ_ENC_MITM = (1 << 2),
    GATT_PERM_WRITE = (1 << 4),
    GATT_PERM_WRITE_ENCRYPTED = (1 << 5),
    GATT_PERM_WRITE_ENC_MITM = (1 << 6),
    GATT_PERM_WRITE_SIGNED = (1 << 7),
    GATT_PERM_WRITE_SIGNED_MITM = (1 << 8),
  };

  device::BluetoothUUID uuid;
  int32_t instance_id;
  int32_t properties;
  int32_t permissions;
  int32_t key_size;
  WriteType write_type;
  std::vector<GattDescriptor> descriptors;

  GattCharacteristic();
  GattCharacteristic(const GattCharacteristic&);
  ~GattCharacteristic();
};

struct DEVICE_BLUETOOTH_EXPORT GattService {
  enum ServiceType {
    GATT_SERVICE_TYPE_PRIMARY = 0,
    GATT_SERVICE_TYPE_SECONDARY = 1,
  };
  device::BluetoothUUID uuid;
  int32_t instance_id;
  int32_t service_type;
  std::vector<GattCharacteristic> characteristics;
  std::vector<GattService> included_services;

  GattService();
  GattService(const GattService&);
  ~GattService();
};

// Callback functions expected to be imported by the GATT client.
//
// This also doubles as an observer class for the GATT client since it will
// really only filter out calls that aren't for this client.
class DEVICE_BLUETOOTH_EXPORT FlossGattClientObserver
    : public base::CheckedObserver {
 public:
  FlossGattClientObserver(const FlossGattClientObserver&) = delete;
  FlossGattClientObserver& operator=(const FlossGattClientObserver&) = delete;

  FlossGattClientObserver() = default;
  ~FlossGattClientObserver() override = default;

  // A client has completed registration for callbacks. Subsequent uses should
  // use this client id.
  virtual void GattClientRegistered(GattStatus status, int32_t client_id) {}

  // A client connection has changed state.
  virtual void GattClientConnectionState(GattStatus status,
                                         int32_t client_id,
                                         bool connected,
                                         std::string address) {}

  // The PHY used for a connection has changed states.
  virtual void GattPhyUpdate(std::string address,
                             LePhy tx,
                             LePhy rx,
                             GattStatus status) {}

  // Result of reading the currently used PHY.
  virtual void GattPhyRead(std::string address,
                           LePhy tx,
                           LePhy rx,
                           GattStatus status) {}

  // Service resolution completed and GATT db available.
  virtual void GattSearchComplete(std::string address,
                                  const std::vector<GattService>& services,
                                  GattStatus status) {}

  // Result of reading a characteristic.
  virtual void GattCharacteristicRead(std::string address,
                                      GattStatus status,
                                      int32_t handle,
                                      const std::vector<uint8_t>& data) {}

  // Result of writing a characteristic.
  virtual void GattCharacteristicWrite(std::string address,
                                       GattStatus status,
                                       int32_t handle) {}

  // Reliable write completed.
  virtual void GattExecuteWrite(std::string address, GattStatus status) {}

  // Result of reading a descriptor.
  virtual void GattDescriptorRead(std::string address,
                                  GattStatus status,
                                  int32_t handle,
                                  const std::vector<uint8_t>& data) {}

  // Result of writing to a descriptor.
  virtual void GattDescriptorWrite(std::string address,
                                   GattStatus status,
                                   int32_t handle) {}

  // Notification or indication of a handle on a remote device.
  virtual void GattNotify(std::string address,
                          int32_t handle,
                          const std::vector<uint8_t>& data) {}

  // Result of reading remote rssi.
  virtual void GattReadRemoteRssi(std::string address,
                                  int32_t rssi,
                                  GattStatus status) {}

  // Result of setting connection mtu.
  virtual void GattConfigureMtu(std::string address,
                                int32_t mtu,
                                GattStatus status) {}

  // Change to connection parameters.
  virtual void GattConnectionUpdated(std::string address,
                                     int32_t interval,
                                     int32_t latency,
                                     int32_t timeout,
                                     GattStatus status) {}

  // Notification from the peer that some records are updated, so a re-discovery
  // is in order.
  virtual void GattServiceChanged(std::string address) {}
};

// Callback functions expected to be imported by the GATT server.
//
// This also doubles as an observer class for the GATT server.
class DEVICE_BLUETOOTH_EXPORT FlossGattServerObserver
    : public base::CheckedObserver {
 public:
  FlossGattServerObserver(const FlossGattServerObserver&) = delete;
  FlossGattServerObserver& operator=(const FlossGattServerObserver&) = delete;

  FlossGattServerObserver() = default;
  ~FlossGattServerObserver() override = default;

  // Server has completed registration for callbacks and set a server id for
  // subsequent use.
  virtual void GattServerRegistered(GattStatus status, int32_t server) {}

  // A server connection has changed state.
  virtual void GattServerConnectionState(int32_t server_id,
                                         bool connected,
                                         std::string address) {}

  // A Gatt service has been added to the server.
  virtual void GattServerServiceAdded(GattStatus status, GattService service) {}

  // A Gatt service has been removed from the server.
  virtual void GattServerServiceRemoved(GattStatus status, int32_t handle) {}

  // A remote device has requested to read a Gatt server characteristic.
  virtual void GattServerCharacteristicReadRequest(std::string address,
                                                   int32_t request_id,
                                                   int32_t offset,
                                                   bool is_long,
                                                   int32_t handle) {}

  // A remote device has requested to read a Gatt server descriptor.
  virtual void GattServerDescriptorReadRequest(std::string address,
                                               int32_t request_id,
                                               int32_t offset,
                                               bool is_long,
                                               int32_t handle) {}

  // A remote device has requested to write to a Gatt server characteristic.
  virtual void GattServerCharacteristicWriteRequest(
      std::string address,
      int32_t request_id,
      int32_t offset,
      int32_t length,
      bool is_prepared_write,
      bool needs_response,
      int32_t handle,
      std::vector<uint8_t> value) {}

  // A remote device has requested to write to a Gatt server descriptor.
  virtual void GattServerDescriptorWriteRequest(std::string address,
                                                int32_t request_id,
                                                int32_t offset,
                                                int32_t length,
                                                bool is_prepared_write,
                                                bool needs_response,
                                                int32_t handle,
                                                std::vector<uint8_t> value) {}

  // Executes a write transaction for a given remote device.
  virtual void GattServerExecuteWrite(std::string address,
                                      int32_t request_id,
                                      bool execute_write) {}

  // A server sent out a notification.
  virtual void GattServerNotificationSent(std::string address,
                                          GattStatus status) {}

  // The MTU for a given device connection has changed.
  virtual void GattServerMtuChanged(std::string address, int32_t mtu) {}

  // A remote device changed the PHY.
  virtual void GattServerPhyUpdate(std::string address,
                                   LePhy tx_phy,
                                   LePhy rx_phy,
                                   GattStatus status) {}

  // A remote device read the PHY.
  virtual void GattServerPhyRead(std::string address,
                                 LePhy tx_phy,
                                 LePhy rx_phy,
                                 GattStatus status) {}

  // A given connection has been updated.
  virtual void GattServerConnectionUpdate(std::string address,
                                          int32_t interval,
                                          int32_t latency,
                                          int32_t timeout,
                                          GattStatus status) {}

  // Subrate connection parameters have been updated.
  virtual void GattServerSubrateChange(std::string address,
                                       int32_t subrate_factor,
                                       int32_t latency,
                                       int32_t continuation_num,
                                       int32_t timeout,
                                       GattStatus status) {}
};

class DEVICE_BLUETOOTH_EXPORT FlossGattManagerClient
    : public FlossDBusClient,
      public FlossGattClientObserver,
      public FlossGattServerObserver {
 public:
  static const char kExportedCallbacksPath[];

  // Creates the instance.
  static std::unique_ptr<FlossGattManagerClient> Create();

  FlossGattManagerClient();
  ~FlossGattManagerClient() override;

  FlossGattManagerClient(const FlossGattManagerClient&) = delete;
  FlossGattManagerClient& operator=(const FlossGattManagerClient&) = delete;

  // Manage observers.
  void AddObserver(FlossGattClientObserver* observer);
  void AddServerObserver(FlossGattServerObserver* observer);
  void RemoveObserver(FlossGattClientObserver* observer);
  void RemoveServerObserver(FlossGattServerObserver* observer);

  // Create a GATT client connection to a remote device on given transport.
  virtual void Connect(ResponseCallback<Void> callback,
                       const std::string& remote_device,
                       const BluetoothTransport& transport,
                       bool is_direct);

  // Disconnect GATT for given device.
  virtual void Disconnect(ResponseCallback<Void> callback,
                          const std::string& remote_device);

  // Start a reliable write for the remote device.
  virtual void BeginReliableWrite(ResponseCallback<Void> callback,
                                  const std::string& remote_device);

  // Execute or abort (depending on the value of |execute|) a reliable write for
  // the remote device.
  virtual void EndReliableWrite(ResponseCallback<Void> callback,
                                const std::string& remote_device,
                                bool execute);

  // Clears the attribute cache of a device.
  virtual void Refresh(ResponseCallback<Void> callback,
                       const std::string& remote_device);

  // Enumerates all GATT services on an already connected device.
  virtual void DiscoverAllServices(ResponseCallback<Void> callback,
                                   const std::string& remote_device);

  // Search for a GATT service on a connected device with a UUID.
  virtual void DiscoverServiceByUuid(ResponseCallback<Void> callback,
                                     const std::string& remote_device,
                                     const device::BluetoothUUID& uuid);

  // Reads a characteristic on a connected device with given |handle|.
  virtual void ReadCharacteristic(ResponseCallback<Void> callback,
                                  const std::string& remote_device,
                                  const int32_t handle,
                                  const AuthRequired auth_required);

  // Reads a characteristic on a connected device between |start_handle| and
  // |end_handle| that matches the given |uuid|.
  virtual void ReadUsingCharacteristicUuid(ResponseCallback<Void> callback,
                                           const std::string& remote_device,
                                           const device::BluetoothUUID& uuid,
                                           const int32_t start_handle,
                                           const int32_t end_handle,
                                           const AuthRequired auth_required);

  // Writes a characteristic on a connected device with given |handle|.
  virtual void WriteCharacteristic(
      ResponseCallback<GattWriteRequestStatus> callback,
      const std::string& remote_device,
      const int32_t handle,
      const WriteType write_type,
      const AuthRequired auth_required,
      base::span<const uint8_t> data);

  // Reads the descriptor for a given characteristic |handle|.
  virtual void ReadDescriptor(ResponseCallback<Void> callback,
                              const std::string& remote_device,
                              const int32_t handle,
                              const AuthRequired auth_required);

  // Writes a descriptor for a given characteristic |handle|.
  virtual void WriteDescriptor(ResponseCallback<Void> callback,
                               const std::string& remote_device,
                               const int32_t handle,
                               const AuthRequired auth_required,
                               base::span<const uint8_t> data);

  // Register for updates on a specific characteristic.
  virtual void RegisterForNotification(ResponseCallback<GattStatus> callback,
                                       const std::string& remote_device,
                                       const int32_t handle);

  // Unregister for updates on a specific characteristic.
  virtual void UnregisterNotification(ResponseCallback<GattStatus> callback,
                                      const std::string& remote_device,
                                      const int32_t handle);

  // Request RSSI for the connected device.
  virtual void ReadRemoteRssi(ResponseCallback<Void> callback,
                              const std::string& remote_device);

  // Configures the MTU for a connected device.
  virtual void ConfigureMTU(ResponseCallback<Void> callback,
                            const std::string& remote_device,
                            const int32_t mtu);

  // Update the connection parameters for the given device.
  virtual void UpdateConnectionParameters(ResponseCallback<Void> callback,
                                          const std::string& remote_device,
                                          const int32_t min_interval,
                                          const int32_t max_interval,
                                          const int32_t latency,
                                          const int32_t timeout,
                                          const uint16_t min_ce_len,
                                          const uint16_t max_ce_len);

  // Create a GATT server connection to a remote device on given transport.
  virtual void ServerConnect(ResponseCallback<Void> callback,
                             const std::string& remote_device,
                             const BluetoothTransport& transport);

  // Disconnect GATT for given device.
  virtual void ServerDisconnect(ResponseCallback<Void> callback,
                                const std::string& remote_device);

  // Set the preferred connection PHY.
  virtual void ServerSetPreferredPhy(ResponseCallback<Void> callback,
                                     const std::string& remote_device,
                                     LePhy tx_phy,
                                     LePhy rx_phy,
                                     int32_t phy_options);

  // Read the current transmitter and receiver PHY of the connection.
  virtual void ServerReadPhy(ResponseCallback<Void> callback,
                             const std::string& remote_device);

  // Add a Gatt service.
  virtual void AddService(ResponseCallback<Void> callback, GattService service);

  // Remove Gatt service.
  virtual void RemoveService(ResponseCallback<Void> callback, int32_t handle);

  // Clear all Gatt services.
  virtual void ClearServices(ResponseCallback<Void> callback);

  // Send a response to a given device.
  virtual void SendResponse(ResponseCallback<Void> callback,
                            const std::string& remote_device,
                            int32_t request_id,
                            GattStatus status,
                            int32_t offset,
                            std::vector<uint8_t> value);

  // Send a notification, with the option to specify whether or not the client
  // must confirm explicit acknowledgement.
  virtual void ServerSendNotification(ResponseCallback<Void> callback,
                                      const std::string& remote_device,
                                      int32_t handle,
                                      bool confirm,
                                      std::vector<uint8_t> value);
  // Get service name.
  std::string ServiceName() const { return service_name_; }
  // Get whether MSFT extension is supported.
  bool GetMsftSupported() const { return property_msft_supported_.Get(); }

  // Initialize the gatt client for the given adapter.
  void Init(dbus::Bus* bus,
            const std::string& service_name,
            const int adapter_index,
            base::Version version,
            base::OnceClosure on_ready) override;

 protected:
  friend class BluetoothGattFlossTest;

  // FlossGattClientObserver overrides
  void GattClientRegistered(GattStatus status, int32_t client_id) override;
  void GattClientConnectionState(GattStatus status,
                                 int32_t client_id,
                                 bool connected,
                                 std::string address) override;
  void GattPhyUpdate(std::string address,
                     LePhy tx,
                     LePhy rx,
                     GattStatus status) override;
  void GattPhyRead(std::string address,
                   LePhy tx,
                   LePhy rx,
                   GattStatus status) override;
  void GattSearchComplete(std::string address,
                          const std::vector<GattService>& services,
                          GattStatus status) override;
  void GattCharacteristicRead(std::string address,
                              GattStatus status,
                              int32_t handle,
                              const std::vector<uint8_t>& data) override;
  void GattCharacteristicWrite(std::string address,
                               GattStatus status,
                               int32_t handle) override;
  void GattExecuteWrite(std::string address, GattStatus status) override;
  void GattDescriptorRead(std::string address,
                          GattStatus status,
                          int32_t handle,
                          const std::vector<uint8_t>& data) override;
  void GattDescriptorWrite(std::string address,
                           GattStatus status,
                           int32_t handle) override;
  void GattNotify(std::string address,
                  int32_t handle,
                  const std::vector<uint8_t>& data) override;
  void GattReadRemoteRssi(std::string address,
                          int32_t rssi,
                          GattStatus status) override;
  void GattConfigureMtu(std::string address,
                        int32_t mtu,
                        GattStatus status) override;
  void GattConnectionUpdated(std::string address,
                             int32_t interval,
                             int32_t latency,
                             int32_t timeout,
                             GattStatus status) override;
  void GattServiceChanged(std::string address) override;
  void OnRegisterNotificationResponse(ResponseCallback<GattStatus> callback,
                                      bool is_registering,
                                      DBusResult<Void> result);

  // FlossGattServerObserver overrides
  void GattServerRegistered(GattStatus status, int32_t server_id) override;
  void GattServerConnectionState(int32_t server_id,
                                 bool connected,
                                 std::string address) override;
  void GattServerServiceAdded(GattStatus status, GattService service) override;
  void GattServerServiceRemoved(GattStatus status, int32_t handle) override;
  void GattServerCharacteristicReadRequest(std::string address,
                                           int32_t request_id,
                                           int32_t offset,
                                           bool is_long,
                                           int32_t handle) override;
  void GattServerDescriptorReadRequest(std::string address,
                                       int32_t request_id,
                                       int32_t offset,
                                       bool is_long,
                                       int32_t handle) override;
  void GattServerCharacteristicWriteRequest(
      std::string address,
      int32_t request_id,
      int32_t offset,
      int32_t length,
      bool is_prepared_write,
      bool needs_response,
      int32_t handle,
      std::vector<uint8_t> value) override;
  void GattServerDescriptorWriteRequest(std::string address,
                                        int32_t request_id,
                                        int32_t offset,
                                        int32_t length,
                                        bool is_prepared_write,
                                        bool needs_response,
                                        int32_t handle,
                                        std::vector<uint8_t> value) override;
  void GattServerExecuteWrite(std::string address,
                              int32_t request_id,
                              bool execute_write) override;
  void GattServerNotificationSent(std::string address,
                                  GattStatus status) override;
  void GattServerMtuChanged(std::string address, int32_t mtu) override;
  void GattServerPhyUpdate(std::string address,
                           LePhy tx_phy,
                           LePhy rx_phy,
                           GattStatus status) override;
  void GattServerPhyRead(std::string address,
                         LePhy tx_phy,
                         LePhy rx_phy,
                         GattStatus status) override;
  void GattServerConnectionUpdate(std::string address,
                                  int32_t interval,
                                  int32_t latency,
                                  int32_t timeout,
                                  GattStatus status) override;
  void GattServerSubrateChange(std::string address,
                               int32_t subrate_factor,
                               int32_t latency,
                               int32_t continuation_num,
                               int32_t timeout,
                               GattStatus status) override;

  // Managed by FlossDBusManager - we keep local pointer to access object proxy.
  raw_ptr<dbus::Bus> bus_ = nullptr;

  // Path used for gatt api calls by this class.
  dbus::ObjectPath gatt_adapter_path_;

  // List of observers interested in event notifications from this client.
  base::ObserverList<FlossGattClientObserver> gatt_client_observers_;
  base::ObserverList<FlossGattServerObserver> gatt_server_observers_;

  // Service which implements the GattManagerClient interface.
  std::string service_name_;

 private:
  friend class FlossGattClientTest;

  // Register gatt client and gatt server to get client and server ids.
  void RegisterClient();
  void RegisterServer();

  // Complete initialization and signal we're ready.
  void CompleteInit();

  template <typename R, typename... Args>
  void CallGattMethod(ResponseCallback<R> callback,
                      const char* member,
                      Args... args) {
    CallMethod(std::move(callback), bus_, service_name_, kGattInterface,
               gatt_adapter_path_, member, args...);
  }

  // Id given for registering as a gatt client and gatt server against Floss.
  // Used in many apis.
  int32_t client_id_ = 0;
  int32_t server_id_ = 0;

  // Signal when the client is ready to be used.
  base::OnceClosure on_ready_;

  // Exported callbacks for interacting with daemon.
  ExportedCallbackManager<FlossGattClientObserver>
      gatt_client_exported_callback_manager_{gatt::kCallbackInterface};
  ExportedCallbackManager<FlossGattServerObserver>
      gatt_server_exported_callback_manager_{gatt::kServerCallbackInterface};

  FlossProperty<bool> property_msft_supported_{
      kGattInterface, gatt::kCallbackInterface, "IsMsftSupported",
      nullptr /* property is not updateable */};

  base::WeakPtrFactory<FlossGattManagerClient> weak_ptr_factory_{this};
};

}  // namespace floss

#endif  // DEVICE_BLUETOOTH_FLOSS_FLOSS_GATT_MANAGER_CLIENT_H_