17#include "pw_bluetooth/low_energy/central2.h"
18#include "pw_bluetooth_sapphire/internal/connection.h"
19#include "pw_bluetooth_sapphire/internal/host/gap/adapter.h"
20#include "pw_multibuf/allocator.h"
31 static constexpr uint8_t kMaxScanResultsQueueSize = 10;
36 Central(bt::gap::Adapter::WeakPtr adapter,
42 pw::bluetooth::PeerId peer_id,
52 class ScanHandleImpl final :
public ScanHandle {
54 explicit ScanHandleImpl(uint16_t scan_id,
Central* central)
55 : scan_id_(scan_id), central_(central) {}
59 ~ScanHandleImpl()
override;
61 void QueueScanResultLocked(ScanResult&& result)
65 std::move(waker_).Wake();
74 async2::PollResult<ScanResult> PendResult(async2::Context& cx)
override;
77 void Release()
override {
delete this; }
79 const uint16_t scan_id_;
94 std::unique_ptr<bt::gap::LowEnergyDiscoverySession> session,
95 ScanHandleImpl* scan_handle,
102 scan_handle_ =
nullptr;
112 const uint16_t scan_id_;
118 Central* const central_;
119 std::unique_ptr<bt::gap::LowEnergyDiscoverySession> session_;
126 void OnConnectionResult(bt::PeerId peer_id,
127 bt::gap::Adapter::LowEnergy::ConnectionResult result,
131 std::unordered_map<uint16_t, ScanState> scans_
PW_GUARDED_BY(lock());
134 bt::gap::Adapter::WeakPtr adapter_;
137 pw::async::Dispatcher& dispatcher_;
138 pw::async::HeapDispatcher heap_dispatcher_;
140 pw::multibuf::MultiBufAllocator& allocator_;
143 WeakSelf<Central> weak_factory_{
this};
147 WeakSelf<Central>::WeakPtr self_{weak_factory_.GetWeakPtr()};
Definition: once_sender.h:43
Definition: dispatcher.h:48
Represents an ongoing LE scan.
Definition: central2.h:148
Represents the LE central role. Used to scan and connect to peripherals.
Definition: central2.h:31
Must only be constructed and destroyed on the Bluetooth thread.
Definition: central.h:28
Definition: allocator.h:57
async2::OnceReceiver< ScanStartResult > Scan(const ScanOptions &options) override
Central(bt::gap::Adapter::WeakPtr adapter, pw::async::Dispatcher &dispatcher, pw::multibuf::MultiBufAllocator &allocator)
pw::expected< Connection2::Ptr, ConnectError > ConnectResult
The result type returned by Connect().
Definition: central2.h:205
#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
The Pigweed namespace.
Definition: alignment.h:27
Parameters used during a scan.
Definition: central2.h:89
Represents parameters that are set on a per-connection basis.
Definition: connection2.h:111