22 using GattDeviceService = winrt::Windows::Devices::Bluetooth::GenericAttributeProfile::GattDeviceService;
25 std::weak_ptr<Peripheral> _peripheral;
28 GattDeviceService _service{
nullptr };
31 std::unordered_map<winrt::guid, std::vector<std::shared_ptr<Characteristic>>> _characteristics{};
42 _characteristics.clear();
62 return _service.AttributeHandle();
72 return _service.Uuid();
82 return _peripheral.lock();
92 return _peripheral.lock();
107 auto it = _characteristics.find(
uuid);
108 bool found = (it != _characteristics.end()) && (!it->second.empty());
109 return found ? it->second[0] :
nullptr;
122 return _characteristics.find(
uuid)->second;
132 size_t _characteristicsCount = 0;
133 for (
auto& [_, instances] : _characteristics)
135 _characteristicsCount += instances.size();
137 outCharacteristics.reserve(outCharacteristics.size() + _characteristicsCount);
138 for (
auto& [_, instances] : _characteristics)
140 for (
auto& c : instances)
142 outCharacteristics.emplace_back(c);
156 GattDeviceService service,
157 std::unordered_map<winrt::guid, std::vector<std::shared_ptr<Characteristic>>> characteristics)
161 _characteristics{ characteristics }
Represents a Bluetooth Low Energy (BLE) peripheral.
Definition Peripheral.h:33
Represents a primary service on a Bluetooth Low Energy (BLE) peripheral.
Definition Service.h:21
std::shared_ptr< const Peripheral > peripheral() const
Gets the peripheral to which the service belongs.
Definition Service.h:80
~Service()
Closes and destroys the Service instance.
Definition Service.h:40
const std::vector< std::shared_ptr< Characteristic > > getCharacteristics(const winrt::guid &uuid)
Gets the all the Characteristic instances with the given UUID.
Definition Service.h:120
winrt::guid uuid() const
Gets the UUID of the service.
Definition Service.h:70
std::shared_ptr< Peripheral > peripheral()
Gets the peripheral to which the service belongs.
Definition Service.h:90
std::shared_ptr< Characteristic > getCharacteristic(const winrt::guid &uuid)
Gets the first Characteristic instance with the given UUID.
Definition Service.h:105
std::uint16_t handle() const
Gets the 16 bits handle of the BLE service.
Definition Service.h:60
void copyCharacteristics(std::vector< std::shared_ptr< Characteristic > > &outCharacteristics)
Copy the discovered characteristics to the given std::vector.
Definition Service.h:130
A collection of C++ classes that provides a simplified access to Bluetooth Low Energy peripherals.
Definition bletypes.h:36