17#include "pw_bluetooth/low_energy/peripheral2.h"
18#include "pw_bluetooth_sapphire/internal/host/gap/adapter.h"
48 class AdvertisedPeripheralImpl final
51 AdvertisedPeripheralImpl(bt::gap::AdvertisementId
id,
53 : id_(id), peripheral_(peripheral) {}
54 ~AdvertisedPeripheralImpl()
override {
55 std::lock_guard lock(Peripheral::lock());
57 peripheral_->OnAdvertisedPeripheralDestroyedLocked(id_);
62 async2::Poll<pw::bluetooth::low_energy::Connection2::Ptr> PendConnection(
63 [[maybe_unused]] async2::Context& cx)
override {
67 void StopAdvertising()
override;
68 async2::Poll<pw::Status> PendStop(async2::Context& cx)
override;
69 void Release()
override {
delete this; }
72 friend class Advertisement;
74 const bt::gap::AdvertisementId id_;
86 class Advertisement final {
88 Advertisement(bt::gap::AdvertisementInstance&& instance,
89 AdvertisedPeripheralImpl* advertised_peripheral)
90 : advertised_peripheral_(advertised_peripheral),
91 instance_(std::move(instance)) {}
96 void OnAdvertisedPeripheralDestroyedLocked()
98 advertised_peripheral_ =
nullptr;
104 friend class AdvertisedPeripheralImpl;
106 AdvertisedPeripheralImpl* advertised_peripheral_;
109 bt::gap::AdvertisementInstance instance_;
113 void OnAdvertisedPeripheralDestroyedLocked(
114 bt::gap::AdvertisementId advertisement_id)
119 void StopAdvertising(bt::gap::AdvertisementId advertisement_id);
122 void OnAdvertiseResult(bt::gap::AdvertisementInstance instance,
123 bt::hci::Result<> result,
124 async2::OnceSender<AdvertiseResult> result_sender);
127 void OnConnection(bt::gap::AdvertisementId advertisement_id,
128 bt::gap::Adapter::LowEnergy::ConnectionResult result);
134 bt::gap::Adapter::WeakPtr adapter_;
136 std::unordered_map<bt::gap::AdvertisementId, Advertisement> advertisements_
140 WeakSelf<Peripheral> weak_factory_{
this};
144 WeakSelf<Peripheral>::WeakPtr self_{weak_factory_.GetWeakPtr()};
Definition: once_sender.h:43
Definition: dispatcher.h:48
Definition: heap_dispatcher.h:25
AdvertisedPeripheral instances are valid for the duration of advertising.
Definition: peripheral2.h:34
Represents the LE Peripheral role, which advertises and is connected to.
Definition: peripheral2.h:93
Must only be constructed and destroyed on the Bluetooth thread.
Definition: peripheral.h:25
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:271
async2::OnceReceiver< AdvertiseResult > Advertise(const AdvertisingParameters ¶meters) override
~Peripheral() override
Must only be destroyed on the Bluetooth thread.
Peripheral(bt::gap::Adapter::WeakPtr adapter, pw::async::Dispatcher &dispatcher)
Must only be constructed on the Bluetooth thread.
#define PW_GUARDED_BY(x)
Definition: lock_annotations.h:60
#define PW_EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: lock_annotations.h:146
#define PW_LOCKS_EXCLUDED(...)
Definition: lock_annotations.h:176
Dual-mode Bluetooth host stack.
Definition: central.h:23
Represents the parameters for configuring advertisements.
Definition: peripheral2.h:163