17#include "pw_async2/value_future.h"
18#include "pw_bluetooth/low_energy/peripheral2.h"
19#include "pw_bluetooth_sapphire/internal/host/gap/adapter.h"
49 class AdvertisedPeripheralImpl final
52 AdvertisedPeripheralImpl(bt::gap::AdvertisementId
id,
54 : id_(id), peripheral_(peripheral) {}
55 ~AdvertisedPeripheralImpl()
override {
56 std::lock_guard lock(Peripheral::lock());
58 peripheral_->OnAdvertisedPeripheralDestroyedLocked(id_);
63 async2::Poll<pw::bluetooth::low_energy::Connection2::Ptr> PendConnection(
64 [[maybe_unused]] async2::Context& cx)
override {
68 void StopAdvertising()
override;
69 async2::Poll<pw::Status> PendStop(async2::Context& cx)
override;
70 void Release()
override {
delete this; }
73 friend class Advertisement;
75 const bt::gap::AdvertisementId id_;
87 class Advertisement final {
89 Advertisement(bt::gap::AdvertisementInstance&& instance,
90 AdvertisedPeripheralImpl* advertised_peripheral)
91 : advertised_peripheral_(advertised_peripheral),
92 instance_(std::move(instance)) {}
97 void OnAdvertisedPeripheralDestroyedLocked()
99 advertised_peripheral_ =
nullptr;
105 friend class AdvertisedPeripheralImpl;
107 AdvertisedPeripheralImpl* advertised_peripheral_;
110 bt::gap::AdvertisementInstance instance_;
114 void OnAdvertisedPeripheralDestroyedLocked(
115 bt::gap::AdvertisementId advertisement_id)
120 void StopAdvertising(bt::gap::AdvertisementId advertisement_id);
123 void OnAdvertiseResult(
124 bt::gap::AdvertisementInstance instance,
125 bt::hci::Result<> result,
126 async2::OptionalValueProvider<AdvertiseResult> result_provider);
129 void OnConnection(bt::gap::AdvertisementId advertisement_id,
130 bt::gap::Adapter::LowEnergy::ConnectionResult result);
136 bt::gap::Adapter::WeakPtr adapter_;
138 std::unordered_map<bt::gap::AdvertisementId, Advertisement> advertisements_
142 WeakSelf<Peripheral> weak_factory_{
this};
146 WeakSelf<Peripheral>::WeakPtr self_{weak_factory_.GetWeakPtr()};
Definition: value_future.h:47
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:87
Must only be constructed and destroyed on the Bluetooth thread.
Definition: peripheral.h:26
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:353
async2::OptionalValueFuture< 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:24
Represents the parameters for configuring advertisements.
Definition: peripheral2.h:157