Skip to content

Commit

Permalink
Add get_dest_channel_id getter to NetworkChannel and implement in Tcp…
Browse files Browse the repository at this point in the history
…IpChannel
  • Loading branch information
LasseRosenow committed Nov 11, 2024
1 parent 8624aab commit a6b6d80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 5 additions & 4 deletions include/reactor-uc/network_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ typedef struct NetworkChannel NetworkChannel;

struct NetworkChannel {
/**
* @brief Used to identify this NetworkChannel among other NetworkChannels at the other federate.
* @brief Expected time until a connection is established after calling @p try_connect.
*/
size_t dest_channel_id;
interval_t expected_try_connect_duration;

/**
* @brief Expected time until a connection is established after calling @p try_connect.
* @brief Get the other federates channel id.
* Used to identify this NetworkChannel among other NetworkChannels at incoming messages from the other federate.
*/
interval_t expected_try_connect_duration;
uint32_t (*get_dest_channel_id)(NetworkChannel *self);

/**
* @brief Get the current state of the connection.
Expand Down
14 changes: 13 additions & 1 deletion src/platform/posix/tcp_ip_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,17 @@ static void TcpIpChannel_free(NetworkChannel *untyped_self) {
self->super.close_connection((NetworkChannel *)self);
}

NetworkChannelState TcpIpChannel_get_state(NetworkChannel *untyped_self) {
static uint32_t TcpIpChannel_get_dest_channel_id(NetworkChannel *untyped_self) {
TcpIpChannel *self = (TcpIpChannel *)untyped_self;

if (self->server) {
return self->client;
} else {
return self->fd;
}
}

static NetworkChannelState TcpIpChannel_get_connection_state(NetworkChannel *untyped_self) {
TcpIpChannel *self = (TcpIpChannel *)untyped_self;
return self->state;
}
Expand All @@ -486,6 +496,8 @@ void TcpIpChannel_ctor(TcpIpChannel *self, const char *host, unsigned short port
self->fd = 0;
self->state = NETWORK_CHANNEL_STATE_UNINITIALIZED;

self->super.get_dest_channel_id = TcpIpChannel_get_dest_channel_id;
self->super.get_connection_state = TcpIpChannel_get_connection_state;
self->super.open_connection = TcpIpChannel_open_connection;
self->super.try_connect = TcpIpChannel_try_connect;
self->super.close_connection = TcpIpChannel_close_connection;
Expand Down

0 comments on commit a6b6d80

Please sign in to comment.