From 9b8b7d6e5963beab5c527a9d2bb083c348ec7761 Mon Sep 17 00:00:00 2001 From: Dongha Kim <74869052+Jakio815@users.noreply.github.com> Date: Tue, 24 Dec 2024 06:11:04 +0900 Subject: [PATCH 1/8] Apply suggestions from code review Co-authored-by: Edward A. Lee --- .../core/federated/network/socket_common.h | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/include/core/federated/network/socket_common.h b/include/core/federated/network/socket_common.h index 71570c125..4d5aeb00d 100644 --- a/include/core/federated/network/socket_common.h +++ b/include/core/federated/network/socket_common.h @@ -2,7 +2,10 @@ #define SOCKET_COMMON_H #include "low_level_platform.h" -#define NUM_SOCKET_RETRIES 10 + +/** + * The amount of time to wait after a failed socket read or write before trying again. This defaults to 100 ms. + */ #define DELAY_BETWEEN_SOCKET_RETRIES MSEC(100) /** @@ -97,6 +100,7 @@ int create_real_time_tcp_socket_errexit(); * @return 0 for success, -1 for failure. */ int create_TCP_server(uint16_t port, int* final_socket, uint16_t* final_port, bool increment_port_on_retry); + /** * @brief Create a UDP server that listens for socket connections. * @@ -105,16 +109,21 @@ int create_TCP_server(uint16_t port, int* final_socket, uint16_t* final_port, bo * @param port The port number to use or 0 to let the OS pick or 1 to start trying at DEFAULT_PORT. * @param final_socket Pointer to the returned socket descriptor on which accepting connections will occur. * @param final_port Pointer to the final port the server will use. + * @param increment_port_on_retry Boolean to retry port increment. * @return 0 for success, -1 for failure. */ int create_UDP_server(uint16_t port, int* final_socket, uint16_t* final_port, bool increment_port_on_retry); /** - * These two functions waits for an incoming connection request on the specified server socket. - * It blocks until a connection is successfully accepted. If an error occurs that is not + * Wait for an incoming connection request on the specified server socket. + * This blocks until a connection is successfully accepted. If an error occurs that is not * temporary (e.g., `EAGAIN` or `EWOULDBLOCK`), it reports the error and exits. Temporary * errors cause the function to retry accepting the connection. - * If the rti_socket is not -1, it checks if the RTI's server socket is still open. + * + * If the `rti_socket` is not -1, this function checks whether the specified socket is still open. + * If it is not open, then this function returns -1. + * This is useful for federates to determine whether they are still connected to the federation + * and to stop waiting when they are not. * * @param socket The server socket file descriptor that is listening for incoming connections. * @param rti_socket The rti socket for the federate to check if it is still open. @@ -126,8 +135,8 @@ int accept_socket(int socket, int rti_socket); /** * - * This function attempts to establish a TCP connection to the specified hostname - * and port. It uses `getaddrinfo` to resolve the hostname and retries the connection + * Attempt to establish a TCP connection to the specified hostname + * and port. This function uses `getaddrinfo` to resolve the hostname and retries the connection * periodically if it fails. If the specified port is 0, it iterates through a range * of default ports starting from `DEFAULT_PORT`. The function will stop retrying * if the `CONNECT_TIMEOUT` is reached. From b2a5af8206f7a973d04eba8661d8978889fd2ed9 Mon Sep 17 00:00:00 2001 From: Dongha Kim Date: Fri, 27 Dec 2024 07:37:22 +0900 Subject: [PATCH 2/8] Make create_server to one integrated function of TCP and UDP. --- core/federated/RTI/rti_remote.c | 6 +++--- core/federated/RTI/rti_remote.h | 3 +-- core/federated/federate.c | 2 +- core/federated/network/socket_common.c | 17 ++++------------- include/core/federated/network/socket_common.h | 16 ++++------------ 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/core/federated/RTI/rti_remote.c b/core/federated/RTI/rti_remote.c index 2ca3ad139..4d38d416f 100644 --- a/core/federated/RTI/rti_remote.c +++ b/core/federated/RTI/rti_remote.c @@ -1508,15 +1508,15 @@ void initialize_federate(federate_info_t* fed, uint16_t id) { int32_t start_rti_server(uint16_t port) { _lf_initialize_clock(); // Create the TCP socket server - if (create_TCP_server(port, &rti_remote->socket_descriptor_TCP, &rti_remote->final_port_TCP, true)) { + if (create_server(port, &rti_remote->socket_descriptor_TCP, &rti_remote->final_port_TCP, TCP, true)) { lf_print_error_system_failure("RTI failed to create TCP server: %s.", strerror(errno)); }; lf_print("RTI: Listening for federates."); // Create the UDP socket server // Try to get the rti_remote->final_port_TCP + 1 port if (rti_remote->clock_sync_global_status >= clock_sync_on) { - if (create_UDP_server(rti_remote->final_port_TCP + 1, &rti_remote->socket_descriptor_UDP, - &rti_remote->final_port_UDP, true)) { + if (create_server(rti_remote->final_port_TCP + 1, &rti_remote->socket_descriptor_UDP, + &rti_remote->final_port_UDP, UDP, true)) { lf_print_error_system_failure("RTI failed to create UDP server: %s.", strerror(errno)); } } diff --git a/core/federated/RTI/rti_remote.h b/core/federated/RTI/rti_remote.h index 000fabcac..de6b144aa 100644 --- a/core/federated/RTI/rti_remote.h +++ b/core/federated/RTI/rti_remote.h @@ -31,6 +31,7 @@ #include "lf_types.h" #include "pqueue_tag.h" +#include "socket_common.h" /** Time allowed for federates to reply to stop request. */ #define MAX_TIME_FOR_REPLY_TO_STOP_REQUEST SEC(30) @@ -38,8 +39,6 @@ ///////////////////////////////////////////// //// Data structures -typedef enum socket_type_t { TCP, UDP } socket_type_t; - /** * Information about a federate known to the RTI, including its runtime state, * mode of execution, and connectivity with other federates. diff --git a/core/federated/federate.c b/core/federated/federate.c index f8f13d740..fc2f86911 100644 --- a/core/federated/federate.c +++ b/core/federated/federate.c @@ -1942,7 +1942,7 @@ void lf_connect_to_rti(const char* hostname, int port) { void lf_create_server(int specified_port) { assert(specified_port <= UINT16_MAX && specified_port >= 0); - if (create_TCP_server(specified_port, &_fed.server_socket, (uint16_t*)&_fed.server_port, false)) { + if (create_server(specified_port, &_fed.server_socket, (uint16_t*)&_fed.server_port, TCP, false)) { lf_print_error_system_failure("RTI failed to create TCP server: %s.", strerror(errno)); }; LF_PRINT_LOG("Server for communicating with other federates started using port %d.", _fed.server_port); diff --git a/core/federated/network/socket_common.c b/core/federated/network/socket_common.c index 20fff0585..1d6945346 100644 --- a/core/federated/network/socket_common.c +++ b/core/federated/network/socket_common.c @@ -133,11 +133,10 @@ static int set_socket_bind_option(int socket_descriptor, uint16_t specified_port return used_port; } -static int create_server(uint16_t port, int* final_socket, uint16_t* final_port, int sock_type, - bool increment_port_on_retry) { +int create_server(uint16_t port, int* final_socket, uint16_t* final_port, socket_type_t sock_type, bool increment_port_on_retry) { int socket_descriptor; struct timeval timeout_time; - if (sock_type == 0) { + if (sock_type == TCP) { // Create an IPv4 socket for TCP. socket_descriptor = create_real_time_tcp_socket_errexit(); // Set the timeout time for the communications of the server @@ -149,14 +148,14 @@ static int create_server(uint16_t port, int* final_socket, uint16_t* final_port, timeout_time = (struct timeval){.tv_sec = UDP_TIMEOUT_TIME / BILLION, .tv_usec = (UDP_TIMEOUT_TIME % BILLION) / 1000}; } - char* type = (sock_type == 0) ? "TCP" : "UDP"; + char* type = (sock_type == TCP) ? "TCP" : "UDP"; if (socket_descriptor < 0) { lf_print_error("Failed to create %s socket.", type); return -1; } set_socket_timeout_option(socket_descriptor, &timeout_time); int used_port = set_socket_bind_option(socket_descriptor, port, increment_port_on_retry); - if (sock_type == 0) { + if (sock_type == TCP) { // Enable listening for socket connections. // The second argument is the maximum number of queued socket requests, // which according to the Mac man page is limited to 128. @@ -170,14 +169,6 @@ static int create_server(uint16_t port, int* final_socket, uint16_t* final_port, return 0; } -int create_TCP_server(uint16_t port, int* final_socket, uint16_t* final_port, bool increment_port_on_retry) { - return create_server(port, final_socket, final_port, 0, increment_port_on_retry); -} - -int create_UDP_server(uint16_t port, int* final_socket, uint16_t* final_port, bool increment_port_on_retry) { - return create_server(port, final_socket, final_port, 1, increment_port_on_retry); -} - /** * Return true if either the socket to the RTI is broken or the socket is * alive and the first unread byte on the socket's queue is MSG_TYPE_FAILED. diff --git a/include/core/federated/network/socket_common.h b/include/core/federated/network/socket_common.h index 71570c125..a9e744791 100644 --- a/include/core/federated/network/socket_common.h +++ b/include/core/federated/network/socket_common.h @@ -63,6 +63,8 @@ */ #define MSG_TYPE_FAILED 25 +typedef enum socket_type_t { TCP, UDP } socket_type_t; + /** * Mutex protecting socket close operations. */ @@ -93,21 +95,11 @@ int create_real_time_tcp_socket_errexit(); * @param port The port number to use or 0 to let the OS pick or 1 to start trying at DEFAULT_PORT. * @param final_socket Pointer to the returned socket descriptor on which accepting connections will occur. * @param final_port Pointer to the final port the server will use. + * @param sock_type Type of the socket wheter TCP or UDP. * @param increment_port_on_retry Boolean to retry port increment. * @return 0 for success, -1 for failure. */ -int create_TCP_server(uint16_t port, int* final_socket, uint16_t* final_port, bool increment_port_on_retry); -/** - * @brief Create a UDP server that listens for socket connections. - * - * This function is just like create_TCP_server(), except that it creates a UDP server. - * - * @param port The port number to use or 0 to let the OS pick or 1 to start trying at DEFAULT_PORT. - * @param final_socket Pointer to the returned socket descriptor on which accepting connections will occur. - * @param final_port Pointer to the final port the server will use. - * @return 0 for success, -1 for failure. - */ -int create_UDP_server(uint16_t port, int* final_socket, uint16_t* final_port, bool increment_port_on_retry); +int create_server(uint16_t port, int* final_socket, uint16_t* final_port, socket_type_t sock_type, bool increment_port_on_retry); /** * These two functions waits for an incoming connection request on the specified server socket. From 817d2f9d5796ba992c8dbfce76090aa3a23300ed Mon Sep 17 00:00:00 2001 From: Dongha Kim Date: Fri, 27 Dec 2024 08:12:38 +0900 Subject: [PATCH 3/8] Fix formatting. --- core/federated/RTI/rti_remote.c | 4 ++-- core/federated/network/socket_common.c | 3 ++- include/core/federated/network/socket_common.h | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/federated/RTI/rti_remote.c b/core/federated/RTI/rti_remote.c index 4d38d416f..6f705d2b9 100644 --- a/core/federated/RTI/rti_remote.c +++ b/core/federated/RTI/rti_remote.c @@ -1515,8 +1515,8 @@ int32_t start_rti_server(uint16_t port) { // Create the UDP socket server // Try to get the rti_remote->final_port_TCP + 1 port if (rti_remote->clock_sync_global_status >= clock_sync_on) { - if (create_server(rti_remote->final_port_TCP + 1, &rti_remote->socket_descriptor_UDP, - &rti_remote->final_port_UDP, UDP, true)) { + if (create_server(rti_remote->final_port_TCP + 1, &rti_remote->socket_descriptor_UDP, &rti_remote->final_port_UDP, + UDP, true)) { lf_print_error_system_failure("RTI failed to create UDP server: %s.", strerror(errno)); } } diff --git a/core/federated/network/socket_common.c b/core/federated/network/socket_common.c index 1d6945346..cc71e897b 100644 --- a/core/federated/network/socket_common.c +++ b/core/federated/network/socket_common.c @@ -133,7 +133,8 @@ static int set_socket_bind_option(int socket_descriptor, uint16_t specified_port return used_port; } -int create_server(uint16_t port, int* final_socket, uint16_t* final_port, socket_type_t sock_type, bool increment_port_on_retry) { +int create_server(uint16_t port, int* final_socket, uint16_t* final_port, socket_type_t sock_type, + bool increment_port_on_retry) { int socket_descriptor; struct timeval timeout_time; if (sock_type == TCP) { diff --git a/include/core/federated/network/socket_common.h b/include/core/federated/network/socket_common.h index c3465c2f5..9d8a71d57 100644 --- a/include/core/federated/network/socket_common.h +++ b/include/core/federated/network/socket_common.h @@ -102,7 +102,8 @@ int create_real_time_tcp_socket_errexit(); * @param increment_port_on_retry Boolean to retry port increment. * @return 0 for success, -1 for failure. */ -int create_server(uint16_t port, int* final_socket, uint16_t* final_port, socket_type_t sock_type, bool increment_port_on_retry); +int create_server(uint16_t port, int* final_socket, uint16_t* final_port, socket_type_t sock_type, + bool increment_port_on_retry); /** * Wait for an incoming connection request on the specified server socket. From 106c827bb9c854cfeb3fa6f9307ed834bc953e26 Mon Sep 17 00:00:00 2001 From: Dongha Kim <74869052+Jakio815@users.noreply.github.com> Date: Sat, 28 Dec 2024 05:52:35 +0900 Subject: [PATCH 4/8] Update include/core/federated/network/socket_common.h Co-authored-by: Edward A. Lee --- include/core/federated/network/socket_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/core/federated/network/socket_common.h b/include/core/federated/network/socket_common.h index 9d8a71d57..9c6138e05 100644 --- a/include/core/federated/network/socket_common.h +++ b/include/core/federated/network/socket_common.h @@ -98,7 +98,7 @@ int create_real_time_tcp_socket_errexit(); * @param port The port number to use or 0 to let the OS pick or 1 to start trying at DEFAULT_PORT. * @param final_socket Pointer to the returned socket descriptor on which accepting connections will occur. * @param final_port Pointer to the final port the server will use. - * @param sock_type Type of the socket wheter TCP or UDP. + * @param sock_type Type of the socket, TCP or UDP. * @param increment_port_on_retry Boolean to retry port increment. * @return 0 for success, -1 for failure. */ From 6583e303561f7ddf045c617ee04a9a7519a0fc89 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 27 Dec 2024 18:22:02 -0800 Subject: [PATCH 5/8] First pass at full names for reactors --- core/reactor_common.c | 28 ++++++++++++++++++++++++++++ include/api/reaction_macros.h | 6 ++++++ include/api/reaction_macros_undef.h | 2 ++ include/core/lf_types.h | 3 +++ include/core/reactor.h | 10 ++++++++++ 5 files changed, 49 insertions(+) diff --git a/core/reactor_common.c b/core/reactor_common.c index 358480eb8..6063d9d27 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -149,6 +149,34 @@ void lf_set_stop_tag(environment_t* env, tag_t tag) { } } +const char* lf_reactor_full_name(self_base_t* self) { + if (self->full_name != NULL) { + return self->full_name; + } + // First find the length of the name. + size_t len = 0; + len += strlen(self->name); + self_base_t* parent = self->parent; + while (parent != NULL) { + len++; + len += strlen(parent->name); + parent = parent->parent; + } + self->full_name = (char*)lf_allocate(len + 1, sizeof(char), &self->allocations); + + size_t location = len - strlen(self->name); + strncpy(&self->full_name[location], self->name, strlen(self->name) + 1); + parent = self->parent; + while(parent != NULL) { + location--; + self->full_name[location] = '.'; + location -= strlen(parent->name); + strncpy(&self->full_name[location], parent->name, strlen(parent->name)); + parent = parent->parent; + } + return self->full_name; +} + #ifdef FEDERATED_DECENTRALIZED interval_t lf_get_stp_offset() { return lf_fed_STA_offset; } diff --git a/include/api/reaction_macros.h b/include/api/reaction_macros.h index 52c39e125..c019a5cff 100644 --- a/include/api/reaction_macros.h +++ b/include/api/reaction_macros.h @@ -199,4 +199,10 @@ */ #define lf_time_logical_elapsed() lf_time_logical_elapsed(self->base.environment) +/** + * @brief Return the fully qualified name of the reactor. + * @param reactor The reactor to get the name of. + */ +#define lf_reactor_full_name(reactor) lf_reactor_full_name(&reactor->base) + #endif // REACTION_MACROS_H diff --git a/include/api/reaction_macros_undef.h b/include/api/reaction_macros_undef.h index 601ea34d3..8055c0ca6 100644 --- a/include/api/reaction_macros_undef.h +++ b/include/api/reaction_macros_undef.h @@ -26,4 +26,6 @@ #undef lf_time_logical #undef lf_time_logical_elapsed +#undef lf_reactor_full_name + #endif // REACTION_MACROS_H diff --git a/include/core/lf_types.h b/include/core/lf_types.h index b6d754ca2..c7f8150ea 100644 --- a/include/core/lf_types.h +++ b/include/core/lf_types.h @@ -277,6 +277,9 @@ typedef struct self_base_t { struct allocation_record_t* allocations; struct reaction_t* executing_reaction; // The currently executing reaction of the reactor. environment_t* environment; + char* name; // The name of the reactor. If a bank, appended with [index]. + char* full_name; // The full name of the reactor or NULL if lf_reactor_full_name() is not called. + self_base_t* parent; // The parent of this reactor. #if !defined(LF_SINGLE_THREADED) void* reactor_mutex; // If not null, this is expected to point to an lf_mutex_t. // It is not declared as such to avoid a dependence on platform.h. diff --git a/include/core/reactor.h b/include/core/reactor.h index fffa9ba19..519ef3f61 100644 --- a/include/core/reactor.h +++ b/include/core/reactor.h @@ -128,5 +128,15 @@ void lf_free_all_reactors(void); */ void lf_free_reactor(self_base_t* self); +/** + * @brief Return the full name of the reactor. + * + * The full name includes the names of all the parent reactors, separated by dots. + * If any reactor is a bank, the name will have a suffix of the form `[bank_index]`. + * + * @param self The self struct of the reactor. + */ +const char* lf_reactor_full_name(self_base_t* self); + #endif /* REACTOR_H */ /** @} */ From 89bfac97e97b8709a90a9872464f31083da21677 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 27 Dec 2024 21:00:34 -0800 Subject: [PATCH 6/8] Format --- core/reactor_common.c | 2 +- include/core/lf_types.h | 4 ++-- include/core/reactor.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index 6063d9d27..9fd04e356 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -167,7 +167,7 @@ const char* lf_reactor_full_name(self_base_t* self) { size_t location = len - strlen(self->name); strncpy(&self->full_name[location], self->name, strlen(self->name) + 1); parent = self->parent; - while(parent != NULL) { + while (parent != NULL) { location--; self->full_name[location] = '.'; location -= strlen(parent->name); diff --git a/include/core/lf_types.h b/include/core/lf_types.h index c7f8150ea..b0bf58b70 100644 --- a/include/core/lf_types.h +++ b/include/core/lf_types.h @@ -277,8 +277,8 @@ typedef struct self_base_t { struct allocation_record_t* allocations; struct reaction_t* executing_reaction; // The currently executing reaction of the reactor. environment_t* environment; - char* name; // The name of the reactor. If a bank, appended with [index]. - char* full_name; // The full name of the reactor or NULL if lf_reactor_full_name() is not called. + char* name; // The name of the reactor. If a bank, appended with [index]. + char* full_name; // The full name of the reactor or NULL if lf_reactor_full_name() is not called. self_base_t* parent; // The parent of this reactor. #if !defined(LF_SINGLE_THREADED) void* reactor_mutex; // If not null, this is expected to point to an lf_mutex_t. diff --git a/include/core/reactor.h b/include/core/reactor.h index 519ef3f61..256fa5c8c 100644 --- a/include/core/reactor.h +++ b/include/core/reactor.h @@ -130,10 +130,10 @@ void lf_free_reactor(self_base_t* self); /** * @brief Return the full name of the reactor. - * + * * The full name includes the names of all the parent reactors, separated by dots. * If any reactor is a bank, the name will have a suffix of the form `[bank_index]`. - * + * * @param self The self struct of the reactor. */ const char* lf_reactor_full_name(self_base_t* self); From 9162ff634ab416f2429ce3b20525c24f7b12b25f Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Dec 2024 08:29:17 -0800 Subject: [PATCH 7/8] Use memcpy rather than strncpy --- core/reactor_common.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index 9fd04e356..d97b0a84d 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -153,25 +153,27 @@ const char* lf_reactor_full_name(self_base_t* self) { if (self->full_name != NULL) { return self->full_name; } - // First find the length of the name. - size_t len = 0; - len += strlen(self->name); + // First find the length of the full name. + size_t name_len = strlen(self->name); + size_t len = name_len; self_base_t* parent = self->parent; while (parent != NULL) { - len++; + len++; // For the dot. len += strlen(parent->name); parent = parent->parent; } self->full_name = (char*)lf_allocate(len + 1, sizeof(char), &self->allocations); + self->full_name[len] = '\0'; // Null terminate the string. - size_t location = len - strlen(self->name); - strncpy(&self->full_name[location], self->name, strlen(self->name) + 1); + size_t location = len - name_len; + memcpy(&self->full_name[location], self->name, name_len); parent = self->parent; while (parent != NULL) { location--; self->full_name[location] = '.'; - location -= strlen(parent->name); - strncpy(&self->full_name[location], parent->name, strlen(parent->name)); + size_t parent_len = strlen(parent->name); + location -= parent_len; + memcpy(&self->full_name[location], parent->name, parent_len); parent = parent->parent; } return self->full_name; From 6306c1196bb5e165dac8dd807c8d1cc01ba85754 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Dec 2024 17:23:47 -0800 Subject: [PATCH 8/8] Added lf_reactor_name function --- core/reactor_common.c | 2 ++ include/api/reaction_macros.h | 15 +++++++++++++++ include/api/reaction_macros_undef.h | 1 + include/core/lf_types.h | 4 ++-- include/core/reactor.h | 15 +++++++++++++-- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index d97b0a84d..7257e5132 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -149,6 +149,8 @@ void lf_set_stop_tag(environment_t* env, tag_t tag) { } } +const char* lf_reactor_name(self_base_t* self) { return self->name; } + const char* lf_reactor_full_name(self_base_t* self) { if (self->full_name != NULL) { return self->full_name; diff --git a/include/api/reaction_macros.h b/include/api/reaction_macros.h index c019a5cff..c73cde530 100644 --- a/include/api/reaction_macros.h +++ b/include/api/reaction_macros.h @@ -199,8 +199,23 @@ */ #define lf_time_logical_elapsed() lf_time_logical_elapsed(self->base.environment) +/** + * @brief Return the instance name of the reactor. + * + * The instance name is the name of given to the instance created by the `new` operator in LF. + * If the instance is in a bank, then the name will have a suffix of the form `[bank_index]`. + * + * @param reactor The reactor to get the name of. + */ +#define lf_reactor_name(reactor) lf_reactor_name(&reactor->base) + /** * @brief Return the fully qualified name of the reactor. + * + * The fully qualified name of a reactor is the instance name of the reactor concatenated with the names of all + * of its parents, separated by dots. If the reactor or any of its parents is a bank, then the name + * will have a suffix of the form `[bank_index]`. + * * @param reactor The reactor to get the name of. */ #define lf_reactor_full_name(reactor) lf_reactor_full_name(&reactor->base) diff --git a/include/api/reaction_macros_undef.h b/include/api/reaction_macros_undef.h index 8055c0ca6..26ab86b2e 100644 --- a/include/api/reaction_macros_undef.h +++ b/include/api/reaction_macros_undef.h @@ -26,6 +26,7 @@ #undef lf_time_logical #undef lf_time_logical_elapsed +#undef lf_reactor_name #undef lf_reactor_full_name #endif // REACTION_MACROS_H diff --git a/include/core/lf_types.h b/include/core/lf_types.h index b0bf58b70..385fc654e 100644 --- a/include/core/lf_types.h +++ b/include/core/lf_types.h @@ -251,8 +251,8 @@ struct trigger_t { * An allocation record that is used by a destructor for a reactor * to free memory that has been dynamically allocated for the particular * instance of the reactor. This will be an element of linked list. - * If the indirect field is true, then the allocated pointer points to - * pointer to allocated memory, rather than directly to the allocated memory. + * The `allocated` pointer points to the allocated memory, and the `next` + * pointer points to the next allocation record (or NULL if there are no more). */ typedef struct allocation_record_t { void* allocated; diff --git a/include/core/reactor.h b/include/core/reactor.h index 256fa5c8c..c98f2e93b 100644 --- a/include/core/reactor.h +++ b/include/core/reactor.h @@ -128,11 +128,22 @@ void lf_free_all_reactors(void); */ void lf_free_reactor(self_base_t* self); +/** + * @brief Return the instance name of the reactor. + * + * The instance name is the name of given to the instance created by the `new` operator in LF. + * If the instance is in a bank, then the name will have a suffix of the form `[bank_index]`. + * + * @param self The self struct of the reactor. + */ +const char* lf_reactor_name(self_base_t* self); + /** * @brief Return the full name of the reactor. * - * The full name includes the names of all the parent reactors, separated by dots. - * If any reactor is a bank, the name will have a suffix of the form `[bank_index]`. + * The fully qualified name of a reactor is the instance name of the reactor concatenated with the names of all + * of its parents, separated by dots. If the reactor or any of its parents is a bank, then the name + * will have a suffix of the form `[bank_index]`. * * @param self The self struct of the reactor. */