Skip to main content

API

The interactor is the main entity to process Native -> Dart interaction.

interactor_nativeโ€‹

Declaration
typedef struct interactor_native
{
uint8_t id;
int32_t descriptor;
struct interactor_messages_pool messages_pool;
struct interactor_buffers_pool buffers_pool;
struct interactor_data_pool data_pool;
struct interactor_memory memory;
struct io_uring* ring;
struct iovec* buffers;
uint32_t buffer_size;
uint16_t buffers_count;
size_t ring_size;
int ring_flags;
struct io_uring_cqe** cqes;
uint64_t cqe_wait_timeout_millis;
uint32_t cqe_wait_count;
uint32_t cqe_peek_count;
void* callbacks;
} interactor_native_t;

int interactor_native_initialize(interactor_native_t* interactor, interactor_native_configuration_t* configuration, uint8_t id);

int interactor_native_initialize_default(interactor_native_t* interactor, uint8_t id);

void interactor_native_register_callback(interactor_native_t* interactor, uint64_t owner, uint64_t method, void (*callback)(interactor_message*));

int32_t interactor_native_get_buffer(interactor_native_t* interactor);

void interactor_native_release_buffer(interactor_native_t* interactor, uint16_t buffer_id);

int32_t interactor_native_available_buffers(interactor_native_t* interactor);

int32_t interactor_native_used_buffers(interactor_native_t* interactor);

interactor_message* interactor_native_allocate_message(interactor_native_t* interactor);

void interactor_native_free_message(interactor_native_t* interactor, interactor_message* message);

struct interactor_payload_pool* interactor_native_payload_pool_create(interactor_native_t* interactor, size_t size);

intptr_t interactor_native_payload_allocate(struct interactor_payload_pool* pool);

void interactor_native_payload_free(struct interactor_payload_pool* pool, intptr_t pointer);

void interactor_native_payload_pool_destroy(struct interactor_payload_pool* pool);

intptr_t interactor_native_data_allocate(interactor_native_t* interactor, size_t size);

void interactor_native_data_free(interactor_native_t* interactor, intptr_t pointer, size_t size);

void interactor_native_process_infinity(interactor_native_t* interactor);

void interactor_native_process_timeout(interactor_native_t* interactor);

void interactor_native_foreach(interactor_native_t* interactor, void (*call)(interactor_message*), void (*callback)(interactor_message*));

int interactor_native_submit(interactor_native_t* interactor);

void interactor_native_call_dart(interactor_native_t* interactor, int target_ring_fd, interactor_message* message);

void interactor_native_callback_to_dart(interactor_native_t* interactor, interactor_message* message);

void interactor_native_destroy(interactor_native_t* interactor);

void interactor_native_close_descriptor(int fd);

Propertiesโ€‹

idโ€‹

Interactor identifier.

descriptorโ€‹

Interactor io_uring fd.

messages_poolโ€‹

Message pool instance.

buffers_poolโ€‹

Buffers pool instance.

data_poolโ€‹

Data pool instance.

memoryโ€‹

Memory holder managed by interactor.

ringโ€‹

IO_Uring managed by interactor.

buffersโ€‹

Allocated buffer array.

buffer_sizeโ€‹

Max buffer size available in the buffers pool.

buffers_countโ€‹

Max buffers that are available in the buffers pool.

ring_sizeโ€‹

Size of io_uring.

ring_flagsโ€‹

Flags of io_uring.

cqesโ€‹

IO_Uring CQE array for processing events.

cqe_wait_timeout_millisโ€‹

How long cqes should be waited on each loop iteration.

cqe_wait_countโ€‹

How many CQES should be waited on each loop iteration.

cqe_peek_countโ€‹

How many CQES should be taken on each loop iteration.

callbacksโ€‹

Interactor callbacks registry.

Functionsโ€‹

interactor_native_initializeโ€‹

Allocate all needed entities, set up io_uring, and initialize interactor fields.

interactor_native_initialize_defaultโ€‹

Allocate all needed entities, set up io_uring, and initialize interactor fields with default configuration values.

interactor_native_register_callbackโ€‹

Add a new callback to the registry.

interactor_native_get_bufferโ€‹

Allocate new buffer in the pool.

interactor_native_release_bufferโ€‹

Free buffer in the pool.

interactor_native_available_buffersโ€‹

Currently available buffers in the pool.

interactor_native_used_buffersโ€‹

Currently used buffers in the pool.

interactor_native_allocate_messageโ€‹

Allocate a new message in the pool.

interactor_native_free_messageโ€‹

Free the message in the pool.

interactor_native_payload_pool_createโ€‹

Create a new pool for the fixed-size structures.

interactor_native_payload_allocateโ€‹

Allocate a payload in the pool.

interactor_native_payload_freeโ€‹

Free the payload in the pool.

interactor_native_payload_pool_destroyโ€‹

Destroy the pool for the fixed-size structures.

interactor_native_data_allocateโ€‹

Allocate a dynamic memory in the pool.

interactor_native_data_freeโ€‹

Free the dynamic memory in the pool.

interactor_native_process_infinityโ€‹

Call interactor_native_peek_infinity and processing events:

  • For call events get a method pointer from the message and execute the method
  • For callback events get a method from the message and call callback from the registry if exists
interactor_native_process_timeoutโ€‹

Call interactor_native_peek_timeout and process events:

  • For call events get a method pointer from the message and execute the method
  • For callback events get a method from the message and call callback from the registry if exists
interactor_native_foreachโ€‹

Iterate over CQEs:

  • For call events get a method pointer from the message and execute the method
  • For callback events get a method from the message and call callback from the registry if exists
interactor_native_submitโ€‹

Submit io_uring.

interactor_native_call_dartโ€‹

Prepare a message for calling a Dart method.

interactor_native_callback_to_dartโ€‹

Prepare a message for executing a callback to the Dart (useful when you don't want to use interactor_native_process_ and handle messages manually).

interactor_native_destroyโ€‹

Free all allocated memory and shutdown the io_uring.

interactor_native_close_descriptorโ€‹

Just close Linux fd.

note

Interactor callbacks are used for handling callbacks from the Dart side on calls from the Native side.

References