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"
57 H4PacketInterface& operator=(
const H4PacketInterface& other) =
default;
59 static constexpr std::uint8_t kH4PacketIndicatorSize = 1;
69 : hci_span_(hci_span), h4_type_(h4_type) {}
72 : hci_span_(h4_span.subspan(kH4PacketIndicatorSize)),
73 h4_type_(emboss::H4PacketType{h4_span[0]}) {}
82 emboss::H4PacketType
GetH4Type() const final {
return h4_type_; }
84 void SetH4Type(emboss::H4PacketType h4_type)
final { h4_type_ = h4_type; }
91 emboss::H4PacketType h4_type_;
99 using ReleaseFn =
Function<void(
const uint8_t*)>;
106 : h4_span_(h4_span), release_fn_(std::move(release_fn)) {}
113 H4PacketWithH4(
const H4PacketWithH4& other) =
delete;
114 H4PacketWithH4& operator=(
const H4PacketWithH4& other) =
delete;
116 H4PacketWithH4(H4PacketWithH4&& other)
117 : h4_span_(other.h4_span_), release_fn_(std::move(other.release_fn_)) {
121 H4PacketWithH4& operator=(H4PacketWithH4&& other) {
122 h4_span_ = other.h4_span_;
123 release_fn_ = std::move(other.release_fn_);
128 ~H4PacketWithH4() final {
130 release_fn_(h4_span_.data());
135 if (h4_span_.empty()) {
136 return emboss::H4PacketType::UNKNOWN;
139 return emboss::H4PacketType(h4_span_[0]);
143 if (!h4_span_.empty()) {
144 h4_span_.data()[0] = cpp23::to_underlying(h4_type);
148 bool HasReleaseFn() {
150 return bool{release_fn_};
157 ReleaseFn ResetAndReturnReleaseFn() {
158 ReleaseFn fn = std::move(release_fn_);
164 if (h4_span_.empty()) {
173 release_fn_ =
nullptr;
178 ReleaseFn release_fn_{};
182 if (h4_span_.empty()) {
185 return pw::span(h4_span_.data() + kH4PacketIndicatorSize,
186 h4_span_.size() - kH4PacketIndicatorSize);
Definition: h4_packet.h:33
H4PacketWithH4 is an H4Packet backed by an H4 buffer.
Definition: h4_packet.h:97
H4PacketWithHci is an H4Packet backed by an HCI buffer.
Definition: h4_packet.h:66
Definition: span_impl.h:235
void SetH4Type(emboss::H4PacketType h4_type) final
Sets HCI packet type indicator.
Definition: h4_packet.h:84
virtual emboss::H4PacketType GetH4Type() const =0
void SetH4Type(emboss::H4PacketType h4_type) final
Sets HCI packet type indicator.
Definition: h4_packet.h:142
emboss::H4PacketType GetH4Type() const final
Definition: h4_packet.h:82
H4PacketWithH4(pw::span< uint8_t > h4_span, ReleaseFn &&release_fn)
release_fn (if callable) will be called when H4PacketWithH4 is destructed.
Definition: h4_packet.h:105
emboss::H4PacketType GetH4Type() const final
Definition: h4_packet.h:134
virtual void SetH4Type(emboss::H4PacketType)=0
Sets HCI packet type indicator.
pw::span< uint8_t > GetHciSpan()
Definition: h4_packet.h:53
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