GCC Code Coverage Report


Directory: ./
File: Os/Console.cpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 24 42 57.1%
Functions: 6 11 54.5%
Branches: 7 17 41.2%

Line Branch Exec Source
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 {
9 1 Console::Console()
10 : ConsoleInterface(),
11 Fw::Logger(),
12
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 m_handle_storage(),
13
1/1
✓ Branch 3 taken 1 times.
2 m_delegate(*ConsoleInterface::getDelegate(m_handle_storage)) {}
14
15 2 Console::~Console() {
16 2 FW_ASSERT(&this->m_delegate == reinterpret_cast<ConsoleInterface*>(&this->m_handle_storage[0]));
17 2 m_delegate.~ConsoleInterface();
18 2 }
19
20 Console::Console(const Console& other)
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
25 Console& Console::operator=(const Console& other) {
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 464 void Console::writeMessage(const CHAR* message, const FwSizeType size) {
34 464 FW_ASSERT(&this->m_delegate == reinterpret_cast<ConsoleInterface*>(&this->m_handle_storage));
35 464 FW_ASSERT(message != nullptr || size == 0);
36 464 this->m_delegate.writeMessage(message, size);
37 464 }
38
39 464 void Console::writeMessage(const Fw::ConstStringBase& message) {
40 464 this->writeMessage(message.toChar(), message.length());
41 464 }
42
43 ConsoleHandle* Console::getHandle() {
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::ConstStringBase& message) {
53 Console::getSingleton().writeMessage(message.toChar(), message.length());
54 }
55
56 1 void Console::init() {
57 // Force trigger on the fly singleton setup
58 1 (void)Console::getSingleton();
59 1 }
60
61 1 Console& Console::getSingleton() {
62
3/7
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
1 static Console s_singleton;
63 // Registration happens once: re-registering on every access would silently replace a
64 // logger the project registered after the console singleton was first used
65 static bool s_registered = false;
66
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (not s_registered) {
67 1 s_registered = true;
68 1 Fw::Logger::registerLogger(&s_singleton);
69 }
70 1 return s_singleton;
71 }
72 } // namespace Os
73