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"
24namespace pw::bluetooth::proxy {
60 H4PacketWithHci(emboss::H4PacketType h4_type, pw::span<uint8_t> hci_span)
61 : hci_span_(hci_span), h4_type_(h4_type) {}
70 emboss::H4PacketType
GetH4Type() final {
return h4_type_; }
72 void SetH4Type(emboss::H4PacketType h4_type)
final { h4_type_ = h4_type; }
74 pw::span<uint8_t>
GetHciSpan() final {
return hci_span_; }
79 pw::span<uint8_t> hci_span_;
81 emboss::H4PacketType h4_type_;
93 : h4_span_(h4_span), release_fn_(std::move(release_fn)) {}
95 H4PacketWithH4(emboss::H4PacketType h4_type, pw::span<uint8_t> h4_span)
100 H4PacketWithH4(
const H4PacketWithH4& other) =
delete;
101 H4PacketWithH4& operator=(
const H4PacketWithH4& other) =
delete;
103 H4PacketWithH4(H4PacketWithH4&& other)
104 : h4_span_(other.h4_span_), release_fn_(std::move(other.release_fn_)) {
108 H4PacketWithH4& operator=(H4PacketWithH4&& other) {
109 h4_span_ = other.h4_span_;
110 release_fn_ = std::move(other.release_fn_);
115 ~H4PacketWithH4() final {
117 release_fn_(h4_span_.data());
122 if (h4_span_.empty()) {
123 return emboss::H4PacketType::UNKNOWN;
126 return emboss::H4PacketType(h4_span_[0]);
130 if (!h4_span_.empty()) {
131 h4_span_.data()[0] = cpp23::to_underlying(h4_type);
135 bool HasReleaseFn() {
137 return bool{release_fn_};
144 pw::Function<void(
const uint8_t*)> ResetAndReturnReleaseFn() {
145 pw::Function<void(
const uint8_t* packet)> fn = std::move(release_fn_);
152 if (h4_span_.empty()) {
155 return pw::span(h4_span_.data() + 1, h4_span_.size() - 1);
158 pw::span<uint8_t> GetH4Span() {
159 if (h4_span_.empty()) {
167 h4_span_ = pw::span<uint8_t>();
168 release_fn_ =
nullptr;
171 pw::span<uint8_t> h4_span_;
173 pw::Function<void(
const uint8_t* packet)> release_fn_{};
Definition: h4_packet.h:31
virtual void SetH4Type(emboss::H4PacketType)=0
Sets HCI packet type indicator.
virtual emboss::H4PacketType GetH4Type()=0
virtual pw::span< uint8_t > GetHciSpan()=0
H4PacketWithH4 is an H4Packet backed by an H4 buffer.
Definition: h4_packet.h:85
void SetH4Type(emboss::H4PacketType h4_type) final
Sets HCI packet type indicator.
Definition: h4_packet.h:129
pw::span< uint8_t > GetHciSpan() final
Definition: h4_packet.h:150
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:91
emboss::H4PacketType GetH4Type() final
Definition: h4_packet.h:121
H4PacketWithHci is an H4Packet backed by an HCI buffer.
Definition: h4_packet.h:58
void SetH4Type(emboss::H4PacketType h4_type) final
Sets HCI packet type indicator.
Definition: h4_packet.h:72
emboss::H4PacketType GetH4Type() final
Definition: h4_packet.h:70
pw::span< uint8_t > GetHciSpan() final
Definition: h4_packet.h:74
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:74