reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
modes.h
Go to the documentation of this file.
1
42#ifndef MODES_H
43#define MODES_H
44
45#ifdef MODAL_REACTORS
46
47#include <stddef.h>
48#include <stdbool.h>
49
50#include "lf_types.h"
51#include "tag.h"
52
53typedef struct event_t event_t;
54typedef struct reaction_t reaction_t;
55typedef struct trigger_t trigger_t;
56
59
69#define _LF_SET_MODE_WITH_TYPE(mode, change_type) \
70 do { \
71 ((self_base_t*)self)->_lf__mode_state.next_mode = mode; \
72 ((self_base_t*)self)->_lf__mode_state.mode_change = change_type; \
73 } while (0)
74
77
79typedef struct reactor_mode_t reactor_mode_t;
82typedef struct reactor_mode_state_t reactor_mode_state_t;
85typedef struct mode_state_variable_reset_data_t mode_state_variable_reset_data_t;
86
88typedef enum { no_transition, reset_transition, history_transition } lf_mode_change_type_t;
89
91struct reactor_mode_t {
92 reactor_mode_state_t* state; // Pointer to a struct with the reactor's mode state. INSTANCE.
93 char* name; // Name of this mode.
94 instant_t deactivation_time; // Time when the mode was left.
95 uint8_t flags; // Bit vector for several internal flags related to the mode.
96};
97
99struct reactor_mode_state_t {
100 reactor_mode_t* parent_mode; // Pointer to the next enclosing mode (if exists).
101 reactor_mode_t* initial_mode; // Pointer to the initial mode.
102 reactor_mode_t* current_mode; // Pointer to the currently active mode (only locally active).
103 reactor_mode_t* next_mode; // Pointer to the next mode to activate at the end of this step (if set).
104 lf_mode_change_type_t mode_change; // A mode change type flag.
105};
107struct mode_state_variable_reset_data_t {
108 reactor_mode_t* mode; // Pointer to the enclosing mode.
109 void* target; // Pointer to the target variable.
110 void* source; // Pointer to the data source.
111 size_t size; // The size of the variable.
112};
113
116typedef struct environment_t environment_t;
117
120void _lf_initialize_modes(environment_t* env);
121void _lf_handle_mode_changes(environment_t* env);
122void _lf_handle_mode_triggered_reactions(environment_t* env);
123bool _lf_mode_is_active(reactor_mode_t* mode);
124void _lf_initialize_mode_states(environment_t* env, reactor_mode_state_t* states[], int states_size);
125void _lf_process_mode_changes(environment_t* env, reactor_mode_state_t* states[], int states_size,
126 mode_state_variable_reset_data_t reset_data[], int reset_data_size,
128void _lf_add_suspended_event(event_t* event);
129void _lf_handle_mode_startup_reset_reactions(environment_t* env, reaction_t** startup_reactions,
131 int reset_reactions_size, reactor_mode_state_t* states[], int states_size);
132void _lf_handle_mode_shutdown_reactions(environment_t* env, reaction_t** shutdown_reactions,
134void _lf_terminate_modal_reactors(environment_t* env);
135
136#else /* IF NOT MODAL_REACTORS */
137/*
138 * Reactions and triggers must have a mode pointer to set up connection to enclosing modes,
139 * also when they are precompiled without modal reactors in order to later work in modal reactors.
140 * Hence define mode type as void in the absence of modes to treat mode pointer as void pointers for that time being.
141 */
142typedef void reactor_mode_t;
143#endif /* MODAL_REACTORS */
144#endif /* MODES_H */
Type definitions that are widely used across different parts of the runtime.
void reactor_mode_t
Definition modes.h:142
Execution environment. This struct contains information about the execution environment....
Definition environment.h:49
int timer_triggers_size
Definition environment.h:65
int reset_reactions_size
Definition environment.h:71
trigger_t ** timer_triggers
Definition environment.h:64
reaction_t ** startup_reactions
Definition environment.h:66
int startup_reactions_size
Definition environment.h:67
reaction_t ** reset_reactions
Definition environment.h:70
reaction_t ** shutdown_reactions
Definition environment.h:68
int shutdown_reactions_size
Definition environment.h:69
Definition lf_types.h:196
Definition lf_types.h:155
Definition lf_types.h:208
Time and tag definitions and functions for Lingua Franca.
int64_t instant_t
Definition tag.h:66