| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Posix/Console.hpp | ||
| 3 | // \brief posix implementation for Os::Console, header and test definitions | ||
| 4 | // ====================================================================== | ||
| 5 | #include <Os/Console.hpp> | ||
| 6 | #include <cstdio> | ||
| 7 | #ifndef OS_POSIX_Console_HPP | ||
| 8 | #define OS_POSIX_Console_HPP | ||
| 9 | |||
| 10 | namespace Os { | ||
| 11 | namespace Posix { | ||
| 12 | namespace Console { | ||
| 13 | |||
| 14 | //! ConsoleHandle class definition for posix implementations. | ||
| 15 | //! | ||
| 16 | struct PosixConsoleHandle : public ConsoleHandle { | ||
| 17 | //! Posix console file descriptor | ||
| 18 | FILE* m_file_descriptor = stdout; | ||
| 19 | }; | ||
| 20 | |||
| 21 | //! \brief posix implementation of Os::ConsoleInterface | ||
| 22 | //! | ||
| 23 | //! Posix implementation of `ConsoleInterface` for use as a delegate class handling posix console operations. Posix | ||
| 24 | //! consoles write to either standard out or standard error. The default file descriptor used is standard out. This may | ||
| 25 | //! be changed by calling `setOutputStream`. | ||
| 26 | //! | ||
| 27 | class PosixConsole : public ConsoleInterface { | ||
| 28 | public: | ||
| 29 | //! Stream selection enumeration | ||
| 30 | enum Stream { | ||
| 31 | STANDARD_OUT = 0, //!< Use standard output stream | ||
| 32 | STANDARD_ERROR = 1 //!< Use standard error stream | ||
| 33 | }; | ||
| 34 | //! \brief constructor | ||
| 35 | //! | ||
| 36 | 10 | PosixConsole() = default; | |
| 37 | |||
| 38 | //! \brief copy constructor | ||
| 39 | ✗ | PosixConsole(const PosixConsole& other) = default; | |
| 40 | |||
| 41 | //! \brief assignment operator that copies the internal representation | ||
| 42 | PosixConsole& operator=(const PosixConsole& other) = default; | ||
| 43 | |||
| 44 | //! \brief destructor | ||
| 45 | //! | ||
| 46 | 20 | ~PosixConsole() override = default; | |
| 47 | |||
| 48 | // ------------------------------------ | ||
| 49 | // Functions overrides | ||
| 50 | // ------------------------------------ | ||
| 51 | |||
| 52 | //! \brief write message to console | ||
| 53 | //! | ||
| 54 | //! Write a message to the console with a bounded size. This will use the active file descriptor as the output | ||
| 55 | //! destination. | ||
| 56 | //! | ||
| 57 | //! \param message: raw message to write | ||
| 58 | //! \param size: size of the message to write to the console | ||
| 59 | void writeMessage(const CHAR* message, const FwSizeType size) override; | ||
| 60 | |||
| 61 | //! \brief returns the raw console handle | ||
| 62 | //! | ||
| 63 | //! Gets the raw console handle from the implementation. Note: users must include the implementation specific | ||
| 64 | //! header to make any real use of this handle. Otherwise it will be as an opaque type. | ||
| 65 | //! | ||
| 66 | //! \return raw console handle | ||
| 67 | //! | ||
| 68 | ConsoleHandle* getHandle() override; | ||
| 69 | |||
| 70 | //! \brief select the output stream | ||
| 71 | //! | ||
| 72 | //! There are two streams defined: standard out, and standard error. This allows users of the posix log | ||
| 73 | //! implementation to chose which stream to use. | ||
| 74 | void setOutputStream(Stream stream); | ||
| 75 | |||
| 76 | private: | ||
| 77 | //! File handle for PosixFile | ||
| 78 | PosixConsoleHandle m_handle; | ||
| 79 | }; | ||
| 80 | } // namespace Console | ||
| 81 | } // namespace Posix | ||
| 82 | } // namespace Os | ||
| 83 | |||
| 84 | #endif // OS_POSIX_Console_HPP | ||
| 85 |