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 07183d8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
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());
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());
};

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());
}

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());
};

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());
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());
return;
}
uint64_t shm_size = length;
Expand Down
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 07183d8

Please sign in to comment.