Skip to content

Commit

Permalink
Rename InputPort -> Input
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj committed Oct 1, 2024
1 parent f193528 commit fe5868d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
5 changes: 3 additions & 2 deletions include/reactor-uc/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include "reactor-uc/reaction.h"
#include "reactor-uc/reactor.h"
#include "reactor-uc/trigger.h"
#include "reactor-uc/action.h"

typedef struct Connection Connection;
typedef struct PhysicalConnection PhysicalConnection;
typedef struct DelayedConnection DelayedConnection;
typedef struct Port Port;
typedef struct OutputPort OutputPort;
typedef struct Output Output;

typedef enum { CONN_LOGICAL, CONN_PHYSICAL, CONN_DELAYED } ConnectionType;

Expand All @@ -22,7 +23,7 @@ struct Connection {
size_t downstreams_size;
size_t downstreams_registered;
void (*register_downstream)(Connection *, Port *);
OutputPort *(*get_final_upstream)(Connection *);
Output *(*get_final_upstream)(Connection *);
};

void Connection_ctor(Connection *self, ConnectionType type, Reactor *parent, Port *upstream, Port **downstreams,
Expand Down
16 changes: 8 additions & 8 deletions include/reactor-uc/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "reactor-uc/reactor.h"
#include "reactor-uc/trigger.h"

typedef struct InputPort InputPort;
typedef struct OutputPort OutputPort;
typedef struct Input Input;
typedef struct Output Output;
typedef struct Connection Connection;
typedef struct Port Port;

Expand All @@ -19,19 +19,19 @@ struct Port {
void (*copy_value_and_trigger_downstreams)(Port *self, const void *value, size_t value_size);
};

struct InputPort {
struct Input {
Port super;
void (*trigger_effects)(InputPort *);
void (*trigger_effects)(Input *);
};

struct OutputPort {
struct Output {
Port super;
};

void InputPort_ctor(InputPort *self, Reactor *parent, Reaction **effects, size_t effects_size, size_t value_size,
void *value_buf, size_t value_capacity);
void Input_ctor(Input *self, Reactor *parent, Reaction **effects, size_t effects_size, size_t value_size,
void *value_buf, size_t value_capacity);

void OutputPort_ctor(OutputPort *self, Reactor *parent, Reaction **sources, size_t sources_size);
void Output_ctor(Output *self, Reactor *parent, Reaction **sources, size_t sources_size);
void Port_ctor(Port *self, TriggerType type, Reactor *parent, Reaction **effects, size_t effects_size,
Reaction **sources, size_t sources_size, size_t value_size, void *value_buf, size_t value_capacity);

Expand Down
4 changes: 2 additions & 2 deletions src/connection.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "reactor-uc/connection.h"
#include <assert.h>

OutputPort *Connection_get_final_upstream(Connection *self) {
Output *Connection_get_final_upstream(Connection *self) {
assert(self->upstream);

switch (self->upstream->super.type) {
case OUTPUT:
return (OutputPort *)self->upstream;
return (Output *)self->upstream;
case INPUT:
if (self->upstream->conn_in) {
return Connection_get_final_upstream(self->upstream->conn_in);
Expand Down
12 changes: 6 additions & 6 deletions src/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void copy_value_down_and_trigger(Port *port, const void *value_ptr, size_
if (down->super.type == INPUT) {
if (handle_now) {
down->super.schedule_now(&down->super, value_ptr);
((InputPort *)down)->trigger_effects((InputPort *)down);
((Input *)down)->trigger_effects((Input *)down);
} else {
instant_t schedule_time = NEVER;
if (is_physical) {
Expand All @@ -62,23 +62,23 @@ static void copy_value_down_and_trigger(Port *port, const void *value_ptr, size_
}
}

void InputPort_trigger_effects(InputPort *self) {
void Input_trigger_effects(Input *self) {
assert(self->super.super.type == INPUT);
Scheduler *sched = &self->super.super.parent->env->scheduler;
sched->trigger_reactions(sched, (Trigger *)self);
}

void InputPort_ctor(InputPort *self, Reactor *parent, Reaction **effects, size_t effects_size, size_t value_size,
void *value_buf, size_t value_capacity) {
void Input_ctor(Input *self, Reactor *parent, Reaction **effects, size_t effects_size, size_t value_size,
void *value_buf, size_t value_capacity) {
Port_ctor(&self->super, INPUT, parent, effects, effects_size, NULL, 0, value_size, value_buf, value_capacity);
self->trigger_effects = InputPort_trigger_effects;
self->trigger_effects = Input_trigger_effects;
}

void Port_copy_value_and_trigger_downstream(Port *self, const void *value, size_t value_size) {
copy_value_down_and_trigger(self, value, value_size, NEVER, false);
}

void OutputPort_ctor(OutputPort *self, Reactor *parent, Reaction **sources, size_t sources_size) {
void Output_ctor(Output *self, Reactor *parent, Reaction **sources, size_t sources_size) {
Port_ctor(&self->super, OUTPUT, parent, NULL, 0, sources, sources_size, 0, NULL, 0);
}

Expand Down
4 changes: 2 additions & 2 deletions src/reaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ size_t Reaction_calculate_level(Reaction *self) {
if (trigger->type == INPUT) {
for (size_t j = 0; j < trigger->effects_size; j++) {
if (trigger->effects[j] == self) {
InputPort *port = (InputPort *)trigger;
Input *port = (Input *)trigger;
if (port->super.conn_in) {
OutputPort *final_upstream_port = port->super.conn_in->get_final_upstream(port->super.conn_in);
Output *final_upstream_port = port->super.conn_in->get_final_upstream(port->super.conn_in);
for (size_t k = 0; k < final_upstream_port->super.super.sources_size; k++) {
Reaction *upstream = final_upstream_port->super.super.sources[k];
size_t upstream_level = upstream->get_level(upstream) + 1;
Expand Down
12 changes: 6 additions & 6 deletions test/delayed_conn_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef struct {
} Reaction1;

typedef struct {
OutputPort super;
Output super;
Reaction *sources[1];
interval_t value;
} Out;
Expand Down Expand Up @@ -41,7 +41,7 @@ void Reaction1_ctor(Reaction1 *self, Reactor *parent) {

void Out_ctor(Out *self, struct Sender *parent) {
self->sources[0] = &parent->reaction.super;
OutputPort_ctor(&self->super, &parent->super, self->sources, 1);
Output_ctor(&self->super, &parent->super, self->sources, 1);
}

void Sender_ctor(struct Sender *self, Reactor *parent, Environment *env) {
Expand All @@ -63,7 +63,7 @@ typedef struct {
} Reaction2;

typedef struct {
InputPort super;
Input super;
interval_t buffer[2];
Reaction *effects[1];
} In;
Expand All @@ -77,7 +77,7 @@ struct Receiver {
};

void In_ctor(In *self, struct Receiver *parent) {
InputPort_ctor(&self->super, &parent->super, self->effects, 1, sizeof(self->buffer[0]), self->buffer, 2);
Input_ctor(&self->super, &parent->super, self->effects, 1, sizeof(self->buffer[0]), self->buffer, 2);
}

void input_handler(Reaction *_self) {
Expand Down Expand Up @@ -106,10 +106,10 @@ void Receiver_ctor(struct Receiver *self, Reactor *parent, Environment *env) {

struct Conn1 {
DelayedConnection super;
InputPort *downstreams[1];
Input *downstreams[1];
};

void Conn1_ctor(struct Conn1 *self, Reactor *parent, OutputPort *upstream) {
void Conn1_ctor(struct Conn1 *self, Reactor *parent, Output *upstream) {
DelayedConnection_ctor(&self->super, parent, &upstream->super, (Port **)self->downstreams, 1, MSEC(150));
}

Expand Down
12 changes: 6 additions & 6 deletions test/port_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef struct {
} Reaction1;

typedef struct {
OutputPort super;
Output super;
Reaction *sources[1];
instant_t value;
} Out;
Expand Down Expand Up @@ -41,7 +41,7 @@ void Reaction1_ctor(Reaction1 *self, Reactor *parent) {

void Out_ctor(Out *self, struct Sender *parent) {
self->sources[0] = &parent->reaction.super;
OutputPort_ctor(&self->super, &parent->super, self->sources, 1);
Output_ctor(&self->super, &parent->super, self->sources, 1);
}

void Sender_ctor(struct Sender *self, Reactor *parent, Environment *env) {
Expand All @@ -63,7 +63,7 @@ typedef struct {
} Reaction2;

typedef struct {
InputPort super;
Input super;
instant_t buffer[1];
Reaction *effects[1];
} In;
Expand All @@ -77,7 +77,7 @@ struct Receiver {
};

void In_ctor(In *self, struct Receiver *parent) {
InputPort_ctor(&self->super, &parent->super, self->effects, 1, sizeof(self->buffer[0]), self->buffer, 1);
Input_ctor(&self->super, &parent->super, self->effects, 1, sizeof(self->buffer[0]), self->buffer, 1);
}

void input_handler(Reaction *_self) {
Expand Down Expand Up @@ -106,10 +106,10 @@ void Receiver_ctor(struct Receiver *self, Reactor *parent, Environment *env) {

struct Conn1 {
Connection super;
InputPort *downstreams[1];
Input *downstreams[1];
};

void Conn1_ctor(struct Conn1 *self, Reactor *parent, OutputPort *upstream) {
void Conn1_ctor(struct Conn1 *self, Reactor *parent, Output *upstream) {
Connection_ctor(&self->super, CONN_LOGICAL, parent, &upstream->super, (Port **)self->downstreams, 1);
}

Expand Down

0 comments on commit fe5868d

Please sign in to comment.