diff --git a/iceoryx_platform/win/source/fnctl.cpp b/iceoryx_platform/win/source/fnctl.cpp index 7326c5939e..0237127123 100644 --- a/iceoryx_platform/win/source/fnctl.cpp +++ b/iceoryx_platform/win/source/fnctl.cpp @@ -16,6 +16,7 @@ #include "iceoryx_platform/fcntl.hpp" #include "iceoryx_platform/handle_translator.hpp" +#include "iceoryx_platform/logging.hpp" #include "iceoryx_platform/win32_errorHandling.hpp" #include "iceoryx_platform/windows.hpp" @@ -23,6 +24,8 @@ #include #include +#include + int iox_open(const char* pathname, int flags, mode_t mode) { int fd; @@ -44,7 +47,10 @@ int iox_ext_open(const char* pathname, int flags, mode_t mode) if (handle == INVALID_HANDLE_VALUE) { - fprintf(stderr, "unable to create file \"%s\"\n", pathname); + std::stringstream stream; + stream << "unable to create file \"" << pathname << "\""; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); + errno = EWOULDBLOCK; return -1; } @@ -54,14 +60,14 @@ int iox_ext_open(const char* pathname, int flags, mode_t mode) int iox_fcntl2(int, int) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_fcntl2' is not implemented in windows!"); errno = ENOSYS; return -1; } int iox_fcntl3(int, int, int) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_fcntl3' is not implemented in windows!"); errno = ENOSYS; return -1; } diff --git a/iceoryx_platform/win/source/getopt.cpp b/iceoryx_platform/win/source/getopt.cpp index 7600ce57b0..3b8cda250d 100644 --- a/iceoryx_platform/win/source/getopt.cpp +++ b/iceoryx_platform/win/source/getopt.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_platform/getopt.hpp" +#include "iceoryx_platform/logging.hpp" #include "iceoryx_platform/windows.hpp" #include @@ -28,8 +29,8 @@ int getopt_long(int argc, char* const[], const char*, const struct option*, int* { if (argc > 1) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); - fprintf(stderr, "command line arguments are not supported in windows\n"); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'getopt_long' is not implemented in windows!"); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "command line arguments are not supported in windows!"); } return -1; } diff --git a/iceoryx_platform/win/source/handle_translator.cpp b/iceoryx_platform/win/source/handle_translator.cpp index 1f2c80bd3d..a6cffd51a9 100644 --- a/iceoryx_platform/win/source/handle_translator.cpp +++ b/iceoryx_platform/win/source/handle_translator.cpp @@ -15,8 +15,10 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_platform/handle_translator.hpp" +#include "iceoryx_platform/logging.hpp" #include +#include constexpr int HandleTranslator::INVALID_LINUX_FD; @@ -81,8 +83,9 @@ void HandleTranslator::remove(const int linuxFd) noexcept auto iter = m_linuxToWindows.find(linuxFd); if (iter == m_linuxToWindows.end()) { - std::cerr << "Unable to release not registered file handle " << linuxFd << " since it was not acquired" - << std::endl; + std::stringstream stream; + stream << "Unable to release not registered file handle " << linuxFd << " since it was not acquired"; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); return; } diff --git a/iceoryx_platform/win/source/mman.cpp b/iceoryx_platform/win/source/mman.cpp index 46b70c8aa7..537b25f23a 100644 --- a/iceoryx_platform/win/source/mman.cpp +++ b/iceoryx_platform/win/source/mman.cpp @@ -16,13 +16,14 @@ #include "iceoryx_platform/mman.hpp" #include "iceoryx_platform/handle_translator.hpp" +#include "iceoryx_platform/logging.hpp" #include "iceoryx_platform/platform_settings.hpp" #include "iceoryx_platform/win32_errorHandling.hpp" -#include #include #include #include +#include #include static std::map handle2segment; @@ -37,10 +38,12 @@ void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) DWORD numberOfBytesToMap = length; auto printErrorMessage = [&] { - std::cerr << "Failed to map file mapping into process space with mmap( addr = " << std::hex << addr << std::dec - << ", length = " << length << ", [always assume PROT_READ | PROT_WRITE] prot = " << prot - << ", [always assume MAP_SHARED] flags = " << flags << ", fd = " << fd - << ", [always assume 0] offset = " << offset << ")" << std::endl; + std::stringstream stream; + stream << "Failed to map file mapping into process space with mmap( addr = " << std::hex << addr << std::dec + << ", length = " << length << ", [always assume PROT_READ | PROT_WRITE] prot = " << prot + << ", [always assume MAP_SHARED] flags = " << flags << ", fd = " << fd + << ", [always assume 0] offset = " << offset << ")"; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); }; void* mappedObject = Win32Call(MapViewOfFile, @@ -77,8 +80,10 @@ int munmap(void* addr, size_t length) } else { - std::cerr << "Failed to unmap memory region with munmap( addr = " << std::hex << addr << std::dec - << ", length = " << length << ")" << std::endl; + std::stringstream stream; + stream << "Failed to unmap memory region with munmap( addr = " << std::hex << addr << std::dec + << ", length = " << length << ")"; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); } return -1; @@ -89,9 +94,11 @@ int iox_shm_open(const char* name, int oflag, mode_t mode) HANDLE sharedMemoryHandle{nullptr}; auto printErrorMessage = [&] { - std::cerr << "Failed to create shared memory with iox_shm_open( name = " << name - << ", [only consider O_CREAT and O_EXCL] oflag = " << oflag - << ", [always assume read, write, execute for everyone] mode = " << mode << ")" << std::endl; + std::stringstream stream; + stream << "Failed to create shared memory with iox_shm_open( name = " << name + << ", [only consider O_CREAT and O_EXCL] oflag = " << oflag + << ", [always assume read, write, execute for everyone] mode = " << mode << ")"; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); }; bool hasCreatedShm = false; @@ -219,7 +226,9 @@ void internal_iox_shm_set_size(int fd, off_t length) auto iter = handle2segment.find(fd); if (iter == handle2segment.end()) { - std::cerr << "Unable to set shared memory size since the file descriptor is invalid." << std::endl; + std::stringstream stream; + stream << "Unable to set shared memory size since the file descriptor is invalid."; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); return; } @@ -227,7 +236,9 @@ void internal_iox_shm_set_size(int fd, off_t length) FILE* shm_state = fopen(name.c_str(), "wb"); if (shm_state == NULL) { - std::cerr << "Unable create shared memory state file \"" << name << "\"" << std::endl; + std::stringstream stream; + stream << "Unable create shared memory state file \"" << name << "\""; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); return; } uint64_t shm_size = length; diff --git a/iceoryx_platform/win/source/pthread.cpp b/iceoryx_platform/win/source/pthread.cpp index 549cbc76e0..c324f9d379 100644 --- a/iceoryx_platform/win/source/pthread.cpp +++ b/iceoryx_platform/win/source/pthread.cpp @@ -16,10 +16,12 @@ #include "iceoryx_platform/pthread.hpp" #include "iceoryx_platform/ipc_handle_manager.hpp" +#include "iceoryx_platform/logging.hpp" #include "iceoryx_platform/win32_errorHandling.hpp" #include "iceoryx_platform/windows.hpp" #include +#include #include HRESULT GetThreadDescription(HANDLE hThread, PWSTR* ppszThreadDescription); @@ -192,9 +194,10 @@ static HANDLE acquireMutexHandle(iox_pthread_mutex_t* mutex) newHandle = Win32Call(OpenMutexA, MUTEX_ALL_ACCESS, false, generateMutexName(mutex->uniqueId).c_str()).value; if (newHandle == nullptr) { - fprintf(stderr, - "interprocess mutex %s is corrupted - segmentation fault immenent\n", - generateMutexName(mutex->uniqueId).c_str()); + std::stringstream stream; + stream << "interprocess mutex '" << generateMutexName(mutex->uniqueId) + << "' is corrupted - segmentation fault immenent"; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); return nullptr; } diff --git a/iceoryx_platform/win/source/semaphore.cpp b/iceoryx_platform/win/source/semaphore.cpp index 21f4210f67..dfb102107f 100644 --- a/iceoryx_platform/win/source/semaphore.cpp +++ b/iceoryx_platform/win/source/semaphore.cpp @@ -17,8 +17,10 @@ #include "iceoryx_platform/semaphore.hpp" #include "iceoryx_platform/ipc_handle_manager.hpp" +#include "iceoryx_platform/logging.hpp" #include +#include static std::string generateSemaphoreName(const UniqueSystemId& id) { @@ -42,9 +44,12 @@ static HANDLE acquireSemaphoreHandle(iox_sem_t* sem) Win32Call(OpenSemaphoreA, SEMAPHORE_ALL_ACCESS, false, generateSemaphoreName(sem->uniqueId).c_str()).value; if (newHandle == nullptr) { - fprintf(stderr, - "interprocess semaphore %s is corrupted - segmentation fault immenent\n", - generateSemaphoreName(sem->uniqueId).c_str()); + std::stringstream stream; + stream << "interprocess semaphore '" << generateSemaphoreName(sem->uniqueId) + << "' is corrupted - segmentation fault immenent"; + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, stream.str().c_str()); + + return nullptr; } diff --git a/iceoryx_platform/win/source/socket.cpp b/iceoryx_platform/win/source/socket.cpp index e456066da1..c0e360d31e 100644 --- a/iceoryx_platform/win/source/socket.cpp +++ b/iceoryx_platform/win/source/socket.cpp @@ -15,47 +15,48 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_platform/socket.hpp" +#include "iceoryx_platform/logging.hpp" #include int iox_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_bind' is not implemented in windows!"); return 0; } int iox_socket(int domain, int type, int protocol) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_socket' is not implemented in windows!"); return 0; } int iox_setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t optlen) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_setsockopt' is not implemented in windows!"); return 0; } ssize_t iox_sendto(int sockfd, const void* buf, size_t len, int flags, const struct sockaddr* dest_addr, socklen_t addrlen) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_sendto' is not implemented in windows!"); return 0; } ssize_t iox_recvfrom(int sockfd, void* buf, size_t len, int flags, struct sockaddr* src_addr, socklen_t* addrlen) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_recvfrom' is not implemented in windows!"); return 0; } int iox_connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_connect' is not implemented in windows!"); return 0; } int iox_closesocket(int sockfd) { - fprintf(stderr, "%s is not implemented in windows!\n", __PRETTY_FUNCTION__); + IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_closesocket' is not implemented in windows!"); return 0; } diff --git a/iceoryx_platform/win/source/win32_errorHandling.cpp b/iceoryx_platform/win/source/win32_errorHandling.cpp index 0ea5ac9340..8409e335f4 100644 --- a/iceoryx_platform/win/source/win32_errorHandling.cpp +++ b/iceoryx_platform/win/source/win32_errorHandling.cpp @@ -19,7 +19,6 @@ #include "iceoryx_platform/logging.hpp" #include -#include #include int __PrintLastErrorToConsole(const char* functionName, const char* file, const int line) noexcept