Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1755 Use platform log frontend everywhere on Wind…
Browse files Browse the repository at this point in the history
…ows platform
  • Loading branch information
elBoberido committed Mar 11, 2024
1 parent 5f19966 commit ea83c57
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 33 deletions.
12 changes: 9 additions & 3 deletions iceoryx_platform/win/source/fnctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

#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"

#include <io.h>
#include <share.h>
#include <sys/stat.h>

#include <sstream>

int iox_open(const char* pathname, int flags, mode_t mode)
{
int fd;
Expand All @@ -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;
}
Expand All @@ -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;
}
5 changes: 3 additions & 2 deletions iceoryx_platform/win/source/getopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdio>
Expand All @@ -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;
}
7 changes: 5 additions & 2 deletions iceoryx_platform/win/source/handle_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_platform/handle_translator.hpp"
#include "iceoryx_platform/logging.hpp"

#include <iostream>
#include <sstream>

constexpr int HandleTranslator::INVALID_LINUX_FD;

Expand Down Expand Up @@ -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;
}

Expand Down
35 changes: 23 additions & 12 deletions iceoryx_platform/win/source/mman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
#include <map>
#include <mutex>
#include <set>
#include <sstream>
#include <string>

static std::map<int, std::string> handle2segment;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -219,15 +226,19 @@ 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;
}

std::string name = shm_state_file_name(iter->second);
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;
Expand Down
9 changes: 6 additions & 3 deletions iceoryx_platform/win/source/pthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cwchar>
#include <sstream>
#include <vector>

HRESULT GetThreadDescription(HANDLE hThread, PWSTR* ppszThreadDescription);
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 8 additions & 3 deletions iceoryx_platform/win/source/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

#include "iceoryx_platform/semaphore.hpp"
#include "iceoryx_platform/ipc_handle_manager.hpp"
#include "iceoryx_platform/logging.hpp"

#include <cstdarg>
#include <sstream>

static std::string generateSemaphoreName(const UniqueSystemId& id)
{
Expand All @@ -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;
}

Expand Down
15 changes: 8 additions & 7 deletions iceoryx_platform/win/source/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,48 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_platform/socket.hpp"
#include "iceoryx_platform/logging.hpp"
#include <cstdio>

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;
}
1 change: 0 additions & 1 deletion iceoryx_platform/win/source/win32_errorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "iceoryx_platform/logging.hpp"

#include <cstdio>
#include <iostream>
#include <mutex>

int __PrintLastErrorToConsole(const char* functionName, const char* file, const int line) noexcept
Expand Down

0 comments on commit ea83c57

Please sign in to comment.