reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
Utilities

Useful functions for application developers. More...

Files

file  audio_loop.h
 Utility function for playing audio on Linux or MacOS.
file  deque.h
 Implementation of a double-ended queue.
file  generics.h
 This file provides macros for Generic Reactors in C-Target.
file  hashmap.h
 Defines a generic, non-resizing hashmap data type.
file  hashset.h
 A hash set implementation in C.
file  hashset_itr.h
 A C hashset iterator implemenation.
file  pointer_hashmap.h
 Defines a hashmap type that maps void pointers to integers.
file  sensor_simulator.h
 Simple terminal-based user interface based on ncurses.
file  type_converter.h
 This file provides macro DO_CONVERT(fromType, toType, value).
file  wave_file_reader.h
 Utility function for reading WAV audio files.

Data Structures

struct  deque_t
 A double-ended queue data structure. More...
struct  hashmap_entry_t
 A hashmap entry. More...
struct  hashmap_t
 A hashmap. More...
struct  hashset_itr_st
 A hashset iterator. More...
struct  hashset_st
 A hashset. More...
struct  lf_waveform_t
 Waveform in 16-bit linear-PCM format. More...
struct  vector_t
 A vector (resizing array) data type. More...

Macros

#define AUDIO_BUFFER_SIZE   4410
 Size of the audio buffer.
#define BUFFER_DURATION_NS   100000000LL
 Duration of the audio buffer.
#define DO_CONVERT(fromType, toType, value)
 Convert the specified value from one type to another.
#define lf_decay(p)
 Decay the specified pointer.
#define lf_get_pointer(p)
 Return the pointer for specified p.
#define lf_is_pointer(p)
 Check whether the passed variable p is a pointer.
#define lf_is_pointer_or_array(p)
 Check whether the passed variable p is an array or a pointer.
#define lf_is_same(typename, b)
 Check whether the type of b is same as the specified typename.
#define lf_is_same_type(a, b)
 Check whether the types of both a and b are same.
#define lf_is_type_equal(typename_a, typename_b)
 Check whether the type of typename_a is same as the type of typename_b.
#define lf_to_left_type(left, right)
 Check types for both left and right and return appropriate value based on left type.
#define MAX_AMPLITUDE   32765
 Maximum amplitude for audio playback.
#define NUM_CHANNELS   1
 Number of channels for audio playback.
#define NUM_NOTES   8
 Maximum number of notes that can play simultaneously.
#define SAMPLE_RATE   44100
 Sample rate for audio playback.

Typedefs

typedef struct deque_t deque_t
 A double-ended queue data structure.
typedef struct hashmap_entry_t hashmap_entry_t
 A hashmap entry.
typedef struct hashmap_t hashmap_t
 A hashmap.
typedef struct lf_waveform_t lf_waveform_t
 Waveform in 16-bit linear-PCM format.
typedef struct vector_t vector_t
 A vector (resizing array) data type.

Functions

void add_to_sound (int index_offset, double value)
 Add the given value to the current write buffer at the specified index.
void deque_initialize (deque_t *d)
 Initialize the specified deque to an empty deque.
bool deque_is_empty (deque_t *d)
 Return true if the queue is empty.
void * deque_peek_back (deque_t *d)
 Peek at the value on the front of the queue, leaving it on the queue.
void * deque_peek_front (deque_t *d)
 Peek at the value on the back of the queue, leaving it on the queue.
void * deque_pop_back (deque_t *d)
 Pop a value from the back of the queue, removing it from the queue.
void * deque_pop_front (deque_t *d)
 Pop a value from the front of the queue, removing it from the queue.
void deque_push_back (deque_t *d, void *value)
 Push a value to the back of the queue.
void deque_push_front (deque_t *d, void *value)
 Push a value to the front of the queue.
size_t deque_size (deque_t *d)
 Return the size of the queue.
void end_sensor_simulator ()
 End ncurses control of the terminal.
void hashmap_free (hashmap_t *hashmap)
 Free all memory used by the given hashmap.
void * hashmap_get (hashmap_t *hashmap, void *key)
 Get the value associated with the given key.
static hashmap_entry_thashmap_get_actual_address (hashmap_t *hashmap, void *key)
 Return the actual address of the hashmap entry corresponding to key, or the address of the closest empty entry if no such entry exists.
hashmap_thashmap_new (size_t capacity, void *nothing)
 Construct a new hashmap object.
void hashmap_put (hashmap_t *hashmap, void *key, void *value)
 Associate a value with the given key.
int hashset_add (hashset_t set, void *item)
 Add a pointer to the hashset.
hashset_t hashset_create (unsigned short nbits)
 Create a hashset instance.
void hashset_destroy (hashset_t set)
 Destroy the hashset instance, freeing allocated memory.
int hashset_is_member (hashset_t set, void *item)
 Returns non-zero if the item is in the hashset and zero otherwise.
hashset_itr_t hashset_iterator (hashset_t set)
 Create a hashset iterator.
int hashset_iterator_has_next (hashset_itr_t itr)
 Return 1 if there is a next value in the hashset and 0 otherwise.
int hashset_iterator_next (hashset_itr_t itr)
 Advance to the next value in the hashset.
void * hashset_iterator_value (hashset_itr_t itr)
 Return the value at the current index.
size_t hashset_num_items (hashset_t set)
 Return the number of items in the hashset.
int hashset_remove (hashset_t set, void *item)
 Remove an item from the hashset.
int lf_play_audio_waveform (lf_waveform_t *waveform, float emphasis, instant_t start_time)
 Play the specified waveform with the specified emphasis at the specified time.
void lf_start_audio_loop (instant_t start_time)
 Start an audio loop thread that becomes ready to receive audio amplitude samples via add_to_sound().
void lf_stop_audio_loop ()
 Stop the audio loop thread.
lf_waveform_tread_wave_file (const char *path)
 Open a wave file, check that the format is supported, allocate memory for the sample data, and fill the memory with the sample data.
int register_sensor_key (char key, void *action)
 Register a keyboard key to trigger the specified action.
void show_tick (const char *character)
 Place a tick (usually a single character) in the tick window.
int start_sensor_simulator (const char *message_lines[], int number_of_lines, int tick_window_width, char *log_file, int log_level)
 Start the sensor simulator if it has not been already started.
void ** vector_at (vector_t *v, size_t idx)
 Return a pointer to where the vector element at 'idx' is stored.
void vector_free (vector_t *v)
 Free the memory held by the given vector, invalidating it.
vector_t vector_new (size_t initial_capacity)
 Allocate and initialize a new vector.
void * vector_pop (vector_t *v)
 Remove and return some pointer that is contained in the given vector, or return NULL if the given vector is empty.
void vector_push (vector_t *v, void *element)
 Add the given element to the vector.
void vector_pushall (vector_t *v, void **array, size_t size)
 Add all elements of the given array to the vector.
size_t vector_size (vector_t *v)
 Return the size of the vector.
void vector_vote (vector_t *v)
 Vote on whether this vector should be given less memory.

Detailed Description

Useful functions for application developers.

This collection of functions provides commonly used functionality that is not part of the core API.

Macro Definition Documentation

◆ AUDIO_BUFFER_SIZE

#define AUDIO_BUFFER_SIZE   4410

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Size of the audio buffer.

◆ BUFFER_DURATION_NS

#define BUFFER_DURATION_NS   100000000LL

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Duration of the audio buffer.

◆ DO_CONVERT

#define DO_CONVERT ( fromType,
toType,
value )

#include </Users/runner/work/reactor-c/reactor-c/util/type_converter.h>

Value:
RESOLVE(fromType, toType, value)
#define RESOLVE(i, o, in)
Definition type_converter.h:20

Convert the specified value from one type to another.

This macro enables user to provide their own converter libraries as long as they follow the convention for naming their conversion functions.

Note
Converter library functions must follow this convention: toType convert__fromType_to__toType(fromType x).
Parameters
fromTypeTypename of value field
toTypeTypename of desired type
valueActual value of type fromType

◆ lf_decay

#define lf_decay ( p)

#include </Users/runner/work/reactor-c/reactor-c/util/generics.h>

Value:
(&*__builtin_choose_expr(lf_is_pointer_or_array(p), p, NULL))
#define lf_is_pointer_or_array(p)
Check whether the passed variable p is an array or a pointer.
Definition generics.h:57

Decay the specified pointer.

Parameters
pThe pointer to decay.
Returns
The decayed pointer.

◆ lf_get_pointer

#define lf_get_pointer ( p)

#include </Users/runner/work/reactor-c/reactor-c/util/generics.h>

Value:
__builtin_choose_expr(lf_is_pointer(p), p, &p)
#define lf_is_pointer(p)
Check whether the passed variable p is a pointer.
Definition generics.h:75

Return the pointer for specified p.

Parameters
pThe variable to get the pointer for.
Returns
The pointer for the specified variable.

◆ lf_is_pointer

#define lf_is_pointer ( p)

#include </Users/runner/work/reactor-c/reactor-c/util/generics.h>

Value:
#define lf_is_same_type(a, b)
Check whether the types of both a and b are same.
Definition generics.h:28
#define lf_decay(p)
Decay the specified pointer.
Definition generics.h:66

Check whether the passed variable p is a pointer.

Parameters
pThe variable to check.
Returns
True if the variable is a pointer, false otherwise.

◆ lf_is_pointer_or_array

#define lf_is_pointer_or_array ( p)

#include </Users/runner/work/reactor-c/reactor-c/util/generics.h>

Value:
(__builtin_classify_type(p) == 5)

Check whether the passed variable p is an array or a pointer.

Parameters
pThe variable to check.
Returns
True if the variable is an array or a pointer, false otherwise.

◆ lf_is_same

#define lf_is_same ( typename,
b )

#include </Users/runner/work/reactor-c/reactor-c/util/generics.h>

Value:
__builtin_types_compatible_p(typename, __typeof__(b))

Check whether the type of b is same as the specified typename.

Parameters
typenameThe type to compare against.
bThe value to compare.
Returns
True if the types are the same, false otherwise.

◆ lf_is_same_type

#define lf_is_same_type ( a,
b )

#include </Users/runner/work/reactor-c/reactor-c/util/generics.h>

Value:
__builtin_types_compatible_p(__typeof__(a), __typeof__(b))

Check whether the types of both a and b are same.

Parameters
aThe first value to compare.
bThe second value to compare.
Returns
True if the types are the same, false otherwise.

◆ lf_is_type_equal

#define lf_is_type_equal ( typename_a,
typename_b )

#include </Users/runner/work/reactor-c/reactor-c/util/generics.h>

Value:
__builtin_types_compatible_p(typename_a, typename_b)

Check whether the type of typename_a is same as the type of typename_b.

Parameters
typename_aThe first type to compare against.
typename_bThe second type to compare against.
Returns
True if the types are the same, false otherwise.

◆ lf_to_left_type

#define lf_to_left_type ( left,
right )

#include </Users/runner/work/reactor-c/reactor-c/util/generics.h>

Value:
__builtin_choose_expr(lf_is_pointer_or_array(left), \
__builtin_choose_expr(lf_is_pointer_or_array(right), (right), &(right)), \
__builtin_choose_expr(lf_is_pointer_or_array(right), *(right), (right)))

Check types for both left and right and return appropriate value based on left type.

Parameters
leftThe left value to check.
rightThe right value to check.
Returns
The appropriate value based on left type.

◆ MAX_AMPLITUDE

#define MAX_AMPLITUDE   32765

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Maximum amplitude for audio playback.

◆ NUM_CHANNELS

#define NUM_CHANNELS   1

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Number of channels for audio playback.

◆ NUM_NOTES

#define NUM_NOTES   8

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Maximum number of notes that can play simultaneously.

◆ SAMPLE_RATE

#define SAMPLE_RATE   44100

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Sample rate for audio playback.

Typedef Documentation

◆ deque_t

typedef struct deque_t deque_t

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

A double-ended queue data structure.

◆ hashmap_entry_t

typedef struct hashmap_entry_t hashmap_entry_t

◆ hashmap_t

typedef struct hashmap_t hashmap_t

◆ lf_waveform_t

typedef struct lf_waveform_t lf_waveform_t

#include </Users/runner/work/reactor-c/reactor-c/util/wave_file_reader.h>

Waveform in 16-bit linear-PCM format.

The waveform element is an array containing audio samples. If there are two channels, then they are interleaved left and right channel. The length is the total number of samples, a multiple of the number of channels.

◆ vector_t

typedef struct vector_t vector_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

A vector (resizing array) data type.

This struct implements a dynamic array that can grow as needed. It is designed to be a simple way of storing a collection of pointers that is frequently filled and then completely emptied.

Function Documentation

◆ add_to_sound()

void add_to_sound ( int index_offset,
double value )

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Add the given value to the current write buffer at the specified index.

If the resulting value is larger than what can be represented in the 16-bit short, truncate it.

Parameters
index_offsetWhere in the buffer to add the amplitude.
valueThe amplitude to add to whatever amplitude is already there.

◆ deque_initialize()

void deque_initialize ( deque_t * d)

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Initialize the specified deque to an empty deque.

Parameters
dThe deque.

◆ deque_is_empty()

bool deque_is_empty ( deque_t * d)

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Return true if the queue is empty.

Parameters
dThe deque.

◆ deque_peek_back()

void * deque_peek_back ( deque_t * d)

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Peek at the value on the front of the queue, leaving it on the queue.

Parameters
dThe queue.
Returns
The value on the front of the queue or NULL if the queue is empty.

◆ deque_peek_front()

void * deque_peek_front ( deque_t * d)

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Peek at the value on the back of the queue, leaving it on the queue.

Parameters
dThe queue.
Returns
The value on the back of the queue or NULL if the queue is empty.

◆ deque_pop_back()

void * deque_pop_back ( deque_t * d)

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Pop a value from the back of the queue, removing it from the queue.

Parameters
dThe queue.
Returns
The value on the back of the queue or NULL if the queue is empty.

◆ deque_pop_front()

void * deque_pop_front ( deque_t * d)

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Pop a value from the front of the queue, removing it from the queue.

Parameters
dThe queue.
Returns
The value on the front of the queue or NULL if the queue is empty.

◆ deque_push_back()

void deque_push_back ( deque_t * d,
void * value )

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Push a value to the back of the queue.

Parameters
dThe queue.
valueThe value to push.

◆ deque_push_front()

void deque_push_front ( deque_t * d,
void * value )

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Push a value to the front of the queue.

Parameters
dThe queue.
valueThe value to push.

◆ deque_size()

size_t deque_size ( deque_t * d)

#include </Users/runner/work/reactor-c/reactor-c/util/deque.h>

Return the size of the queue.

Parameters
dThe deque.
Returns
The size of the queue.

◆ end_sensor_simulator()

void end_sensor_simulator ( )

#include </Users/runner/work/reactor-c/reactor-c/util/sensor_simulator.h>

End ncurses control of the terminal.

◆ hashmap_free()

void hashmap_free ( hashmap_t * hashmap)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/impl/hashmap.h>

Free all memory used by the given hashmap.

◆ hashmap_get()

void * hashmap_get ( hashmap_t * hashmap,
void * key )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/impl/hashmap.h>

Get the value associated with the given key.

Precondition: The key must be present in the map.

◆ hashmap_get_actual_address()

hashmap_entry_t * hashmap_get_actual_address ( hashmap_t * hashmap,
void * key )
static

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/impl/hashmap.h>

Return the actual address of the hashmap entry corresponding to key, or the address of the closest empty entry if no such entry exists.

Parameters
hashmapThe hashmap to search.
keyThe key from which to begin a search.

◆ hashmap_new()

hashmap_t * hashmap_new ( size_t capacity,
void * nothing )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/impl/hashmap.h>

Construct a new hashmap object.

Parameters
capacityA number that is much larger than the maximum number of items that this hashmap will contain. Insufficient surplus capacity will cause poor performance.
nothingA key that is guaranteed never to be used.

◆ hashmap_put()

void hashmap_put ( hashmap_t * hashmap,
void * key,
void * value )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/impl/hashmap.h>

Associate a value with the given key.

◆ hashset_add()

int hashset_add ( hashset_t set,
void * item )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset.h>

Add a pointer to the hashset.

Note that 0 and 1 are special values, meaning nil and deleted items. This function will return -1 indicating error if you try to add 0 or 1. This function may resize the hashset if it is approaching capacity. Returns zero if the item is already in the set and non-zero otherwise.

Parameters
setThe hashset.
itemThe item to add.
Returns
0 if the item is already in the set and non-zero otherwise.

◆ hashset_create()

hashset_t hashset_create ( unsigned short nbits)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset.h>

Create a hashset instance.

The returned value is a pointer. The caller must call hashset_destroy() to free allocated memory.

Parameters
nbitsThe log base 2 of the initial capacity of the hashset.
Returns
A pointer to the hashset.

◆ hashset_destroy()

void hashset_destroy ( hashset_t set)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset.h>

Destroy the hashset instance, freeing allocated memory.

Parameters
setThe hashset to destroy.

◆ hashset_is_member()

int hashset_is_member ( hashset_t set,
void * item )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset.h>

Returns non-zero if the item is in the hashset and zero otherwise.

Parameters
setThe hashset.
itemThe item to check.
Returns
Non-zero if the item is in the hashset and zero otherwise.

◆ hashset_iterator()

hashset_itr_t hashset_iterator ( hashset_t set)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset_itr.h>

Create a hashset iterator.

The caller should then iterate over the hashset as follows:

hashset_itr_t iterator = hashset_iterator(my_hashset);
while (hashset_iterator_next(iterator) >= 0) {
void* my_value = hashset_iterator_value(iterator);
...
}
free(iterator);
void * hashset_iterator_value(hashset_itr_t itr)
Return the value at the current index.
int hashset_iterator_next(hashset_itr_t itr)
Advance to the next value in the hashset.
hashset_itr_t hashset_iterator(hashset_t set)
Create a hashset iterator.
struct hashset_itr_st * hashset_itr_t
Definition hashset_itr.h:46

The caller must call free() on this iterator after using it.

Parameters
setThe hashset to iterate over.
Returns
A hashset iterator.

◆ hashset_iterator_has_next()

int hashset_iterator_has_next ( hashset_itr_t itr)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset_itr.h>

Return 1 if there is a next value in the hashset and 0 otherwise.

Parameters
itrThe hashset iterator.
Returns
1 if there is a next value in the hashset and 0 otherwise.

◆ hashset_iterator_next()

int hashset_iterator_next ( hashset_itr_t itr)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset_itr.h>

Advance to the next value in the hashset.

This returns a non-negative number (the current index) if there is a next item and -1 otherwise.

Parameters
itrThe hashset iterator.
Returns
The current index.

◆ hashset_iterator_value()

void * hashset_iterator_value ( hashset_itr_t itr)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset_itr.h>

Return the value at the current index.

The called should check hashset_iterator_has_next before calling this.

Parameters
itrThe hashset iterator.
Returns
The value at the current index.

◆ hashset_num_items()

size_t hashset_num_items ( hashset_t set)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset.h>

Return the number of items in the hashset.

Parameters
setThe hashset.
Returns
The number of items in the hashset.

◆ hashset_remove()

int hashset_remove ( hashset_t set,
void * item )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/hashset/hashset.h>

Remove an item from the hashset.

Parameters
setThe hashset.
itemThe item to remove.
Returns
Non-zero if the item was removed and zero if the item is not on the hashset.

◆ lf_play_audio_waveform()

int lf_play_audio_waveform ( lf_waveform_t * waveform,
float emphasis,
instant_t start_time )

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Play the specified waveform with the specified emphasis at the specified time.

If the waveform is null, play a simple tick (an impulse). If the waveform has length zero or volume 0, play nothing.

If the time is too far in the future (beyond the window of the current audio write buffer), then block until the audio output catches up. If the audio playback has already passed the specified point, then play the waveform as soon as possible and return 1. Otherwise, return 0.

Parameters
waveformThe waveform to play or NULL to just play a tick.
emphasisThe emphasis (0.0 for silence, 1.0 for waveform volume).
start_timeThe time to start playing the waveform.

◆ lf_start_audio_loop()

void lf_start_audio_loop ( instant_t start_time)

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Start an audio loop thread that becomes ready to receive audio amplitude samples via add_to_sound().

If there is already an audio loop running, then do nothing.

Parameters
start_timeThe logical time that aligns with the first audio buffer.

◆ lf_stop_audio_loop()

void lf_stop_audio_loop ( )

#include </Users/runner/work/reactor-c/reactor-c/util/audio_loop.h>

Stop the audio loop thread.

◆ read_wave_file()

lf_waveform_t * read_wave_file ( const char * path)

#include </Users/runner/work/reactor-c/reactor-c/util/wave_file_reader.h>

Open a wave file, check that the format is supported, allocate memory for the sample data, and fill the memory with the sample data.

It is up to the caller to free the memory when done with it. That code should first free the waveform element of the returned struct, then the struct itself. This implementation supports only 16-bit linear PCM files. On a Mac, you can convert audio files into this format using the afconvert utility.

Parameters
pathThe path to the file.
Returns
An array of sample data or NULL if the file can't be opened or has an usupported format.

◆ register_sensor_key()

int register_sensor_key ( char key,
void * action )

#include </Users/runner/work/reactor-c/reactor-c/util/sensor_simulator.h>

Register a keyboard key to trigger the specified action.

Printable ASCII characters (codes 32 to 127) are supported plus '
' and '\0', where the latter registers a trigger to invoked when any key is pressed. If a specific key is registered and any key ('\0') is also registered, the registered and any key ('\0') is also registered, the any key trigger will be scheduled after the specific key is scheduled. If these triggers belong to different reactors, they could be invoked in parallel. This will fail if the specified key has already been registered (error code 1), or the key is not a supported key or a newline ‘
’ or any key '\0' (error code 2) or if the trigger is NULL (error code 3).

Parameters
keyThe key to register.
actionThe action to trigger when the key is pressed (a pointer to an lf_action_based_t struct).
Returns
0 for success, error code for failure.

◆ show_tick()

void show_tick ( const char * character)

#include </Users/runner/work/reactor-c/reactor-c/util/sensor_simulator.h>

Place a tick (usually a single character) in the tick window.

Parameters
characterThe tick character.

◆ start_sensor_simulator()

int start_sensor_simulator ( const char * message_lines[],
int number_of_lines,
int tick_window_width,
char * log_file,
int log_level )

#include </Users/runner/work/reactor-c/reactor-c/util/sensor_simulator.h>

Start the sensor simulator if it has not been already started.

This must be called at least once before any call to register_sensor_key. The specified message is an initial message to display at the upper left, typically a set of instructions, that remains displayed throughout the lifetime of the window. Please ensure that the message_lines array and its contained strings are not on the stack because they will be used later in a separate thread.

Parameters
message_linesThe message lines.
number_of_linesThe number of lines.
tick_window_widthThe width of the tick window or 0 for none.
log_fileIf non-NULL, the name of a file to which to write logging messages.
log_levelThe level of log messages to redirect to the file. The level should be one of LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO, LOG_LEVEL_LOG, LOG_LEVEL_DEBUG, or LOG_LEVEL_ALL.
Returns
0 for success, error code for failure.

◆ vector_at()

void ** vector_at ( vector_t * v,
size_t idx )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

Return a pointer to where the vector element at 'idx' is stored.

This can be used to set the value of the element or to read it. If the index is past the end of the vector, then the vector is automatically expanded and filled with NULL pointers as needed. If no element at idx has been previously set, then the value pointed to by the returned pointer will be NULL.

Parameters
vThe vector.
idxThe index into the vector.
Returns
A pointer to the element at 'idx', which is itself a pointer.

◆ vector_free()

void vector_free ( vector_t * v)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

Free the memory held by the given vector, invalidating it.

Parameters
vAny vector.

◆ vector_new()

vector_t vector_new ( size_t initial_capacity)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

Allocate and initialize a new vector.

Parameters
initial_capacityThe desired initial capacity to allocate. Must be more than 0.
Returns
A new vector with the given initial capacity.

◆ vector_pop()

void * vector_pop ( vector_t * v)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

Remove and return some pointer that is contained in the given vector, or return NULL if the given vector is empty.

Parameters
vAny vector.

◆ vector_push()

void vector_push ( vector_t * v,
void * element )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

Add the given element to the vector.

The given element should be non-null.

Parameters
vA vector that is to grow.
elementAn element that the vector should contain.

◆ vector_pushall()

void vector_pushall ( vector_t * v,
void ** array,
size_t size )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

Add all elements of the given array to the vector.

Elements should be non-null.

Parameters
vA vector that is to grow.
arrayAn array of items to be added to the vector.
sizeThe size of the given array.

◆ vector_size()

size_t vector_size ( vector_t * v)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

Return the size of the vector.

Parameters
vAny vector
Returns
size_t The size of the vector.

◆ vector_vote()

void vector_vote ( vector_t * v)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/vector.h>

Vote on whether this vector should be given less memory.

If v contains few elements, it becomes more likely to shrink. It is suggested that this function be called when the number of elements in v reaches a local maximum.

Parameters
vAny vector.