Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocating output connection list at common parent reactor #93

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/posix/testing_fed_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -147,6 +147,7 @@ typedef struct {
ConnSender conn;
FederatedConnectionBundle *_bundles[1];
Reactor *_children[1];
Connection *_conn_sender_out[1];
} MainSender;

typedef struct {
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions examples/zephyr/basic_federated/federated_sender/src/sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions include/reactor-uc/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
9 changes: 5 additions & 4 deletions test/unit/delayed_conn_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions test/unit/port_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
Loading