Skip to content

Commit

Permalink
[Messaging] Fixing the linking problems on Windows (#1421)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
VeithMetro and pwielders authored Oct 4, 2023
1 parent 7f0fd3d commit 20036df
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 18 deletions.
6 changes: 5 additions & 1 deletion Source/core/TextStreamRedirectType.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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: ";
Expand Down
1 change: 1 addition & 0 deletions Source/core/core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<ClInclude Include="SystemInfo.h" />
<ClInclude Include="TextFragment.h" />
<ClInclude Include="TextReader.h" />
<ClInclude Include="TextStreamRedirectType.h" />
<ClInclude Include="Thread.h" />
<ClInclude Include="ThreadPool.h" />
<ClInclude Include="Time.h" />
Expand Down
3 changes: 3 additions & 0 deletions Source/core/core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@
<ClInclude Include="FileObserver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TextStreamRedirectType.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CyclicBuffer.cpp">
Expand Down
6 changes: 3 additions & 3 deletions Source/messaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ add_library(${TARGET}
TraceCategories.cpp
Logging.cpp
DirectOutput.cpp
OperationalCategories.cpp)
ConsoleStreamRedirect.cpp
OperationalCategories.cpp)

set(PUBLIC_HEADERS
Module.h
Expand All @@ -43,8 +44,7 @@ set(PUBLIC_HEADERS
TextMessage.h
BaseCategory.h
ConsoleStreamRedirect.h
OperationalCategories.h
)
OperationalCategories.h)

target_compile_definitions(${TARGET} PRIVATE MESSAGING_EXPORTS)

Expand Down
45 changes: 45 additions & 0 deletions Source/messaging/ConsoleStreamRedirect.cpp
Original file line number Diff line number Diff line change
@@ -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<StandardOut>(::_fileno(stdout))
#else
: Core::TextStreamRedirectType<StandardOut>(STDOUT_FILENO)
#endif
{
}

ConsoleStandardError::ConsoleStandardError()
#ifdef __WINDOWS__
: Core::TextStreamRedirectType<StandardError>(::_fileno(stderr))
#else
: Core::TextStreamRedirectType<StandardError>(STDERR_FILENO)
#endif
{
}

}
}
18 changes: 4 additions & 14 deletions Source/messaging/ConsoleStreamRedirect.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Module.h"
#include "Control.h"
#include "OperationalCategories.h"

Expand Down Expand Up @@ -60,13 +61,7 @@ namespace WPEFramework {
ConsoleStandardOut& operator=(const ConsoleStandardOut&) = delete;

private:
ConsoleStandardOut()
#ifdef __WINDOWS__
: Core::TextStreamRedirectType<StandardOut>(::_fileno(stdout)) {
#else
: Core::TextStreamRedirectType<StandardOut>(STDOUT_FILENO) {
#endif
}
ConsoleStandardOut();

public:
~ConsoleStandardOut() = default;
Expand All @@ -87,16 +82,11 @@ namespace WPEFramework {
ConsoleStandardError& operator=(const ConsoleStandardError&) = delete;

private:
ConsoleStandardError()
#ifdef __WINDOWS__
: Core::TextStreamRedirectType<StandardError>(::_fileno(stderr)) {
#else
: Core::TextStreamRedirectType<StandardError>(STDERR_FILENO) {
#endif
}
ConsoleStandardError();

public:
~ConsoleStandardError() = default;

static ConsoleStandardError& Instance()
{
static ConsoleStandardError singleton;
Expand Down
3 changes: 3 additions & 0 deletions Source/messaging/messaging.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@
<ClInclude Include="MessageUnit.h" />
<ClInclude Include="Module.h" />
<ClInclude Include="ConsoleStreamRedirect.h" />
<ClInclude Include="OperationalCategories.h" />
<ClInclude Include="TextMessage.h" />
<ClInclude Include="TraceCategories.h" />
<ClInclude Include="TraceControl.h" />
<ClInclude Include="TraceFactory.h" />
<ClInclude Include="messaging.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ConsoleStreamRedirect.cpp" />
<ClCompile Include="DirectOutput.cpp" />
<ClCompile Include="Logging.cpp" />
<ClCompile Include="MessageClient.cpp" />
<ClCompile Include="MessageUnit.cpp" />
<ClCompile Include="Module.cpp" />
<ClCompile Include="OperationalCategories.cpp" />
<ClCompile Include="TraceCategories.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
Expand Down
9 changes: 9 additions & 0 deletions Source/messaging/messaging.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<ClInclude Include="ConsoleStreamRedirect.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OperationalCategories.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Logging.cpp">
Expand All @@ -80,5 +83,11 @@
<ClCompile Include="DirectOutput.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="OperationalCategories.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ConsoleStreamRedirect.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

0 comments on commit 20036df

Please sign in to comment.