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