19#include "lib/stdcompat/utility.h"
20#include "pw_bluetooth/hci_h4.emb.h"
21#include "pw_function/function.h"
22#include "pw_span/span.h"
58 static constexpr std::uint8_t kH4PacketIndicatorSize = 1;
65 : hci_span_(hci_span), h4_type_(h4_type) {}
68 : hci_span_(h4_span.subspan(kH4PacketIndicatorSize)),
69 h4_type_(emboss::H4PacketType{h4_span[0]}) {}
78 emboss::H4PacketType
GetH4Type() final {
return h4_type_; }
80 void SetH4Type(emboss::H4PacketType h4_type)
final { h4_type_ = h4_type; }
89 emboss::H4PacketType h4_type_;
101 : h4_span_(h4_span), release_fn_(std::move(release_fn)) {}
108 H4PacketWithH4(
const H4PacketWithH4& other) =
delete;
109 H4PacketWithH4& operator=(
const H4PacketWithH4& other) =
delete;
111 H4PacketWithH4(H4PacketWithH4&& other)
112 : h4_span_(other.h4_span_), release_fn_(std::move(other.release_fn_)) {
116 H4PacketWithH4& operator=(H4PacketWithH4&& other) {
117 h4_span_ = other.h4_span_;
118 release_fn_ = std::move(other.release_fn_);
123 ~H4PacketWithH4() final {
125 release_fn_(h4_span_.data());
130 if (h4_span_.empty()) {
131 return emboss::H4PacketType::UNKNOWN;
134 return emboss::H4PacketType(h4_span_[0]);
138 if (!h4_span_.empty()) {
139 h4_span_.data()[0] = cpp23::to_underlying(h4_type);
143 bool HasReleaseFn() {
145 return bool{release_fn_};
152 pw::Function<void(
const uint8_t*)> ResetAndReturnReleaseFn() {
153 pw::Function<void(
const uint8_t* packet)> fn = std::move(release_fn_);
160 if (h4_span_.empty()) {
163 return pw::span(h4_span_.data() + kH4PacketIndicatorSize,
164 h4_span_.size() - kH4PacketIndicatorSize);
168 if (h4_span_.empty()) {
177 release_fn_ =
nullptr;
182 pw::Function<void(
const uint8_t* packet)> release_fn_{};
Definition: h4_packet.h:33
H4PacketWithH4 is an H4Packet backed by an H4 buffer.
Definition: h4_packet.h:93
H4PacketWithHci is an H4Packet backed by an HCI buffer.
Definition: h4_packet.h:62
Definition: span_impl.h:235
void SetH4Type(emboss::H4PacketType h4_type) final
Sets HCI packet type indicator.
Definition: h4_packet.h:80
void SetH4Type(emboss::H4PacketType h4_type) final
Sets HCI packet type indicator.
Definition: h4_packet.h:137
emboss::H4PacketType GetH4Type() final
Definition: h4_packet.h:78
pw::span< uint8_t > GetHciSpan() final
Definition: h4_packet.h:82
pw::span< uint8_t > GetHciSpan() final
Definition: h4_packet.h:158
virtual void SetH4Type(emboss::H4PacketType)=0
Sets HCI packet type indicator.
virtual emboss::H4PacketType GetH4Type()=0
H4PacketWithH4(pw::span< uint8_t > h4_span, pw::Function< void(const uint8_t *buffer)> &&release_fn)
release_fn (if callable) will be called when H4PacketWithH4 is destructed.
Definition: h4_packet.h:99
emboss::H4PacketType GetH4Type() final
Definition: h4_packet.h:129
virtual pw::span< uint8_t > GetHciSpan()=0
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73
Lightweight proxy for augmenting Bluetooth functionality.
Definition: h4_packet.h:24