F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Console.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Console.hpp
3 // \brief common function definitions for Os::Console
4 // ======================================================================
5 #ifndef Os_Console_hpp_
6 #define Os_Console_hpp_
7 
8 #include <FpConfig.hpp>
9 #include <Fw/Logger/Logger.hpp>
10 #include <Os/Console.hpp>
11 #include <Os/Os.hpp>
12 
13 namespace Os {
15  struct ConsoleHandle {
16  };
17 
18  // \brief Interface defining the properties of the console
20  public:
22  ConsoleInterface() = default;
23 
25  virtual ~ConsoleInterface() = default;
26 
33  virtual void writeMessage(const CHAR *message, const FwSizeType size) = 0;
34 
42  virtual ConsoleHandle *getHandle() = 0;
43 
65  static ConsoleInterface* getDelegate(ConsoleHandleStorage& aligned_placement_new_memory, const ConsoleInterface* to_copy=nullptr);
66  };
67 
68  class Console : public ConsoleInterface, public Fw::Logger {
69  public:
71  Console();
72 
74  ~Console();
75 
77  Console(const Console& other);
78 
80  Console& operator=(const Console& other);
81 
89  void writeMessage(const CHAR *message, const FwSizeType size) override;
90 
96  void writeMessage(const Fw::StringBase& message) override;
97 
105  ConsoleHandle *getHandle() override;
106 
112  static void write(const Fw::StringBase& message);
113 
121  static void write(const CHAR *message, const FwSizeType size);
122 
124  static void init();
125 
128  static Console& getSingleton();
129 
130  private:
131  // This section is used to store the implementation-defined console handle. To Os::Console and fprime, this type
132  // is opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle
133  // in the byte-array here and set `handle` to that address for storage.
134  alignas(FW_HANDLE_ALIGNMENT) ConsoleHandleStorage m_handle_storage; // Storage for the delegate
135  ConsoleInterface &m_delegate;
136  };
137 }
138 
139 #endif
char CHAR
Definition: BasicTypes.h:32
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition: FpConfig.h:440
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
C++-compatible configuration header for fprime configuration.
U8 ConsoleHandleStorage[FW_CONSOLE_HANDLE_MAX_SIZE]
Definition: Os.hpp:11
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
ConsoleInterface()=default
Default constructor.
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