bluetooth_remote_gatt_service_mac.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_MAC_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_MAC_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/mac/scoped_nsobject.h"
  10. #include "base/memory/raw_ptr.h"
  11. #include "device/bluetooth/bluetooth_remote_gatt_service.h"
  12. @class CBCharacteristic;
  13. @class CBDescriptor;
  14. @class CBPeripheral;
  15. @class CBService;
  16. namespace device {
  17. class BluetoothAdapterMac;
  18. class BluetoothDevice;
  19. class BluetoothRemoteGattCharacteristicMac;
  20. class BluetoothRemoteGattDescriptorMac;
  21. class BluetoothLowEnergyDeviceMac;
  22. class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattServiceMac
  23. : public BluetoothRemoteGattService {
  24. public:
  25. BluetoothRemoteGattServiceMac(
  26. BluetoothLowEnergyDeviceMac* bluetooth_device_mac,
  27. CBService* service,
  28. bool is_primary);
  29. BluetoothRemoteGattServiceMac(const BluetoothRemoteGattServiceMac&) = delete;
  30. BluetoothRemoteGattServiceMac& operator=(
  31. const BluetoothRemoteGattServiceMac&) = delete;
  32. ~BluetoothRemoteGattServiceMac() override;
  33. // BluetoothRemoteGattService override.
  34. std::string GetIdentifier() const override;
  35. BluetoothUUID GetUUID() const override;
  36. bool IsPrimary() const override;
  37. BluetoothDevice* GetDevice() const override;
  38. std::vector<BluetoothRemoteGattService*> GetIncludedServices() const override;
  39. private:
  40. friend class BluetoothLowEnergyDeviceMac;
  41. friend class BluetoothRemoteGattCharacteristicMac;
  42. friend class BluetoothTestMac;
  43. // Starts discovering characteristics by calling CoreBluetooth.
  44. void DiscoverCharacteristics();
  45. // Called by the BluetoothLowEnergyDeviceMac instance when the characteristics
  46. // has been discovered.
  47. void DidDiscoverCharacteristics();
  48. // Called by the BluetoothLowEnergyDeviceMac instance when the descriptors has
  49. // been discovered.
  50. void DidDiscoverDescriptors(CBCharacteristic* characteristic);
  51. // Sends notification if this service is ready with all characteristics
  52. // discovered.
  53. void SendNotificationIfComplete();
  54. // Returns the mac adapter.
  55. BluetoothAdapterMac* GetMacAdapter() const;
  56. // Returns CBPeripheral.
  57. CBPeripheral* GetCBPeripheral() const;
  58. // Returns CBService.
  59. CBService* GetService() const;
  60. // Returns a remote characteristic based on the CBCharacteristic.
  61. BluetoothRemoteGattCharacteristicMac* GetBluetoothRemoteGattCharacteristicMac(
  62. CBCharacteristic* cb_characteristic) const;
  63. // Returns a remote descriptor based on the CBDescriptor.
  64. BluetoothRemoteGattDescriptorMac* GetBluetoothRemoteGattDescriptorMac(
  65. CBDescriptor* cb_descriptor) const;
  66. // bluetooth_device_mac_ owns instances of this class.
  67. raw_ptr<BluetoothLowEnergyDeviceMac> bluetooth_device_mac_;
  68. // A service from CBPeripheral.services.
  69. base::scoped_nsobject<CBService> service_;
  70. bool is_primary_;
  71. // Service identifier.
  72. std::string identifier_;
  73. // Service UUID.
  74. BluetoothUUID uuid_;
  75. // Increased each time DiscoverCharacteristics() is called. And decreased when
  76. // DidDiscoverCharacteristics() is called.
  77. int discovery_pending_count_;
  78. };
  79. // Stream operator for logging.
  80. DEVICE_BLUETOOTH_EXPORT std::ostream& operator<<(
  81. std::ostream& out,
  82. const BluetoothRemoteGattServiceMac& service);
  83. } // namespace device
  84. #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_MAC_H_