LexLeo 0.0.0-dev+f8e5087-dirty
Technical documentation
Loading...
Searching...
No Matches
stdio_stream.c File Reference

stdio_stream adapter implementation. More...

Include dependency graph for stdio_stream.c:

Go to the source code of this file.

Functions

stdio_stream_cfg_t stdio_stream_default_cfg (void)
 Return a default configuration for the stdio_stream adapter.
 
stdio_stream_env_t stdio_stream_default_env (const osal_stdio_ops_t *stdio_ops, const osal_mem_ops_t *mem, const stream_env_t *port_env)
 Build a default environment for the stdio_stream adapter.
 
static size_t stdio_stream_read (void *backend, void *buf, size_t n, stream_status_t *st)
 
static size_t stdio_stream_write (void *backend, const void *buf, size_t n, stream_status_t *st)
 
static stream_status_t stdio_stream_flush (void *backend)
 
static stream_status_t stdio_stream_close (void *backend)
 
stream_status_t stdio_stream_create_stream (stream_t **out, const stdio_stream_args_t *args, const stdio_stream_cfg_t *cfg, const stdio_stream_env_t *env)
 Create a standard-I/O-backed stream instance.
 
static void stdio_stream_destroy_ud_ctor (const void *ud, const osal_mem_ops_t *mem)
 
stream_status_t stdio_stream_create_desc (stream_adapter_desc_t *out, stream_key_t key, const stdio_stream_cfg_t *cfg, const stdio_stream_env_t *env, const osal_mem_ops_t *mem)
 Build a stream adapter descriptor for the stdio_stream adapter.
 
stream_status_t stdio_stream_ctor (const void *ud, const void *args, stream_t **out)
 Factory-compatible constructor callback for the stdio_stream adapter.
 

Variables

static const stream_vtbl_t STDIO_STREAM_VTBL
 

Detailed Description

This module implements the stdio_stream adapter, which exposes the process standard I/O streams (stdin, stdout, and stderr) through the generic stream port.

Definition in file stdio_stream.c.

Function Documentation

◆ stdio_stream_close()

static stream_status_t stdio_stream_close ( void *  backend)
static

Definition at line 136 of file stdio_stream.c.

◆ stdio_stream_create_desc()

stream_status_t stdio_stream_create_desc ( stream_adapter_desc_t out,
stream_key_t  key,
const stdio_stream_cfg_t cfg,
const stdio_stream_env_t env,
const osal_mem_ops_t mem 
)
Parameters
outOutput location that receives the constructed adapter descriptor on success.
keyBorrowed adapter registration key.
cfgBorrowed adapter configuration copied into descriptor-owned constructor data.
envBorrowed adapter environment copied into descriptor-owned constructor data.
memBorrowed memory operations table used to allocate the descriptor-owned constructor data.
Return values
STREAM_STATUS_OKThe descriptor was created successfully.
STREAM_STATUS_INVALIDOne or more arguments are invalid.
STREAM_STATUS_OOMMemory allocation failed.

The descriptor produced by this function is intended to be registered into a stream factory. The constructor user data allocated for that descriptor is owned by the descriptor lifecycle and must therefore use the factory memory operations.

Definition at line 245 of file stdio_stream.c.

◆ stdio_stream_create_stream()

stream_status_t stdio_stream_create_stream ( stream_t **  out,
const stdio_stream_args_t args,
const stdio_stream_cfg_t cfg,
const stdio_stream_env_t env 
)

This function allocates and initializes a public stream_t whose backend wraps stdin, stdout, or stderr according to args->kind.

Ownership:

  • On success, a newly allocated stream is returned in *out.
  • The caller becomes responsible for destroying it via stream_destroy().
  • On failure, *out is left unchanged.
Parameters
[out]outReceives the created stream handle. Must not be NULL.
[in]argsCreation arguments selecting which standard I/O stream is wrapped by the created adapter instance. Must not be NULL.
[in]cfgAdapter configuration. Must not be NULL.
[in]envAdapter environment containing injected dependencies. Must not be NULL.
Return values
STREAM_STATUS_OKStream successfully created.
STREAM_STATUS_INVALIDOne or more arguments are invalid.
STREAM_STATUS_OOMMemory allocation failed.

Definition at line 156 of file stdio_stream.c.

◆ stdio_stream_ctor()

stream_status_t stdio_stream_ctor ( const void *  ud,
const void *  args,
stream_t **  out 
)
Parameters
udBorrowed adapter-specific constructor user data.
argsBorrowed creation arguments expected by the adapter factory contract.
outOutput location that receives the created stream_t * on success.
Return values
STREAM_STATUS_OKThe stream was created successfully.
STREAM_STATUS_INVALIDOne or more arguments are invalid.
STREAM_STATUS_OOMMemory allocation failed.

This callback is intended to be stored in a stream_adapter_desc_t and invoked through the stream factory contract.

Definition at line 289 of file stdio_stream.c.

◆ stdio_stream_default_cfg()

stdio_stream_cfg_t stdio_stream_default_cfg ( void  )

This helper provides a value-initialized baseline configuration that the Composition Root may override.

Returns
A well-formed default stdio_stream_cfg_t.

Definition at line 27 of file stdio_stream.c.

◆ stdio_stream_default_env()

stdio_stream_env_t stdio_stream_default_env ( const osal_stdio_ops_t stdio_ops,
const osal_mem_ops_t mem,
const stream_env_t port_env 
)

This helper packages borrowed dependencies into a value-initialized stdio_stream_env_t.

The returned environment does not take ownership of any pointer passed as argument.

Parameters
stdio_opsBorrowed OSAL stdio operations table used by the adapter backend to access the standard streams and the stdio primitives required to implement the stream port contract.
memBorrowed memory operations table used by the adapter backend.
[in]port_envBorrowed stream port environment.
Returns
A well-formed stdio_stream_env_t aggregating the provided dependencies.

Definition at line 31 of file stdio_stream.c.

◆ stdio_stream_destroy_ud_ctor()

static void stdio_stream_destroy_ud_ctor ( const void *  ud,
const osal_mem_ops_t mem 
)
static

Definition at line 233 of file stdio_stream.c.

◆ stdio_stream_flush()

static stream_status_t stdio_stream_flush ( void *  backend)
static

Definition at line 113 of file stdio_stream.c.

◆ stdio_stream_read()

static size_t stdio_stream_read ( void *  backend,
void *  buf,
size_t  n,
stream_status_t st 
)
static

Definition at line 45 of file stdio_stream.c.

◆ stdio_stream_write()

static size_t stdio_stream_write ( void *  backend,
const void *  buf,
size_t  n,
stream_status_t st 
)
static

Definition at line 79 of file stdio_stream.c.

Variable Documentation

◆ STDIO_STREAM_VTBL

const stream_vtbl_t STDIO_STREAM_VTBL
static
Initial value:
= {
}
static stream_status_t stdio_stream_flush(void *backend)
static stream_status_t stdio_stream_close(void *backend)
static size_t stdio_stream_write(void *backend, const void *buf, size_t n, stream_status_t *st)
static size_t stdio_stream_read(void *backend, void *buf, size_t n, stream_status_t *st)

Definition at line 149 of file stdio_stream.c.