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/Console.cpp
3 // \brief common function implementation for Os::Console
4 // ======================================================================
5 #include <Fw/Types/Assert.hpp>
6 #include <Os/Console.hpp>
7 
8 namespace Os {
10  : ConsoleInterface(),
11  Fw::Logger(),
12  m_handle_storage(),
13  m_delegate(*ConsoleInterface::getDelegate(m_handle_storage)) {}
14 
16  FW_ASSERT(&this->m_delegate == reinterpret_cast<ConsoleInterface*>(&this->m_handle_storage[0]));
17  m_delegate.~ConsoleInterface();
18 }
19 
21  : m_handle_storage(), m_delegate(*Console::getDelegate(m_handle_storage, &other.m_delegate)) {
22  FW_ASSERT(&this->m_delegate == reinterpret_cast<Console*>(&this->m_handle_storage[0]));
23 }
24 
26  FW_ASSERT(&this->m_delegate == reinterpret_cast<Console*>(&this->m_handle_storage[0]));
27  if (this != &other) {
28  this->m_delegate = *ConsoleInterface::getDelegate(m_handle_storage, &other.m_delegate);
29  }
30  return *this;
31 }
32 
33 void Console::writeMessage(const CHAR* message, const FwSizeType size) {
34  FW_ASSERT(&this->m_delegate == reinterpret_cast<ConsoleInterface*>(&this->m_handle_storage));
35  FW_ASSERT(message != nullptr || size == 0);
36  this->m_delegate.writeMessage(message, size);
37 }
38 
39 void Console::writeMessage(const Fw::StringBase& message) {
40  this->writeMessage(message.toChar(), message.length());
41 }
42 
44  FW_ASSERT(&this->m_delegate == reinterpret_cast<ConsoleInterface*>(&this->m_handle_storage));
45  return this->m_delegate.getHandle();
46 }
47 
48 void Console::write(const CHAR* message, const FwSizeType size) {
49  Console::getSingleton().writeMessage(message, size);
50 }
51 
52 void Console::write(const Fw::StringBase& message) {
53  Console::getSingleton().writeMessage(message.toChar(), message.length());
54 }
55 
56 void Console::init() {
57  // Force trigger on the fly singleton setup
58  (void)Console::getSingleton();
59 }
60 
62  static Console s_singleton;
63  Fw::Logger::registerLogger(&s_singleton);
64  return s_singleton;
65 }
66 } // namespace Os
static Console & getSingleton()
get a reference to singleton
Definition: Console.cpp:61
PlatformSizeType FwSizeType
static void write(const Fw::StringBase &message)
write message to console
Definition: Console.cpp:52
virtual ~ConsoleInterface()=default
Default destructor.
virtual void writeMessage(const CHAR *message, const FwSizeType size)=0
write message to console
char CHAR
Definition: BasicTypes.h:59
static ConsoleInterface * getDelegate(ConsoleHandleStorage &aligned_placement_new_memory, const ConsoleInterface *to_copy=nullptr)
provide a pointer to a console delegate object
static void registerLogger(Logger *logger)
register a logger implementation
Definition: Logger.cpp:37
virtual ConsoleHandle * getHandle()=0
returns the raw console handle
SizeType length() const
Get length of string.
Definition: StringBase.cpp:121
Base class for storing implementation specific handle information.
Definition: Console.hpp:15
~Console()
Default destructor.
Definition: Console.cpp:15
ConsoleHandle * getHandle() override
returns the raw console handle
Definition: Console.cpp:43
Console & operator=(const Console &other)
assignment operator that copies the internal representation
Definition: Console.cpp:25
Console()
Default constructor.
Definition: Console.cpp:9
#define FW_ASSERT(...)
Definition: Assert.hpp:14
virtual const CHAR * toChar() const =0
void writeMessage(const CHAR *message, const FwSizeType size) override
write message to console
Definition: Console.cpp:33
static void init()
initialize singleton
Definition: Console.cpp:56