F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Console.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title Os/Posix/Console.cpp
3// \brief posix implementation for Os::Console
4// ======================================================================
6#include <Fw/Types/Assert.hpp>
7#include <limits>
8#include <cstdio>
9
10namespace Os {
11namespace Posix {
12namespace Console {
13
14
15void PosixConsole::writeMessage(const CHAR *message, const FwSizeType size) {
16 // size_t is defined as different sizes on different platforms. Since FwSizeType is likely larger than size_t
17 // on these platforms, and the user is unlikely to console-log more than size_t-max data, we cap the total
18 // size at the limit of the interface.
19 FwSizeType capped_size = (size <= std::numeric_limits<size_t>::max()) ? size : std::numeric_limits<size_t>::max();
20 if (message != nullptr) {
21 (void)::fwrite(message, sizeof(CHAR), static_cast<size_t>(capped_size), this->m_handle.m_file_descriptor);
22 (void)::fflush(this->m_handle.m_file_descriptor);
23 }
24}
25
27 return &this->m_handle;
28}
29
30void PosixConsole ::setOutputStream(Stream stream) {
31 switch (stream) {
32 case STANDARD_OUT:
33 this->m_handle.m_file_descriptor = stdout;
34 break;
35 case STANDARD_ERROR:
36 this->m_handle.m_file_descriptor = stderr;
37 break;
38 default:
39 FW_ASSERT(0);
40 break;
41 }
42}
43
44
45} // namespace Console
46} // namespace Posix
47} // namespace Os
#define FW_ASSERT(...)
Definition Assert.hpp:14
char CHAR
Definition BasicTypes.h:32
PlatformSizeType FwSizeType
Definition FpConfig.h:35
Stream
Stream selection enumeration.
Definition Console.hpp:30
void writeMessage(const CHAR *message, const FwSizeType size) override
write message to console
Definition Console.cpp:15
ConsoleHandle * getHandle() override
returns the raw console handle
Definition Console.cpp:26
Base class for storing implementation specific handle information.
Definition Console.hpp:15
FILE * m_file_descriptor
Posix console file descriptor.
Definition Console.hpp:18