From c7b7f4d93142f547ef1e74f4e25ea40eefb02fda Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 8 Nov 2024 14:55:50 +0000 Subject: [PATCH] Add get_dest_channel_id getter to NetworkChannel and implement in TcpIpChannel --- include/reactor-uc/network_channel.h | 9 +++++---- src/platform/posix/tcp_ip_channel.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/reactor-uc/network_channel.h b/include/reactor-uc/network_channel.h index bcac2756..a8e754c6 100644 --- a/include/reactor-uc/network_channel.h +++ b/include/reactor-uc/network_channel.h @@ -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. diff --git a/src/platform/posix/tcp_ip_channel.c b/src/platform/posix/tcp_ip_channel.c index e1b3f48f..ef34b1d0 100644 --- a/src/platform/posix/tcp_ip_channel.c +++ b/src/platform/posix/tcp_ip_channel.c @@ -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; } @@ -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;