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)
72 async2::PollResult<ScanResult> PendResult(async2::Context& cx)
override;
75 void Release()
override {
delete this; }
77 const uint16_t scan_id_;
92 std::unique_ptr<bt::gap::LowEnergyDiscoverySession> session,
93 ScanHandleImpl* scan_handle,
100 scan_handle_ =
nullptr;
110 const uint16_t scan_id_;
116 Central* const central_;
117 std::unique_ptr<bt::gap::LowEnergyDiscoverySession> session_;
124 void OnConnectionResult(bt::PeerId peer_id,
125 bt::gap::Adapter::LowEnergy::ConnectionResult result,
129 std::unordered_map<uint16_t, ScanState> scans_
PW_GUARDED_BY(lock());
132 bt::gap::Adapter::WeakPtr adapter_;
135 pw::async::Dispatcher& dispatcher_;
136 pw::async::HeapDispatcher heap_dispatcher_;
138 pw::multibuf::MultiBufAllocator& allocator_;
141 WeakSelf<Central> weak_factory_{
this};
145 WeakSelf<Central>::WeakPtr self_{weak_factory_.GetWeakPtr()};
Definition: once_sender.h:42
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:200
#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