BACnet.Stack.LogBufferBehaviour behaviour (bacstack v0.1.0-dev.1)

Copy Markdown View Source

A behaviour for log buffer implementations, most notably for the BACnet.Stack.TrendLogger module.

The behaviour contains the functions from the BACnet.Stack.LogBuffer module, the default log buffer implementation used by BACnet.Stack.TrendLogger.

Using a behaviour allows exchanging the implementation with a different one, for example backed by SQLite.

Summary

Types

The item that gets check in into the log buffer.

A module implementing the Log Buffer Behaviour.

t()

The data structure representing the log buffer.

Callbacks

Checks in an item.

Checks out the oldest item in the log buffer.

Drops the specified amount of oldest items from the log buffer.

Creates a new log buffer from the given list, with an optional max size. The head of the list will be the oldest entry in the log buffer.

Get the size of the log buffer.

Creates a new log buffer with an optional max size.

Peeks into the log buffer and returns the oldest item without removing it.

Peeks into the log buffer and returns the newest item without removing it.

Reads the specified count, starting from the given position (offset), from the log buffer.

Creates a list from the log buffer.

Truncates the log buffer to size zero.

Types

item()

@type item() :: term()

The item that gets check in into the log buffer.

mod()

@type mod() :: module()

A module implementing the Log Buffer Behaviour.

t()

@type t() :: term()

The data structure representing the log buffer.

Callbacks

checkin(buffer, item)

@callback checkin(buffer :: t(), item()) :: t()

Checks in an item.

If the log buffer has a max size, the max size will be maintained (meaning the oldest item gets dropped on overflow).

checkout(buffer)

@callback checkout(buffer :: t()) :: {item :: item() | nil, new_buffer :: t()}

Checks out the oldest item in the log buffer.

If the log buffer is empty, nil will be returned as item.

drop(buffer, amount)

@callback drop(buffer :: t(), amount :: pos_integer()) :: t()

Drops the specified amount of oldest items from the log buffer.

from_list(source, max_size)

@callback from_list(source :: list(), max_size :: pos_integer() | nil) :: t()

Creates a new log buffer from the given list, with an optional max size. The head of the list will be the oldest entry in the log buffer.

If a max size is specified, the list will be truncated to the max size (from the end). The queue length will be calculated in any case. This operation is O(n).

get_size(buffer)

@callback get_size(buffer :: t()) :: non_neg_integer()

Get the size of the log buffer.

new(max_size)

@callback new(max_size :: pos_integer() | nil) :: t()

Creates a new log buffer with an optional max size.

peek(buffer)

@callback peek(buffer :: t()) :: {:ok, item()} | :error

Peeks into the log buffer and returns the oldest item without removing it.

peek_r(buffer)

@callback peek_r(buffer :: t()) :: {:ok, item()} | :error

Peeks into the log buffer and returns the newest item without removing it.

read_range(buffer, offset, count)

@callback read_range(buffer :: t(), offset :: non_neg_integer(), count :: pos_integer()) ::
  [item()]

Reads the specified count, starting from the given position (offset), from the log buffer.

to_list(buffer)

@callback to_list(buffer :: t()) :: [item()]

Creates a list from the log buffer.

truncate(buffer)

@callback truncate(buffer :: t()) :: t()

Truncates the log buffer to size zero.