From 20036df157ebebe4097cda6017b10bfaacf57ba7 Mon Sep 17 00:00:00 2001 From: Mateusz Daniluk <121170681+VeithMetro@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:05:09 +0200 Subject: [PATCH] [Messaging] Fixing the linking problems on Windows (#1421) * Moving the definitions of ControlStreamRedirects to the cpp file * Fixing bugs on Windows with TextStreamRedirectType header * Adding missing files to the project files * Adding a new cpp file to CMake as well * Removing constructor definitions from the header * Formating fixes --------- Co-authored-by: Pierre Wielders --- Source/core/TextStreamRedirectType.h | 6 ++- Source/core/core.vcxproj | 1 + Source/core/core.vcxproj.filters | 3 ++ Source/messaging/CMakeLists.txt | 6 +-- Source/messaging/ConsoleStreamRedirect.cpp | 45 ++++++++++++++++++++++ Source/messaging/ConsoleStreamRedirect.h | 18 ++------- Source/messaging/messaging.vcxproj | 3 ++ Source/messaging/messaging.vcxproj.filters | 9 +++++ 8 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 Source/messaging/ConsoleStreamRedirect.cpp diff --git a/Source/core/TextStreamRedirectType.h b/Source/core/TextStreamRedirectType.h index 6023bc396..937e2cb69 100644 --- a/Source/core/TextStreamRedirectType.h +++ b/Source/core/TextStreamRedirectType.h @@ -272,6 +272,10 @@ namespace Core { } return (_handle == nullptr); } + Core::IResource::handle Origin() const + { + return (_copy == Core::IResource::INVALID ? _index : _copy); + } private: bool CreateOverlappedPipe(HANDLE& readPipe, int& writePipe) @@ -475,7 +479,7 @@ namespace Core { if (length > 0) { dst.resize(length); vsnprintf((char*)dst.data(), dst.size() + 1, format, ap); - write(_channel.Origin(), dst.c_str(), length); + _write(_channel.Origin(), dst.c_str(), length); } else { dst = "Format error! format: "; diff --git a/Source/core/core.vcxproj b/Source/core/core.vcxproj index 60bff135c..83823d0bf 100644 --- a/Source/core/core.vcxproj +++ b/Source/core/core.vcxproj @@ -86,6 +86,7 @@ + diff --git a/Source/core/core.vcxproj.filters b/Source/core/core.vcxproj.filters index 34f84b90d..d37ef3acc 100644 --- a/Source/core/core.vcxproj.filters +++ b/Source/core/core.vcxproj.filters @@ -252,6 +252,9 @@ Header Files + + Header Files + diff --git a/Source/messaging/CMakeLists.txt b/Source/messaging/CMakeLists.txt index beff54646..c7bb2fe40 100644 --- a/Source/messaging/CMakeLists.txt +++ b/Source/messaging/CMakeLists.txt @@ -24,7 +24,8 @@ add_library(${TARGET} TraceCategories.cpp Logging.cpp DirectOutput.cpp - OperationalCategories.cpp) + ConsoleStreamRedirect.cpp + OperationalCategories.cpp) set(PUBLIC_HEADERS Module.h @@ -43,8 +44,7 @@ set(PUBLIC_HEADERS TextMessage.h BaseCategory.h ConsoleStreamRedirect.h - OperationalCategories.h - ) + OperationalCategories.h) target_compile_definitions(${TARGET} PRIVATE MESSAGING_EXPORTS) diff --git a/Source/messaging/ConsoleStreamRedirect.cpp b/Source/messaging/ConsoleStreamRedirect.cpp new file mode 100644 index 000000000..e6d76fb50 --- /dev/null +++ b/Source/messaging/ConsoleStreamRedirect.cpp @@ -0,0 +1,45 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2022 Metrological + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Module.h" +#include "ConsoleStreamRedirect.h" + +namespace WPEFramework { +namespace Messaging { + + ConsoleStandardOut::ConsoleStandardOut() +#ifdef __WINDOWS__ + : Core::TextStreamRedirectType(::_fileno(stdout)) +#else + : Core::TextStreamRedirectType(STDOUT_FILENO) +#endif + { + } + + ConsoleStandardError::ConsoleStandardError() +#ifdef __WINDOWS__ + : Core::TextStreamRedirectType(::_fileno(stderr)) +#else + : Core::TextStreamRedirectType(STDERR_FILENO) +#endif + { + } + +} +} diff --git a/Source/messaging/ConsoleStreamRedirect.h b/Source/messaging/ConsoleStreamRedirect.h index d47f8ed59..24b78e5dd 100644 --- a/Source/messaging/ConsoleStreamRedirect.h +++ b/Source/messaging/ConsoleStreamRedirect.h @@ -1,5 +1,6 @@ #pragma once +#include "Module.h" #include "Control.h" #include "OperationalCategories.h" @@ -60,13 +61,7 @@ namespace WPEFramework { ConsoleStandardOut& operator=(const ConsoleStandardOut&) = delete; private: - ConsoleStandardOut() -#ifdef __WINDOWS__ - : Core::TextStreamRedirectType(::_fileno(stdout)) { -#else - : Core::TextStreamRedirectType(STDOUT_FILENO) { -#endif - } + ConsoleStandardOut(); public: ~ConsoleStandardOut() = default; @@ -87,16 +82,11 @@ namespace WPEFramework { ConsoleStandardError& operator=(const ConsoleStandardError&) = delete; private: - ConsoleStandardError() -#ifdef __WINDOWS__ - : Core::TextStreamRedirectType(::_fileno(stderr)) { -#else - : Core::TextStreamRedirectType(STDERR_FILENO) { -#endif - } + ConsoleStandardError(); public: ~ConsoleStandardError() = default; + static ConsoleStandardError& Instance() { static ConsoleStandardError singleton; diff --git a/Source/messaging/messaging.vcxproj b/Source/messaging/messaging.vcxproj index 8a2008879..8c40f9ed8 100644 --- a/Source/messaging/messaging.vcxproj +++ b/Source/messaging/messaging.vcxproj @@ -31,6 +31,7 @@ + @@ -38,11 +39,13 @@ + + diff --git a/Source/messaging/messaging.vcxproj.filters b/Source/messaging/messaging.vcxproj.filters index f8de8cb2e..8a47fefac 100644 --- a/Source/messaging/messaging.vcxproj.filters +++ b/Source/messaging/messaging.vcxproj.filters @@ -60,6 +60,9 @@ Header Files + + Header Files + @@ -80,5 +83,11 @@ Source Files + + Source Files + + + Source Files + \ No newline at end of file