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

fs_stream adapter implementation (OSAL file backend). More...

Include dependency graph for fs_stream.c:

Go to the source code of this file.

Functions

static stream_status_t map_osal_status (osal_file_status_t osal_st)
 
static size_t fs_stream_read (void *backend, void *buf, size_t n, stream_status_t *st)
 
static size_t fs_stream_write (void *backend, const void *buf, size_t n, stream_status_t *st)
 
static stream_status_t fs_stream_flush (void *backend)
 
static stream_status_t fs_stream_close (void *backend)
 
static stream_status_t create_backend (fs_stream_t **out, const fs_stream_args_t *args, const fs_stream_cfg_t *cfg, const fs_stream_env_t *env)
 
static void destroy_backend (fs_stream_t **p)
 
static void fs_stream_destroy_ud_ctor (const void *ud, const osal_mem_ops_t *mem)
 
stream_status_t fs_stream_create_stream (stream_t **out, const fs_stream_args_t *args, const fs_stream_cfg_t *cfg, const fs_stream_env_t *env)
 Create a file-backed stream instance.
 
stream_status_t fs_stream_ctor (const void *ud, const void *args, stream_t **out)
 Factory constructor callback for the fs_stream adapter.
 
stream_status_t fs_stream_create_desc (stream_adapter_desc_t *out, stream_key_t key, const fs_stream_cfg_t *cfg, const fs_stream_env_t *env, const osal_mem_ops_t *mem)
 Build an adapter descriptor for registering fs_stream in a factory.
 
fs_stream_cfg_t fs_stream_default_cfg (void)
 Return a default configuration for the fs_stream adapter.
 
fs_stream_env_t fs_stream_default_env (const osal_file_env_t *file_env, const osal_file_ops_t *file_ops, const stream_env_t *port_env)
 Build a default environment for the fs_stream adapter.
 

Variables

static const stream_vtbl_t VTBL
 

Detailed Description

File-backed stream adapter. This module is a thin wrapper around OSAL file operations.

Definition in file fs_stream.c.

Function Documentation

◆ create_backend()

static stream_status_t create_backend ( fs_stream_t **  out,
const fs_stream_args_t args,
const fs_stream_cfg_t cfg,
const fs_stream_env_t env 
)
static

Definition at line 134 of file fs_stream.c.

◆ destroy_backend()

static void destroy_backend ( fs_stream_t **  p)
static

Definition at line 183 of file fs_stream.c.

◆ fs_stream_close()

static stream_status_t fs_stream_close ( void *  backend)
static

Definition at line 109 of file fs_stream.c.

◆ fs_stream_create_desc()

stream_status_t fs_stream_create_desc ( stream_adapter_desc_t out,
stream_key_t  key,
const fs_stream_cfg_t cfg,
const fs_stream_env_t env,
const osal_mem_ops_t mem 
)

The Composition Root uses this function to build a stream_adapter_desc_t suitable for registration into the stream factory, for example via stream_factory_add_adapter().

Memory policy:

  • mem must be the allocator that will later be used to destroy the descriptor-owned user data through ud_dtor.
Parameters
[out]outDescriptor to initialize. Must not be NULL.

On failure, if out != NULL, *out is reset to an empty descriptor.

Parameters
[in]keyAdapter key used by the factory to select this adapter. Must not be NULL and must not be an empty string.
[in]cfgAdapter configuration to bind into the descriptor. Must not be NULL.
[in]envAdapter environment to bind into the descriptor. Must not be NULL.
[in]memMemory operations used to allocate descriptor-owned user data. Must not be NULL.
Return values
STREAM_STATUS_OKDescriptor successfully created.
STREAM_STATUS_INVALIDOne or more arguments are invalid.
STREAM_STATUS_OOMAllocation of descriptor-owned user data failed.

Definition at line 256 of file fs_stream.c.

◆ fs_stream_create_stream()

stream_status_t fs_stream_create_stream ( stream_t **  out,
const fs_stream_args_t args,
const fs_stream_cfg_t cfg,
const fs_stream_env_t env 
)

This function allocates and initializes a public stream_t whose backend is an OSAL file opened according to the parameters provided in fs_stream_args_t.

The underlying OSAL file is opened through the file operations injected in the adapter environment.

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 describing the file to open. Must not be NULL.

Contract:

  • args->path must not be NULL and must not be an empty string.
  • args->flags must not be zero.
Parameters
[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.
STREAM_STATUS_IO_ERRORThe underlying OSAL file operation failed.

Definition at line 208 of file fs_stream.c.

◆ fs_stream_ctor()

stream_status_t fs_stream_ctor ( const void *  ud,
const void *  args,
stream_t **  out 
)

This function implements the stream_ctor_fn_t contract expected by the stream port factory.

The opaque user-data pointer ud is expected to reference a fs_stream_ctor_ud_t structure containing the configuration and environment required to construct the stream instance.

The args parameter is the runtime argument blob supplied by the factory when creating a stream instance. It is expected to point to a const fs_stream_args_t * describing the file to open.

Parameters
[in]udOpaque user data stored in the adapter descriptor.

Expected type:

Parameters
[in]argsRuntime argument blob supplied by the factory.

Expected type:

Parameters
[out]outReceives the created stream handle.
Returns
  • STREAM_STATUS_OK on success
  • STREAM_STATUS_INVALID if one or more arguments are invalid
  • STREAM_STATUS_OOM on allocation failure
  • STREAM_STATUS_IO_ERROR if the underlying OSAL file operation fails
Postcondition
On success, *out receives a newly created stream instance owned by the caller.

On failure, *out is left unchanged.

Definition at line 233 of file fs_stream.c.

◆ fs_stream_default_cfg()

fs_stream_cfg_t fs_stream_default_cfg ( void  )

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

Returns
A well-formed default fs_stream_cfg_t.

Definition at line 294 of file fs_stream.c.

◆ fs_stream_default_env()

fs_stream_env_t fs_stream_default_env ( const osal_file_env_t file_env,
const osal_file_ops_t file_ops,
const stream_env_t port_env 
)

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

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

Parameters
[in]file_envBorrowed OSAL file environment.
[in]file_opsBorrowed OSAL file operations table.
[in]port_envBorrowed stream port environment.
Returns
A well-formed fs_stream_env_t aggregating the provided dependencies.

Definition at line 298 of file fs_stream.c.

◆ fs_stream_destroy_ud_ctor()

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

Definition at line 199 of file fs_stream.c.

◆ fs_stream_flush()

static stream_status_t fs_stream_flush ( void *  backend)
static

Definition at line 92 of file fs_stream.c.

◆ fs_stream_read()

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

Definition at line 42 of file fs_stream.c.

◆ fs_stream_write()

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

Definition at line 63 of file fs_stream.c.

◆ map_osal_status()

static stream_status_t map_osal_status ( osal_file_status_t  osal_st)
static

Definition at line 22 of file fs_stream.c.

Variable Documentation

◆ VTBL

const stream_vtbl_t VTBL
static
Initial value:
= {
.read = fs_stream_read,
.write = fs_stream_write,
.flush = fs_stream_flush,
.close = fs_stream_close
}
static stream_status_t fs_stream_close(void *backend)
Definition fs_stream.c:109
static size_t fs_stream_read(void *backend, void *buf, size_t n, stream_status_t *st)
Definition fs_stream.c:42
static size_t fs_stream_write(void *backend, const void *buf, size_t n, stream_status_t *st)
Definition fs_stream.c:63
static stream_status_t fs_stream_flush(void *backend)
Definition fs_stream.c:92

Definition at line 127 of file fs_stream.c.