From 850e57a002be593346b92a7469c4bbbdf2fe1c55 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 10 Nov 2023 17:01:20 +0000 Subject: [PATCH] ipc: Move non-channel functions to utils [NFC] --- src/xrt/ipc/CMakeLists.txt | 1 + src/xrt/ipc/shared/ipc_utils.c | 32 +++++++++++++++++++ src/xrt/ipc/shared/ipc_utils.h | 40 +++++++++++++++++------- src/xrt/ipc/shared/ipc_utils_windows.cpp | 7 ----- 4 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 src/xrt/ipc/shared/ipc_utils.c diff --git a/src/xrt/ipc/CMakeLists.txt b/src/xrt/ipc/CMakeLists.txt index b2772e98a..25a26a8ad 100644 --- a/src/xrt/ipc/CMakeLists.txt +++ b/src/xrt/ipc/CMakeLists.txt @@ -31,6 +31,7 @@ set(IPC_COMMON_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/ipc_protocol_generated.h shared/ipc_shmem.c shared/ipc_shmem.h + shared/ipc_utils.c shared/ipc_utils.h ) diff --git a/src/xrt/ipc/shared/ipc_utils.c b/src/xrt/ipc/shared/ipc_utils.c new file mode 100644 index 000000000..6fdd5ae43 --- /dev/null +++ b/src/xrt/ipc/shared/ipc_utils.c @@ -0,0 +1,32 @@ +// Copyright 2022, Magic Leap, Inc. +// Copyright 2020-2023, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief IPC util helpers. + * @author Julian Petrov + * @author Jakob Bornecrantz + * @ingroup ipc_shared + */ + +#include "ipc_utils.h" + +#ifdef XRT_OS_WINDOWS +#include "util/u_windows.h" +#endif + + +/* + * + * Misc utils 'exported' functions. + * + */ + +#ifdef XRT_OS_WINDOWS +const char * +ipc_winerror(DWORD err) +{ + static char s_buf[4096]; // N.B. Not thread-safe. If needed, use a thread var + return u_winerror(s_buf, sizeof(s_buf), err, false); +} +#endif diff --git a/src/xrt/ipc/shared/ipc_utils.h b/src/xrt/ipc/shared/ipc_utils.h index 3a5026cce..ce2c85f3e 100644 --- a/src/xrt/ipc/shared/ipc_utils.h +++ b/src/xrt/ipc/shared/ipc_utils.h @@ -22,6 +22,34 @@ extern "C" { #endif + +/* + * + * Misc utils. + * + */ + +#if defined(XRT_OS_WINDOWS) || defined(XRT_DOXYGEN) +/*! + * Helper to convert windows error codes to human readable strings for logging. + * N.B. This routine is not thread safe. + * + * @param err windows error code + * @return human readable string corresponding to the error code. + * + * @ingroup ipc_shared + */ +const char * +ipc_winerror(DWORD err); +#endif + + +/* + * + * Channel functions. + * + */ + /*! * Wrapper for a socket and flags. */ @@ -155,18 +183,6 @@ xrt_result_t ipc_send_handles( struct ipc_message_channel *imc, const void *data, size_t size, const HANDLE *handles, uint32_t handle_count); -/*! - * Helper to convert windows error codes to human readable strings for logging - * N.B. This routine is not thread safe - * - * @param err windows error code - * @return human readable string corresponding to the error code - * - * @public @memberof ipc_message_channel - */ -const char * -ipc_winerror(DWORD err); - #endif // XRT_OS_UNIX /*! * @} diff --git a/src/xrt/ipc/shared/ipc_utils_windows.cpp b/src/xrt/ipc/shared/ipc_utils_windows.cpp index 8b2eda55f..cd2319123 100644 --- a/src/xrt/ipc/shared/ipc_utils_windows.cpp +++ b/src/xrt/ipc/shared/ipc_utils_windows.cpp @@ -93,13 +93,6 @@ open_target_process_dup_handle(struct ipc_message_channel *imc) * */ -const char * -ipc_winerror(DWORD err) -{ - static char s_buf[4096]; // N.B. Not thread-safe. If needed, use a thread var - return u_winerror(s_buf, sizeof(s_buf), err, false); -} - void ipc_message_channel_close(struct ipc_message_channel *imc) {