ESPHome 2026.2.2
Loading...
Searching...
No Matches
esphome::api::APIFrameHelper Class Referenceabstract

#include <api_frame_helper.h>

Inheritance diagram for esphome::api::APIFrameHelper:
esphome::api::APINoiseFrameHelper esphome::api::APIPlaintextFrameHelper

Data Structures

struct  SendBuffer
 

Public Member Functions

 APIFrameHelper ()=default
 
 APIFrameHelper (std::unique_ptr< socket::Socket > socket)
 
const char * get_client_name () const
 
const char * get_peername_to (std::span< char, socket::SOCKADDR_STR_LEN > buf) const
 
void set_client_name (const char *name, size_t len)
 
virtual ~APIFrameHelper ()=default
 
virtual APIError init ()=0
 
virtual APIError loop ()
 
virtual APIError read_packet (ReadPacketBuffer *buffer)=0
 
bool can_write_without_blocking ()
 
int getpeername (struct sockaddr *addr, socklen_t *addrlen)
 
APIError close ()
 
APIError shutdown (int how)
 
void set_nodelay_for_message (bool is_log_message)
 
virtual APIError write_protobuf_packet (uint8_t type, ProtoWriteBuffer buffer)=0
 
virtual APIError write_protobuf_messages (ProtoWriteBuffer buffer, std::span< const MessageInfo > messages)=0
 
uint8_t frame_header_padding () const
 
uint8_t frame_footer_size () const
 
bool is_socket_ready () const
 
void release_buffers ()
 

Protected Types

enum class  State : uint8_t {
  INITIALIZE = 1 , CLIENT_HELLO = 2 , SERVER_HELLO = 3 , HANDSHAKE = 4 ,
  DATA = 5 , CLOSED = 6 , FAILED = 7 , EXPLICIT_REJECT = 8
}
 

Protected Member Functions

APIError write_raw_ (const struct iovec *iov, int iovcnt, uint16_t total_write_len)
 
APIError try_send_tx_buf_ ()
 
void buffer_data_from_iov_ (const struct iovec *iov, int iovcnt, uint16_t total_write_len, uint16_t offset)
 
APIError handle_socket_write_error_ ()
 
template<typename StateEnum >
APIError write_raw_ (const struct iovec *iov, int iovcnt, socket::Socket *socket, std::vector< uint8_t > &tx_buf, const std::string &info, StateEnum &state, StateEnum failed_state)
 
void set_nodelay_raw_ (bool enable)
 
APIError init_common_ ()
 
APIError handle_socket_read_result_ (ssize_t received)
 

Protected Attributes

std::unique_ptr< socket::Socketsocket_
 
std::array< std::unique_ptr< SendBuffer >, API_MAX_SEND_QUEUE > tx_buf_
 
std::vector< uint8_t > rx_buf_
 
char client_name_ [CLIENT_INFO_NAME_MAX_LEN] {}
 
uint16_t rx_buf_len_ = 0
 
State state_ {State::INITIALIZE}
 
uint8_t frame_header_padding_ {0}
 
uint8_t frame_footer_size_ {0}
 
uint8_t tx_buf_head_ {0}
 
uint8_t tx_buf_tail_ {0}
 
uint8_t tx_buf_count_ {0}
 
int8_t nodelay_state_ {NODELAY_ON}
 

Static Protected Attributes

static constexpr int8_t NODELAY_ON = -1
 
static constexpr int8_t LOG_NAGLE_COUNT = 2
 

Detailed Description

Definition at line 86 of file api_frame_helper.h.

Member Enumeration Documentation

◆ State

enum class esphome::api::APIFrameHelper::State : uint8_t
strongprotected
Enumerator
INITIALIZE 
CLIENT_HELLO 
SERVER_HELLO 
HANDSHAKE 
DATA 
CLOSED 
FAILED 
EXPLICIT_REJECT 

Definition at line 220 of file api_frame_helper.h.

Constructor & Destructor Documentation

◆ APIFrameHelper() [1/2]

esphome::api::APIFrameHelper::APIFrameHelper ( )
default

◆ APIFrameHelper() [2/2]

esphome::api::APIFrameHelper::APIFrameHelper ( std::unique_ptr< socket::Socket > socket)
inlineexplicit

Definition at line 89 of file api_frame_helper.h.

◆ ~APIFrameHelper()

virtual esphome::api::APIFrameHelper::~APIFrameHelper ( )
virtualdefault

Member Function Documentation

◆ buffer_data_from_iov_()

void esphome::api::APIFrameHelper::buffer_data_from_iov_ ( const struct iovec * iov,
int iovcnt,
uint16_t total_write_len,
uint16_t offset )
protected

Definition at line 125 of file api_frame_helper.cpp.

◆ can_write_without_blocking()

bool esphome::api::APIFrameHelper::can_write_without_blocking ( )
inline

Definition at line 106 of file api_frame_helper.h.

◆ close()

APIError esphome::api::APIFrameHelper::close ( )
inline

Definition at line 108 of file api_frame_helper.h.

◆ frame_footer_size()

uint8_t esphome::api::APIFrameHelper::frame_footer_size ( ) const
inline

Definition at line 168 of file api_frame_helper.h.

◆ frame_header_padding()

uint8_t esphome::api::APIFrameHelper::frame_header_padding ( ) const
inline

Definition at line 166 of file api_frame_helper.h.

◆ get_client_name()

const char * esphome::api::APIFrameHelper::get_client_name ( ) const
inline

Definition at line 92 of file api_frame_helper.h.

◆ get_peername_to()

const char * esphome::api::APIFrameHelper::get_peername_to ( std::span< char, socket::SOCKADDR_STR_LEN > buf) const

Definition at line 248 of file api_frame_helper.cpp.

◆ getpeername()

int esphome::api::APIFrameHelper::getpeername ( struct sockaddr * addr,
socklen_t * addrlen )
inline

Definition at line 107 of file api_frame_helper.h.

◆ handle_socket_read_result_()

APIError esphome::api::APIFrameHelper::handle_socket_read_result_ ( ssize_t received)
protected

Definition at line 279 of file api_frame_helper.cpp.

◆ handle_socket_write_error_()

APIError esphome::api::APIFrameHelper::handle_socket_write_error_ ( )
protected

Definition at line 115 of file api_frame_helper.cpp.

◆ init()

virtual APIError esphome::api::APIFrameHelper::init ( )
pure virtual

◆ init_common_()

APIError esphome::api::APIFrameHelper::init_common_ ( )
protected

Definition at line 257 of file api_frame_helper.cpp.

◆ is_socket_ready()

bool esphome::api::APIFrameHelper::is_socket_ready ( ) const
inline

Definition at line 170 of file api_frame_helper.h.

◆ loop()

APIError esphome::api::APIFrameHelper::loop ( )
virtual

◆ read_packet()

virtual APIError esphome::api::APIFrameHelper::read_packet ( ReadPacketBuffer * buffer)
pure virtual

◆ release_buffers()

void esphome::api::APIFrameHelper::release_buffers ( )
inline

Definition at line 172 of file api_frame_helper.h.

◆ set_client_name()

void esphome::api::APIFrameHelper::set_client_name ( const char * name,
size_t len )
inline

Definition at line 97 of file api_frame_helper.h.

◆ set_nodelay_for_message()

void esphome::api::APIFrameHelper::set_nodelay_for_message ( bool is_log_message)
inline

Definition at line 140 of file api_frame_helper.h.

◆ set_nodelay_raw_()

void esphome::api::APIFrameHelper::set_nodelay_raw_ ( bool enable)
inlineprotected

Definition at line 254 of file api_frame_helper.h.

◆ shutdown()

APIError esphome::api::APIFrameHelper::shutdown ( int how)
inline

Definition at line 117 of file api_frame_helper.h.

◆ try_send_tx_buf_()

APIError esphome::api::APIFrameHelper::try_send_tx_buf_ ( )
protected

Definition at line 217 of file api_frame_helper.cpp.

◆ write_protobuf_messages()

virtual APIError esphome::api::APIFrameHelper::write_protobuf_messages ( ProtoWriteBuffer buffer,
std::span< const MessageInfo > messages )
pure virtual

◆ write_protobuf_packet()

virtual APIError esphome::api::APIFrameHelper::write_protobuf_packet ( uint8_t type,
ProtoWriteBuffer buffer )
pure virtual

◆ write_raw_() [1/2]

template<typename StateEnum >
APIError esphome::api::APIFrameHelper::write_raw_ ( const struct iovec * iov,
int iovcnt,
socket::Socket * socket,
std::vector< uint8_t > & tx_buf,
const std::string & info,
StateEnum & state,
StateEnum failed_state )
protected

◆ write_raw_() [2/2]

APIError esphome::api::APIFrameHelper::write_raw_ ( const struct iovec * iov,
int iovcnt,
uint16_t total_write_len )
protected

Definition at line 165 of file api_frame_helper.cpp.

Field Documentation

◆ client_name_

char esphome::api::APIFrameHelper::client_name_[CLIENT_INFO_NAME_MAX_LEN] {}
protected

Definition at line 236 of file api_frame_helper.h.

◆ frame_footer_size_

uint8_t esphome::api::APIFrameHelper::frame_footer_size_ {0}
protected

Definition at line 242 of file api_frame_helper.h.

◆ frame_header_padding_

uint8_t esphome::api::APIFrameHelper::frame_header_padding_ {0}
protected

Definition at line 241 of file api_frame_helper.h.

◆ LOG_NAGLE_COUNT

int8_t esphome::api::APIFrameHelper::LOG_NAGLE_COUNT = 2
staticconstexprprotected

Definition at line 250 of file api_frame_helper.h.

◆ NODELAY_ON

int8_t esphome::api::APIFrameHelper::NODELAY_ON = -1
staticconstexprprotected

Definition at line 249 of file api_frame_helper.h.

◆ nodelay_state_

int8_t esphome::api::APIFrameHelper::nodelay_state_ {NODELAY_ON}
protected

Definition at line 251 of file api_frame_helper.h.

◆ rx_buf_

std::vector<uint8_t> esphome::api::APIFrameHelper::rx_buf_
protected

Definition at line 233 of file api_frame_helper.h.

◆ rx_buf_len_

uint16_t esphome::api::APIFrameHelper::rx_buf_len_ = 0
protected

Definition at line 239 of file api_frame_helper.h.

◆ socket_

std::unique_ptr<socket::Socket> esphome::api::APIFrameHelper::socket_
protected

Definition at line 210 of file api_frame_helper.h.

◆ state_

State esphome::api::APIFrameHelper::state_ {State::INITIALIZE}
protected

Definition at line 240 of file api_frame_helper.h.

◆ tx_buf_

std::array<std::unique_ptr<SendBuffer>, API_MAX_SEND_QUEUE> esphome::api::APIFrameHelper::tx_buf_
protected

Definition at line 232 of file api_frame_helper.h.

◆ tx_buf_count_

uint8_t esphome::api::APIFrameHelper::tx_buf_count_ {0}
protected

Definition at line 245 of file api_frame_helper.h.

◆ tx_buf_head_

uint8_t esphome::api::APIFrameHelper::tx_buf_head_ {0}
protected

Definition at line 243 of file api_frame_helper.h.

◆ tx_buf_tail_

uint8_t esphome::api::APIFrameHelper::tx_buf_tail_ {0}
protected

Definition at line 244 of file api_frame_helper.h.


The documentation for this class was generated from the following files: