From f61a51d91bbd6af90add4c04e30c02bc17b16f14 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 11 Jul 2023 11:16:45 -0400 Subject: [PATCH 1/5] Remove javadocs that moved to header file --- core/reactor.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/core/reactor.c b/core/reactor.c index d9e2bbc6e..2d17bb337 100644 --- a/core/reactor.c +++ b/core/reactor.c @@ -396,26 +396,14 @@ int lf_reactor_c_main(int argc, const char* argv[]) { } } -/** - * @brief Notify of new event by calling the unthreaded platform API - * @param env Environment in which we are executing. - */ int lf_notify_of_event(environment_t* env) { return _lf_unthreaded_notify_of_event(); } -/** - * @brief Enter critical section by disabling interrupts - * @param env Environment in which we are executing. - */ int lf_critical_section_enter(environment_t* env) { return lf_disable_interrupts_nested(); } -/** - * @brief Leave a critical section by enabling interrupts - * @param env Environment in which we are executing. - */ int lf_critical_section_exit(environment_t* env) { return lf_enable_interrupts_nested(); } From 1fe93d1cbfe53c4e3b9e9b3bf3d8263aa166d18f Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 11 Jul 2023 11:17:25 -0400 Subject: [PATCH 2/5] Added critical section function declarations to header file --- include/core/platform.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/core/platform.h b/include/core/platform.h index 283b76753..aee8004e2 100644 --- a/include/core/platform.h +++ b/include/core/platform.h @@ -50,6 +50,24 @@ extern "C" { // Forward declarations typedef struct environment_t environment_t; +/** + * @brief Notify of new event by calling the unthreaded platform API + * @param env Environment in which we are executing. + */ +int lf_notify_of_event(environment_t* env); + +/** + * @brief Enter critical section by disabling interrupts + * @param env Environment in which we are executing. + */ +int lf_critical_section_enter(environment_t* env); + +/** + * @brief Leave a critical section by enabling interrupts + * @param env Environment in which we are executing. + */ +int lf_critical_section_exit(environment_t* env); + #if defined(PLATFORM_ARDUINO) #include "platform/lf_arduino_support.h" #elif defined(PLATFORM_ZEPHYR) From ef3f708375d842dae6497e873b09e1ae6371bf65 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 11 Jul 2023 11:18:12 -0400 Subject: [PATCH 3/5] Removed declarations of functions not used anywhere --- include/core/reactor.h | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/include/core/reactor.h b/include/core/reactor.h index 87ba8b18f..e4069844a 100644 --- a/include/core/reactor.h +++ b/include/core/reactor.h @@ -547,23 +547,5 @@ void _lf_create_environments(); * runtime. Should be routed to appropriate API calls in platform.h */ -/** - * @brief Notify other threads of new events on the event queue. - * - */ -void _lf_notify_of_event(); - -/** - * @brief Enter critical section. Must be paired with a - * `_lf_critical_section_exit()` - * - */ -void _lf_critical_section_enter(); - -/** - * @brief Leave critical section - */ -void _lf_critical_section_exit(); - #endif /* REACTOR_H */ /** @} */ From 78767eb8421fba0a858ff6d7bf435c58a459ff62 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 11 Jul 2023 14:13:59 -0400 Subject: [PATCH 4/5] Expose utility functions even if not federated. Removed redundant comments. --- core/federated/net_util.c | 281 +++--------------------------- include/core/federated/net_util.h | 144 ++++++++------- 2 files changed, 102 insertions(+), 323 deletions(-) diff --git a/core/federated/net_util.c b/core/federated/net_util.c index 91cdc5427..9a5580a3b 100644 --- a/core/federated/net_util.c +++ b/core/federated/net_util.c @@ -30,7 +30,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * Utility functions for a federate in a federated execution. */ -#ifdef FEDERATED #include #include #include @@ -40,11 +39,14 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include // Defines memcpy() #include // Defines nanosleep() -#include // Defines read(), write(), and close() #include "net_util.h" #include "util.h" +// Define socket functions only for federated execution. +#ifdef FEDERATED +#include // Defines read(), write(), and close() + #ifndef NUMBER_OF_FEDERATES #define NUMBER_OF_FEDERATES 1 #endif @@ -52,43 +54,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** Number of nanoseconds to sleep before retrying a socket read. */ #define SOCKET_READ_RETRY_INTERVAL 1000000 -/** Return true (1) if the host is big endian. Otherwise, - * return false. - */ -int host_is_big_endian() { - static int host = 0; - union { - uint32_t uint; - unsigned char c[sizeof(uint32_t)]; - } x; - if (host == 0) { - // Determine the endianness of the host by setting the low-order bit. - x.uint = 0x01; - host = (x.c[3] == 0x01) ? HOST_BIG_ENDIAN : HOST_LITTLE_ENDIAN; - } - return (host == HOST_BIG_ENDIAN); -} - -/** - * Read the specified number of bytes from the specified socket into the - * specified buffer. If an error or an EOF occurs during this - * reading, then if format is non-null, close the socket, - * report an error and exit. - * If format is NULL, then just return 0 for EOF and a negative number - * for any other error. - * - * This function takes a formatted - * string and additional optional arguments similar to printf(format, ...) - * that is appended to the error messages. - * - * @param socket The socket ID. - * @param num_bytes The number of bytes to read. - * @param buffer The buffer into which to put the bytes. - * @param format A printf-style format string, followed by arguments to - * fill the string, or NULL to not exit with an error message. - * @return The number of bytes read, or 0 if an EOF is received, or - * a negative number for an error. - */ ssize_t read_from_socket_errexit( int socket, size_t num_bytes, @@ -129,44 +94,10 @@ ssize_t read_from_socket_errexit( return bytes_read; } -/** - * Read the specified number of bytes from the specified socket into the - * specified buffer. If a disconnect occurs during this - * reading, return a negative number. If an EOF occurs during this - * reading, return 0. Otherwise, return the number of bytes read. - * This is a version of read_from_socket_errexit() that neither - * closes the socket nor errors out. - * - * @param socket The socket ID. - * @param num_bytes The number of bytes to read. - * @param buffer The buffer into which to put the bytes. - * @return The number of bytes read or 0 when EOF is received or negative for an error. - */ ssize_t read_from_socket(int socket, size_t num_bytes, unsigned char* buffer) { return read_from_socket_errexit(socket, num_bytes, buffer, NULL); } -/** - * Write the specified number of bytes to the specified socket from the - * specified buffer. If an error or an EOF occurs during this - * reading, then if the format string is non-null, close the socket, - * report an error, and exit. If the format string is null, - * report an error or EOF and return. - * - * This function takes a formatted - * string and additional optional arguments similar to printf(format, ...) - * that is appended to the error messages. - * - * @param socket The socket ID. - * @param num_bytes The number of bytes to write. - * @param buffer The buffer from which to get the bytes. - * @param mutex If non-NULL, the mutex to unlock before exiting. - * @param format A format string for error messages, followed by any number of - * fields that will be used to fill the format string as in printf, or NULL - * to prevent exit on error. - * @return The number of bytes written, or 0 if an EOF was received, or a negative - * number if an error occurred. - */ ssize_t write_to_socket_errexit_with_mutex( int socket, size_t num_bytes, @@ -199,26 +130,6 @@ ssize_t write_to_socket_errexit_with_mutex( return bytes_written; } -/** - * Write the specified number of bytes to the specified socket from the - * specified buffer. If an error or an EOF occurs during this - * reading, then if the format string is non-null, close the socket, - * report an error, and exit. If the format string is null, - * report an error or EOF and return. - * - * This function takes a formatted - * string and additional optional arguments similar to printf(format, ...) - * that is appended to the error messages. - * - * @param socket The socket ID. - * @param num_bytes The number of bytes to write. - * @param buffer The buffer from which to get the bytes. - * @param format A format string for error messages, followed by any number of - * fields that will be used to fill the format string as in printf, or NULL - * to prevent exit on error. - * @return The number of bytes written, or 0 if an EOF was received, or a negative - * number if an error occurred. - */ ssize_t write_to_socket_errexit( int socket, size_t num_bytes, @@ -227,30 +138,14 @@ ssize_t write_to_socket_errexit( return write_to_socket_errexit_with_mutex(socket, num_bytes, buffer, NULL, format); } -/** - * Write the specified number of bytes to the specified socket from the - * specified buffer. If a disconnect or an EOF occurs during this - * reading, return a negative number or 0 respectively. Otherwise, - * return the number of bytes written. - * This is a version of write_to_socket_errexit() that neither closes - * the socket nor errors out. - * - * @param socket The socket ID. - * @param num_bytes The number of bytes to write. - * @param buffer The buffer from which to get the bytes. - * @return The number of bytes written, or 0 if an EOF was received, or a negative - * number if an error occurred. - */ ssize_t write_to_socket(int socket, size_t num_bytes, unsigned char* buffer) { return write_to_socket_errexit_with_mutex(socket, num_bytes, buffer, NULL, NULL); } -/** Write the specified data as a sequence of bytes starting - * at the specified address. This encodes the data in little-endian - * order (lowest order byte first). - * @param data The data to write. - * @param buffer The location to start writing. - */ +#endif // FEDERATED + +// Below are more generally useful functions. + void encode_int64(int64_t data, unsigned char* buffer) { // This strategy is fairly brute force, but it avoids potential // alignment problems. @@ -261,12 +156,6 @@ void encode_int64(int64_t data, unsigned char* buffer) { } } -/** Write the specified data as a sequence of bytes starting - * at the specified address. This encodes the data in little-endian - * order (lowest order byte first). This works for int32_t. - * @param data The data to write. - * @param buffer The location to start writing. - */ void encode_int32(int32_t data, unsigned char* buffer) { // This strategy is fairly brute force, but it avoids potential // alignment problems. Note that this assumes an int32_t is four bytes. @@ -276,12 +165,6 @@ void encode_int32(int32_t data, unsigned char* buffer) { buffer[3] = (unsigned char)((data & (int32_t)0xff000000) >> 24); } -/** Write the specified data as a sequence of bytes starting - * at the specified address. This encodes the data in little-endian - * order (lowest order byte first). This works for uint32_t. - * @param data The data to write. - * @param buffer The location to start writing. - */ void encode_uint32(uint32_t data, unsigned char* buffer) { // This strategy is fairly brute force, but it avoids potential // alignment problems. Note that this assumes a uint32_t is four bytes. @@ -291,12 +174,6 @@ void encode_uint32(uint32_t data, unsigned char* buffer) { buffer[3] = (unsigned char)((data & (uint32_t)0xff000000) >> 24); } -/** Write the specified data as a sequence of bytes starting - * at the specified address. This encodes the data in little-endian - * order (lowest order byte first). - * @param data The data to write. - * @param buffer The location to start writing. - */ void encode_uint16(uint16_t data, unsigned char* buffer) { // This strategy is fairly brute force, but it avoids potential // alignment problems. Note that this assumes a short is two bytes. @@ -304,16 +181,20 @@ void encode_uint16(uint16_t data, unsigned char* buffer) { buffer[1] = (unsigned char)((data & 0xff00) >> 8); } -/** If this host is little endian, then reverse the order of - * the bytes of the argument. Otherwise, return the argument - * unchanged. This can be used to convert the argument to - * network order (big endian) and then back again. - * Network transmissions, by convention, are big endian, - * meaning that the high-order byte is sent first. - * But many platforms, including my Mac, are little endian, - * meaning that the low-order byte is first in memory. - * @param src The argument to convert. - */ +int host_is_big_endian() { + static int host = 0; + union { + uint32_t uint; + unsigned char c[sizeof(uint32_t)]; + } x; + if (host == 0) { + // Determine the endianness of the host by setting the low-order bit. + x.uint = 0x01; + host = (x.c[3] == 0x01) ? HOST_BIG_ENDIAN : HOST_LITTLE_ENDIAN; + } + return (host == HOST_BIG_ENDIAN); +} + int32_t swap_bytes_if_big_endian_int32(int32_t src) { union { int32_t uint; @@ -331,16 +212,6 @@ int32_t swap_bytes_if_big_endian_int32(int32_t src) { return x.uint; } -/** If this host is little endian, then reverse the order of - * the bytes of the argument. Otherwise, return the argument - * unchanged. This can be used to convert the argument to - * network order (big endian) and then back again. - * Network transmissions, by convention, are big endian, - * meaning that the high-order byte is sent first. - * But many platforms, including my Mac, are little endian, - * meaning that the low-order byte is first in memory. - * @param src The argument to convert. - */ uint32_t swap_bytes_if_big_endian_uint32(uint32_t src) { union { uint32_t uint; @@ -358,16 +229,6 @@ uint32_t swap_bytes_if_big_endian_uint32(uint32_t src) { return x.uint; } -/** If this host is little endian, then reverse the order of - * the bytes of the argument. Otherwise, return the argument - * unchanged. This can be used to convert the argument to - * network order (big endian) and then back again. - * Network transmissions, by convention, are big endian, - * meaning that the high-order byte is sent first. - * But many platforms, including my Mac, are little endian, - * meaning that the low-order byte is first in memory. - * @param src The argument to convert. - */ int64_t swap_bytes_if_big_endian_int64(int64_t src) { union { int64_t ull; @@ -387,16 +248,6 @@ int64_t swap_bytes_if_big_endian_int64(int64_t src) { return x.ull; } -/** If this host is little endian, then reverse the order of - * the bytes of the argument. Otherwise, return the argument - * unchanged. This can be used to convert the argument to - * network order (big endian) and then back again. - * Network transmissions, by convention, are big endian, - * meaning that the high-order byte is sent first. - * But many platforms, including my Mac, are little endian, - * meaning that the low-order byte is first in memory. - * @param src The argument to convert. - */ uint16_t swap_bytes_if_big_endian_uint16(uint16_t src) { union { uint16_t uint; @@ -413,10 +264,6 @@ uint16_t swap_bytes_if_big_endian_uint16(uint16_t src) { return x.uint; } -/** Extract an int32_t from the specified byte sequence. - * This will swap the order of the bytes if this machine is big endian. - * @param bytes The address of the start of the sequence of bytes. - */ int32_t extract_int32(unsigned char* bytes) { // Use memcpy to prevent possible alignment problems on some processors. union { @@ -427,10 +274,6 @@ int32_t extract_int32(unsigned char* bytes) { return swap_bytes_if_big_endian_int32(result.uint); } -/** Extract a uint32_t from the specified byte sequence. - * This will swap the order of the bytes if this machine is big endian. - * @param bytes The address of the start of the sequence of bytes. - */ uint32_t extract_uint32(unsigned char* bytes) { // Use memcpy to prevent possible alignment problems on some processors. union { @@ -441,10 +284,6 @@ uint32_t extract_uint32(unsigned char* bytes) { return swap_bytes_if_big_endian_uint32(result.uint); } -/** Extract a int64_t from the specified byte sequence. - * This will swap the order of the bytes if this machine is big endian. - * @param bytes The address of the start of the sequence of bytes. - */ int64_t extract_int64(unsigned char* bytes) { // Use memcpy to prevent possible alignment problems on some processors. union { @@ -455,10 +294,6 @@ int64_t extract_int64(unsigned char* bytes) { return swap_bytes_if_big_endian_int64(result.ull); } -/** Extract an uint16_t from the specified byte sequence. - * This will swap the order of the bytes if this machine is big endian. - * @param bytes The address of the start of the sequence of bytes. - */ uint16_t extract_uint16(unsigned char* bytes) { // Use memcpy to prevent possible alignment problems on some processors. union { @@ -469,16 +304,8 @@ uint16_t extract_uint16(unsigned char* bytes) { return swap_bytes_if_big_endian_uint16(result.ushort); } -/** - * Extract the core header information that all messages between - * federates share. The core header information is two bytes with - * the ID of the destination port, two bytes with the ID of the destination - * federate, and four bytes with the length of the message. - * @param buffer The buffer to read from. - * @param port_id The place to put the port ID. - * @param federate_id The place to put the federate ID. - * @param length The place to put the length. - */ +#ifdef FEDERATED + void extract_header( unsigned char* buffer, uint16_t* port_id, @@ -507,18 +334,6 @@ void extract_header( // printf("DEBUG: Federate receiving message to port %d to federate %d of length %d.\n", port_id, federate_id, length); } -/** - * Extract the timed header information for timed messages between - * federates. This is two bytes with the ID of the destination port, - * two bytes with the ID of the destination - * federate, four bytes with the length of the message, - * eight bytes with a timestamp, and four bytes with a microstep. - * @param buffer The buffer to read from. - * @param port_id The place to put the port ID. - * @param federate_id The place to put the federate ID. - * @param length The place to put the length. - * @param tag The place to put the tag. - */ void extract_timed_header( unsigned char* buffer, uint16_t* port_id, @@ -535,15 +350,6 @@ void extract_timed_header( tag->microstep = temporary_tag.microstep; } -/** - * Extract tag information from buffer. - * - * The tag is transmitted as a 64-bit (8 byte) signed integer for time and a - * 32-bit (4 byte) unsigned integer for microstep. - * - * @param buffer The buffer to read from. - * @return The extracted tag. - */ tag_t extract_tag( unsigned char* buffer ) { @@ -554,14 +360,6 @@ tag_t extract_tag( return tag; } -/** - * Encode tag information into buffer. - * - * Buffer must have been allocated externally. - * - * @param buffer The buffer to encode into. - * @param tag The tag to encode into 'buffer'. - */ void encode_tag( unsigned char* buffer, tag_t tag @@ -570,11 +368,6 @@ void encode_tag( encode_uint32(tag.microstep, &(buffer[sizeof(int64_t)])); } - -/** - * Checks if str matches regex. - * @return true if there is a match, false otherwise. - */ bool match_regex(const char* str, char* regex) { regex_t regex_compiled; regmatch_t group; @@ -593,11 +386,6 @@ bool match_regex(const char* str, char* regex) { return valid; } - -/** - * Checks if port is valid. - * @return true if valid, false otherwise. - */ bool validate_port(char* port) { // magic number 6 since port range is [0, 65535] int port_len = strnlen(port, 6); @@ -614,11 +402,6 @@ bool validate_port(char* port) { return port_number >= 0 && port_number <= 65535; } - -/** - * Checks if host is valid. - * @return true if valid, false otherwise. - */ bool validate_host(const char* host) { // regex taken from LFValidator.xtend char* ipv4_regex = "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; @@ -626,21 +409,12 @@ bool validate_host(const char* host) { return match_regex(host, ipv4_regex) || match_regex(host, host_or_FQN_regex); } - -/** - * Checks if user is valid. - * @return true if valid, false otherwise. - */ bool validate_user(const char* user) { // regex taken from LFValidator.xtend char* username_regex = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$"; return match_regex(user, username_regex); } -/** - * Extract one match group from the rti_addr regex . - * @return true if SUCCESS, else false. - */ bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group, int max_len, int min_len, const char* err_msg) { size_t size = group.rm_eo - group.rm_so; @@ -653,10 +427,6 @@ bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group, return true; } -/** - * Extract match groups from the rti_addr regex. - * @return true if success, else false. - */ bool extract_match_groups(const char* rti_addr, char** rti_addr_strs, bool** rti_addr_flags, regmatch_t* group_array, int* gids, int* max_lens, int* min_lens, const char** err_msgs) { for (int i = 0; i < 3; i++) { @@ -671,9 +441,6 @@ bool extract_match_groups(const char* rti_addr, char** rti_addr_strs, bool** rti return true; } -/** - * Extract the host, port and user from rti_addr. - */ void extract_rti_addr_info(const char* rti_addr, rti_addr_info_t* rti_addr_info) { const char* regex_str = "(([a-zA-Z0-9_-]{1,254})@)?([a-zA-Z0-9.]{1,255})(:([0-9]{1,5}))?"; size_t max_groups = 6; diff --git a/include/core/federated/net_util.h b/include/core/federated/net_util.h index 666eac653..fc5c85248 100644 --- a/include/core/federated/net_util.h +++ b/include/core/federated/net_util.h @@ -54,11 +54,14 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define HOST_LITTLE_ENDIAN 1 #define HOST_BIG_ENDIAN 2 -/** Return true (1) if the host is big endian. Otherwise, - * return false. +/** + * Return true (1) if the host is big endian. Otherwise, + * return false. */ int host_is_big_endian(void); +#ifdef FEDERATED + /** * Read the specified number of bytes from the specified socket into the * specified buffer. If a disconnect or an EOF occurs during this @@ -157,92 +160,104 @@ ssize_t write_to_socket_errexit( */ int write_to_socket2(int socket, int num_bytes, unsigned char* buffer); -/** Write the specified data as a sequence of bytes starting - * at the specified address. This encodes the data in little-endian - * order (lowest order byte first). - * @param data The data to write. - * @param buffer The location to start writing. +#endif // FEDERATED + +/** + * Write the specified data as a sequence of bytes starting + * at the specified address. This encodes the data in little-endian + * order (lowest order byte first). + * @param data The data to write. + * @param buffer The location to start writing. */ void encode_int64(int64_t data, unsigned char* buffer); -/** Write the specified data as a sequence of bytes starting - * at the specified address. This encodes the data in little-endian - * order (lowest order byte first). This works for int32_t. - * @param data The data to write. - * @param buffer The location to start writing. +/** + * Write the specified data as a sequence of bytes starting + * at the specified address. This encodes the data in little-endian + * order (lowest order byte first). This works for int32_t. + * @param data The data to write. + * @param buffer The location to start writing. */ void encode_int32(int32_t data, unsigned char* buffer); -/** Write the specified data as a sequence of bytes starting - * at the specified address. This encodes the data in little-endian - * order (lowest order byte first). This works for uint32_t. - * @param data The data to write. - * @param buffer The location to start writing. +/** + * Write the specified data as a sequence of bytes starting + * at the specified address. This encodes the data in little-endian + * order (lowest order byte first). This works for uint32_t. + * @param data The data to write. + * @param buffer The location to start writing. */ void encode_uint32(uint32_t data, unsigned char* buffer); -/** Write the specified data as a sequence of bytes starting - * at the specified address. This encodes the data in little-endian - * order (lowest order byte first). - * @param data The data to write. - * @param buffer The location to start writing. +/** + * Write the specified data as a sequence of bytes starting + * at the specified address. This encodes the data in little-endian + * order (lowest order byte first). + * @param data The data to write. + * @param buffer The location to start writing. */ void encode_uint16(uint16_t data, unsigned char* buffer); -/** If this host is little endian, then reverse the order of - * the bytes of the argument. Otherwise, return the argument - * unchanged. This can be used to convert the argument to - * network order (big endian) and then back again. - * Network transmissions, by convention, are big endian, - * meaning that the high-order byte is sent first. - * But many platforms, including my Mac, are little endian, - * meaning that the low-order byte is first in memory. - * @param src The argument to convert. +/** + * If this host is little endian, then reverse the order of + * the bytes of the argument. Otherwise, return the argument + * unchanged. This can be used to convert the argument to + * network order (big endian) and then back again. + * Network transmissions, by convention, are big endian, + * meaning that the high-order byte is sent first. + * But many platforms, including my Mac, are little endian, + * meaning that the low-order byte is first in memory. + * @param src The argument to convert. */ int32_t swap_bytes_if_big_endian_int32(int32_t src); -/** If this host is little endian, then reverse the order of - * the bytes of the argument. Otherwise, return the argument - * unchanged. This can be used to convert the argument to - * network order (big endian) and then back again. - * Network transmissions, by convention, are big endian, - * meaning that the high-order byte is sent first. - * But many platforms, including my Mac, are little endian, - * meaning that the low-order byte is first in memory. - * @param src The argument to convert. +/** + * If this host is little endian, then reverse the order of + * the bytes of the argument. Otherwise, return the argument + * unchanged. This can be used to convert the argument to + * network order (big endian) and then back again. + * Network transmissions, by convention, are big endian, + * meaning that the high-order byte is sent first. + * But many platforms, including my Mac, are little endian, + * meaning that the low-order byte is first in memory. + * @param src The argument to convert. */ int64_t swap_bytes_if_big_endian_int64(int64_t src); -/** If this host is little endian, then reverse the order of - * the bytes of the argument. Otherwise, return the argument - * unchanged. This can be used to convert the argument to - * network order (big endian) and then back again. - * Network transmissions, by convention, are big endian, - * meaning that the high-order byte is sent first. - * But many platforms, including my Mac, are little endian, - * meaning that the low-order byte is first in memory. - * @param src The argument to convert. +/** + * If this host is little endian, then reverse the order of + * the bytes of the argument. Otherwise, return the argument + * unchanged. This can be used to convert the argument to + * network order (big endian) and then back again. + * Network transmissions, by convention, are big endian, + * meaning that the high-order byte is sent first. + * But many platforms, including my Mac, are little endian, + * meaning that the low-order byte is first in memory. + * @param src The argument to convert. */ uint16_t swap_bytes_if_big_endian_uint16(uint16_t src); -/** Extract an int32_t from the specified byte sequence. - * This will swap the order of the bytes if this machine is big endian. - * @param bytes The address of the start of the sequence of bytes. +/** + * This will swap the order of the bytes if this machine is big endian. + * @param bytes The address of the start of the sequence of bytes. */ int32_t extract_int32(unsigned char* bytes); -/** Extract a int64_t from the specified byte sequence. - * This will swap the order of the bytes if this machine is big endian. - * @param bytes The address of the start of the sequence of bytes. +/** + * This will swap the order of the bytes if this machine is big endian. + * @param bytes The address of the start of the sequence of bytes. */ int64_t extract_int64(unsigned char* bytes); -/** Extract an uint16_t from the specified byte sequence. - * This will swap the order of the bytes if this machine is big endian. - * @param bytes The address of the start of the sequence of bytes. +/** + * Extract an uint16_t from the specified byte sequence. + * This will swap the order of the bytes if this machine is big endian. + * @param bytes The address of the start of the sequence of bytes. */ uint16_t extract_uint16(unsigned char* bytes); +#ifdef FEDERATED + /** * Extract the core header information that all messages between * federates share. The core header information is two bytes with @@ -319,33 +334,29 @@ typedef struct rti_addr_info_t { } rti_addr_info_t; /** - * Checks if str matches regex. + * Check whether str matches regex. * @return true if there is a match, false otherwise. */ bool match_regex(const char* str, char* regex); - /** - * Checks if port is valid. + * Check whether port is valid. * @return true if valid, false otherwise. */ bool validate_port(char* port); - /** - * Checks if host is valid. + * Check whether host is valid. * @return true if valid, false otherwise. */ bool validate_host(const char* host); - /** - * Checks if user is valid. + * Check whether user is valid. * @return true if valid, false otherwise. */ bool validate_user(const char* user); - /** * Extract one match group from the rti_addr regex . * @return true if SUCCESS, else false. @@ -364,5 +375,6 @@ bool extract_match_groups(const char* rti_addr, char** rti_addr_strs, bool** rti */ void extract_rti_addr_info(const char* rti_addr, rti_addr_info_t* rti_addr_info); +#endif // FEDERATED #endif /* NET_UTIL_H */ From ac3f64993d40d8db2ee5e3af3fb10cbb8035b7c1 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 11 Jul 2023 14:30:32 -0400 Subject: [PATCH 5/5] Make signature of critical section functions compatible --- core/federated/RTI/rti_lib.c | 16 ++-------------- core/federated/RTI/rti_lib.h | 6 ++++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/core/federated/RTI/rti_lib.c b/core/federated/RTI/rti_lib.c index 76d398a41..21f1a460a 100644 --- a/core/federated/RTI/rti_lib.c +++ b/core/federated/RTI/rti_lib.c @@ -38,23 +38,11 @@ lf_mutex_t rti_mutex; lf_cond_t received_start_times; lf_cond_t sent_start_time; -/** - * Enter a critical section where logical time and the event queue are guaranteed - * to not change unless they are changed within the critical section. - * this can be implemented by disabling interrupts. - * Users of this function must ensure that lf_init_critical_sections() is - * called first and that lf_critical_section_exit() is called later. - * @return 0 on success, platform-specific error number otherwise. - */ -extern int lf_critical_section_enter() { +extern int lf_critical_section_enter(environment_t* env) { return lf_mutex_lock(&rti_mutex); } -/** - * Exit the critical section entered with lf_lock_time(). - * @return 0 on success, platform-specific error number otherwise. - */ -extern int lf_critical_section_exit() { +extern int lf_critical_section_exit(environment_t* env) { return lf_mutex_unlock(&rti_mutex); } diff --git a/core/federated/RTI/rti_lib.h b/core/federated/RTI/rti_lib.h index 4d474a562..9d7c63948 100644 --- a/core/federated/RTI/rti_lib.h +++ b/core/federated/RTI/rti_lib.h @@ -190,15 +190,17 @@ typedef struct federation_rti_t { * this can be implemented by disabling interrupts. * Users of this function must ensure that lf_init_critical_sections() is * called first and that lf_critical_section_exit() is called later. + * @param env Ignored (present for compatibility). * @return 0 on success, platform-specific error number otherwise. */ -extern int lf_critical_section_enter(); +extern int lf_critical_section_enter(environment_t* env); /** * Exit the critical section entered with lf_lock_time(). + * @param env Ignored (present for compatibility). * @return 0 on success, platform-specific error number otherwise. */ -extern int lf_critical_section_exit(); +extern int lf_critical_section_exit(environment_t* env); /** * Create a server and enable listening for socket connections.