From 3ca9bfbf66bf0dc261811def350ce7a50f27844d Mon Sep 17 00:00:00 2001 From: Tassilo Tanneberger Date: Thu, 24 Oct 2024 06:50:41 +0200 Subject: [PATCH] Allocating output connection list at common parent reactor (#93) * moving connection to parent constructor * fix examples * Update zephyr federation also to use new output conn out --------- Co-authored-by: erlingrj --- examples/posix/testing_fed_conn.c | 9 +++++---- .../zephyr/basic_federated/federated_sender/src/sender.c | 9 +++++---- include/reactor-uc/macros.h | 6 +++--- test/unit/delayed_conn_test.c | 9 +++++---- test/unit/port_test.c | 9 +++++---- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/examples/posix/testing_fed_conn.c b/examples/posix/testing_fed_conn.c index 8bef6415..e92a5a9e 100644 --- a/examples/posix/testing_fed_conn.c +++ b/examples/posix/testing_fed_conn.c @@ -14,7 +14,7 @@ DEFINE_TIMER_STRUCT(Timer1, 1) DEFINE_TIMER_CTOR_FIXED(Timer1, 1, MSEC(0), SEC(1)) DEFINE_REACTION_STRUCT(Sender, 0, 1) DEFINE_OUTPUT_PORT_STRUCT(Out, 1, 1) -DEFINE_OUTPUT_PORT_CTOR(Out, 1, 1) +DEFINE_OUTPUT_PORT_CTOR(Out, 1) typedef struct { Reactor super; @@ -37,13 +37,13 @@ DEFINE_REACTION_BODY(Sender, 0) { } DEFINE_REACTION_CTOR(Sender, 0) -void Sender_ctor(Sender *self, Reactor *parent, Environment *env) { +void Sender_ctor(Sender *self, Reactor *parent, Environment *env, Connection** conn_out, size_t conn_out_num) { self->_reactions[0] = (Reaction *)&self->reaction; self->_triggers[0] = (Trigger *)&self->timer; Reactor_ctor(&self->super, "Sender", env, parent, NULL, 0, self->_reactions, 1, self->_triggers, 1); Sender_Reaction0_ctor(&self->reaction, &self->super); Timer_ctor(&self->timer.super, &self->super, 0, MSEC(100), self->timer.effects, 1); - Out_ctor(&self->out, &self->super); + Out_ctor(&self->out, &self->super, conn_out, conn_out_num); TIMER_REGISTER_EFFECT(self->timer, self->reaction); // Register reaction as a source for out @@ -147,6 +147,7 @@ typedef struct { ConnSender conn; FederatedConnectionBundle *_bundles[1]; Reactor *_children[1]; + Connection *_conn_sender_out[1]; } MainSender; typedef struct { @@ -160,7 +161,7 @@ typedef struct { void MainSender_ctor(MainSender *self, Environment *env) { self->_children[0] = &self->sender.super; - Sender_ctor(&self->sender, &self->super, env); + Sender_ctor(&self->sender, &self->super, env, self->_conn_sender_out, 1); SenderRecvConn_ctor(&self->bundle, &self->sender); self->_bundles[0] = &self->bundle.super; diff --git a/examples/zephyr/basic_federated/federated_sender/src/sender.c b/examples/zephyr/basic_federated/federated_sender/src/sender.c index 7f012517..3be64e9b 100644 --- a/examples/zephyr/basic_federated/federated_sender/src/sender.c +++ b/examples/zephyr/basic_federated/federated_sender/src/sender.c @@ -20,7 +20,7 @@ DEFINE_ACTION_STRUCT(Action1, PHYSICAL_ACTION, 1, 0, bool, 2) DEFINE_ACTION_CTOR_FIXED(Action1, PHYSICAL_ACTION, 1, 0, bool, 2, MSEC(0)) DEFINE_REACTION_STRUCT(Sender, 0, 1) DEFINE_OUTPUT_PORT_STRUCT(Out, 1, 2) -DEFINE_OUTPUT_PORT_CTOR(Out, 1, 2) +DEFINE_OUTPUT_PORT_CTOR(Out, 1) Action1 *action_ptr = NULL; void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { @@ -84,13 +84,13 @@ DEFINE_REACTION_BODY(Sender, 0) { } DEFINE_REACTION_CTOR(Sender, 0); -void Sender_ctor(Sender *self, Reactor *parent, Environment *env) { +void Sender_ctor(Sender *self, Reactor *parent, Environment *env, Connection **conn_out, size_t conn_out_num) { self->_reactions[0] = (Reaction *)&self->reaction; self->_triggers[0] = (Trigger *)&self->action; Reactor_ctor(&self->super, "Sender", env, parent, NULL, 0, self->_reactions, 1, self->_triggers, 1); Sender_Reaction0_ctor(&self->reaction, &self->super); Action1_ctor(&self->action, &self->super); - Out_ctor(&self->out, &self->super); + Out_ctor(&self->out, &self->super, conn_out, conn_out_num); ACTION_REGISTER_EFFECT(self->action, self->reaction); // Register reaction as a source for out @@ -159,11 +159,12 @@ typedef struct { SenderRecv2Bundle bundle2; FederatedConnectionBundle *_bundles[2]; Reactor *_children[1]; + Connection *_sender_conn[2]; } MainSender; void MainSender_ctor(MainSender *self, Environment *env) { self->_children[0] = &self->sender.super; - Sender_ctor(&self->sender, &self->super, env); + Sender_ctor(&self->sender, &self->super, env, self->_sender_conn, 2); Reactor_ctor(&self->super, "MainSender", env, NULL, self->_children, 1, NULL, 0, NULL, 0); SenderRecv1Bundle_ctor(&self->bundle1, &self->super); SenderRecv2Bundle_ctor(&self->bundle2, &self->super); diff --git a/include/reactor-uc/macros.h b/include/reactor-uc/macros.h index c7ea3648..623d4a5b 100644 --- a/include/reactor-uc/macros.h +++ b/include/reactor-uc/macros.h @@ -104,9 +104,9 @@ Connection *conns_out[NumConnsOut]; \ } PortName; -#define DEFINE_OUTPUT_PORT_CTOR(PortName, SourceSize, NumConnsOut) \ - void PortName##_ctor(PortName *self, Reactor *parent) { \ - Output_ctor(&self->super, parent, self->sources, SourceSize, (Connection **)&self->conns_out, NumConnsOut); \ +#define DEFINE_OUTPUT_PORT_CTOR(PortName, SourceSize) \ + void PortName##_ctor(PortName *self, Reactor *parent, Connection **conn_out, size_t conn_num) { \ + Output_ctor(&self->super, parent, self->sources, SourceSize, conn_out, conn_num); \ } #define DEFINE_INPUT_PORT_STRUCT(PortName, EffectSize, BufferType, NumConnsOut) \ diff --git a/test/unit/delayed_conn_test.c b/test/unit/delayed_conn_test.c index d66b7d92..7e47f3db 100644 --- a/test/unit/delayed_conn_test.c +++ b/test/unit/delayed_conn_test.c @@ -6,7 +6,7 @@ DEFINE_TIMER_STRUCT(Timer1, 1) DEFINE_TIMER_CTOR_FIXED(Timer1, 1, 0, MSEC(10)) DEFINE_REACTION_STRUCT(Sender, 0, 0); DEFINE_OUTPUT_PORT_STRUCT(Out, 1, 1) -DEFINE_OUTPUT_PORT_CTOR(Out, 1, 1) +DEFINE_OUTPUT_PORT_CTOR(Out, 1) typedef struct { Reactor super; @@ -27,13 +27,13 @@ DEFINE_REACTION_BODY(Sender, 0) { } DEFINE_REACTION_CTOR(Sender, 0); -void Sender_ctor(Sender *self, Reactor *parent, Environment *env) { +void Sender_ctor(Sender *self, Reactor *parent, Environment *env, Connection** conn_out, size_t conn_out_num) { self->_reactions[0] = (Reaction *)&self->reaction; self->_triggers[0] = (Trigger *)&self->timer; Reactor_ctor(&self->super, "Sender", env, parent, NULL, 0, self->_reactions, 1, self->_triggers, 1); Sender_Reaction0_ctor(&self->reaction, &self->super); Timer1_ctor(&self->timer, &self->super); - Out_ctor(&self->out, &self->super); + Out_ctor(&self->out, &self->super, conn_out, conn_out_num); TIMER_REGISTER_EFFECT(self->timer, self->reaction); @@ -87,11 +87,12 @@ typedef struct { Conn1 conn; Reactor *_children[2]; + Connection *_conn_sender_out[1]; } Main; void Main_ctor(Main *self, Environment *env) { self->_children[0] = &self->sender.super; - Sender_ctor(&self->sender, &self->super, env); + Sender_ctor(&self->sender, &self->super, env, self->_conn_sender_out, 1); self->_children[1] = &self->receiver.super; Receiver_ctor(&self->receiver, &self->super, env); diff --git a/test/unit/port_test.c b/test/unit/port_test.c index 979be3a4..5c41702d 100644 --- a/test/unit/port_test.c +++ b/test/unit/port_test.c @@ -6,7 +6,7 @@ DEFINE_TIMER_STRUCT(Timer1, 1) DEFINE_TIMER_CTOR_FIXED(Timer1, 1, 0, SEC(1)) DEFINE_REACTION_STRUCT(Sender, 0, 0) DEFINE_OUTPUT_PORT_STRUCT(Out, 1, 1) -DEFINE_OUTPUT_PORT_CTOR(Out, 1, 1) +DEFINE_OUTPUT_PORT_CTOR(Out, 1) typedef struct { Reactor super; @@ -27,13 +27,13 @@ DEFINE_REACTION_BODY(Sender, 0) { } DEFINE_REACTION_CTOR(Sender, 0) -void Sender_ctor(Sender *self, Reactor *parent, Environment *env) { +void Sender_ctor(Sender *self, Reactor *parent, Environment *env, Connection** conn_out, size_t conn_num) { self->_reactions[0] = (Reaction *)&self->reaction; self->_triggers[0] = (Trigger *)&self->timer; Reactor_ctor(&self->super, "Sender", env, parent, NULL, 0, self->_reactions, 1, self->_triggers, 1); Sender_Reaction0_ctor(&self->reaction, &self->super); Timer1_ctor(&self->timer, &self->super); - Out_ctor(&self->out, &self->super); + Out_ctor(&self->out, &self->super, conn_out, conn_num); TIMER_REGISTER_EFFECT(self->timer, self->reaction); OUTPUT_REGISTER_SOURCE(self->out, self->reaction); } @@ -85,11 +85,12 @@ typedef struct { Conn1 conn; Reactor *_children[2]; + Connection *_conn_sender_out[1]; } Main; void Main_ctor(Main *self, Environment *env) { self->_children[0] = &self->sender.super; - Sender_ctor(&self->sender, &self->super, env); + Sender_ctor(&self->sender, &self->super, env, self->_conn_sender_out, 1); self->_children[1] = &self->receiver.super; Receiver_ctor(&self->receiver, &self->super, env);