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