PebbleOS
Loading...
Searching...
No Matches
Typedefs | Functions

Build an outbound message piecemeal in a kernel-heap buffer. More...

Typedefs

typedef struct SendBuffer SendBuffer
 Opaque buffer holding one outbound message.
 

Functions

size_t comm_session_send_buffer_get_max_payload_length (const CommSession *session)
 Get the largest payload a send buffer can hold.
 
SendBuffer * comm_session_send_buffer_begin_write (CommSession *session, uint16_t endpoint_id, size_t required_free_length, uint32_t timeout_ms)
 Allocate a kernel-heap buffer for an outbound message.
 
bool comm_session_send_buffer_write (SendBuffer *send_buffer, const uint8_t *data, size_t length)
 Append payload data to a send buffer.
 
void comm_session_send_buffer_end_write (SendBuffer *send_buffer)
 Finish a message and queue it for sending.
 

Detailed Description

Build an outbound message piecemeal in a kernel-heap buffer.

SendBuffer *sb = comm_session_send_buffer_begin_write(session, endpoint_id, sizeof(hdr) + len,
if (sb) {
comm_session_send_buffer_write(sb, (const uint8_t *)&hdr, sizeof(hdr));
}
bool comm_session_send_buffer_write(SendBuffer *send_buffer, const uint8_t *data, size_t length)
Append payload data to a send buffer.
struct SendBuffer SendBuffer
Opaque buffer holding one outbound message.
Definition session_send_buffer.h:26
SendBuffer * comm_session_send_buffer_begin_write(CommSession *session, uint16_t endpoint_id, size_t required_free_length, uint32_t timeout_ms)
Allocate a kernel-heap buffer for an outbound message.
void comm_session_send_buffer_end_write(SendBuffer *send_buffer)
Finish a message and queue it for sending.
#define COMM_SESSION_DEFAULT_TIMEOUT
Default send timeout in milliseconds.
Definition session.h:103

Typedef Documentation

◆ SendBuffer

typedef struct SendBuffer SendBuffer

Opaque buffer holding one outbound message.

Function Documentation

◆ comm_session_send_buffer_begin_write()

SendBuffer * comm_session_send_buffer_begin_write ( CommSession *  session,
uint16_t  endpoint_id,
size_t  required_free_length,
uint32_t  timeout_ms 
)

Allocate a kernel-heap buffer for an outbound message.

Blocks until enough space is available or the timeout expires. Must be followed by comm_session_send_buffer_end_write(). bt_lock() must not be held. Use comm_session_send_queue_add_job() to avoid the kernel-heap allocation, or comm_session_send_data() to send a message in one call.

Parameters
sessionDestination session.
endpoint_idPebble Protocol endpoint ID.
required_free_lengthPayload space in bytes guaranteed to be available on success.
timeout_msMaximum time to wait for the space.
Returns
Send buffer, or NULL on timeout, if the length exceeds the maximum payload, or if session is not valid.

◆ comm_session_send_buffer_end_write()

void comm_session_send_buffer_end_write ( SendBuffer *  send_buffer)

Finish a message and queue it for sending.

Ownership of send_buffer passes to the send queue. bt_lock() may be held.

Parameters
send_bufferBuffer from comm_session_send_buffer_begin_write().

◆ comm_session_send_buffer_get_max_payload_length()

size_t comm_session_send_buffer_get_max_payload_length ( const CommSession *  session)

Get the largest payload a send buffer can hold.

Parameters
sessionDestination session.
Returns
Maximum payload length in bytes, or 0 if session is not valid.

◆ comm_session_send_buffer_write()

bool comm_session_send_buffer_write ( SendBuffer *  send_buffer,
const uint8_t *  data,
size_t  length 
)

Append payload data to a send buffer.

bt_lock() may be held.

Parameters
send_bufferBuffer from comm_session_send_buffer_begin_write().
dataData to append.
lengthLength of data in bytes.
Returns
True if appended; false if it does not fit. Writes within the required_free_length passed to comm_session_send_buffer_begin_write() always fit.