GCC Code Coverage Report


Directory: ./
File: Memory.hpp
Date: 2026-09-03 22:13:09
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 2 2 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // ======================================================================
2 // \title Os/Memory.hpp
3 // \brief common function definitions for Os::Memory
4 // ======================================================================
5 #include "Os/Os.hpp"
6
7 #ifndef OS_MEMORY_HPP_
8 #define OS_MEMORY_HPP_
9
10 namespace Os {
11
12 //! \brief Memory variable handle parent
13 class MemoryHandle {};
14
15 //! \brief interface for memory implementation
16 class MemoryInterface {
17 public:
18 using Status = Os::Generic::Status;
19 using Usage = Os::Generic::UsedTotal;
20
21 //! Default constructor
22 2 MemoryInterface() = default;
23 //! Default destructor
24 4 virtual ~MemoryInterface() = default;
25
26 //! \brief copy constructor is forbidden
27 MemoryInterface(const MemoryInterface& other) = delete; // NO_CODESONAR (cpp:S3657)
28
29 //! \brief assignment operator is forbidden
30 virtual MemoryInterface& operator=(const MemoryInterface& other) = delete;
31
32 //! \brief get system memory usage
33 //!
34 //! \param memory_usage: (output) data structure used to store memory usage
35 //! \return: ERROR when error occurs, OK otherwise.
36 virtual Status _getUsage(Usage& memory_usage) = 0;
37
38 //! \brief return the underlying memory handle (implementation specific).
39 //! \return internal task handle representation
40 virtual MemoryHandle* getHandle() = 0;
41
42 //! \brief provide a pointer to a Mutex delegate object
43 static MemoryInterface* getDelegate(MemoryHandleStorage& aligned_new_memory);
44 };
45
46 //! \brief memory implementation
47 class Memory final : public MemoryInterface {
48 public:
49 //! \brief default constructor
50 Memory();
51
52 //! \brief default virtual destructor
53 ~Memory() final;
54
55 //! \brief copy constructor is forbidden
56 Memory(const MemoryInterface& other) = delete;
57
58 //! \brief copy constructor is forbidden
59 Memory(const MemoryInterface* other) = delete;
60
61 //! \brief assignment operator is forbidden
62 MemoryInterface& operator=(const MemoryInterface& other) override = delete;
63
64 //-----------------------------------------------------------------------------
65 // Interface methods
66 //-----------------------------------------------------------------------------
67 public:
68 //! \brief initialize the singleton
69 static void init();
70
71 //! \brief return singleton
72 static Memory& getSingleton();
73
74 //-----------------------------------------------------------------------------
75 // Delegating methods
76 //-----------------------------------------------------------------------------
77
78 //! \brief get system memory usage
79 //!
80 //! This method delegates to the underlying implementation.
81 //!
82 //! \param memory_usage: (output) data structure used to store memory usage
83 //! \return: ERROR when error occurs, OK otherwise.
84 Status _getUsage(Usage& memory_usage) override;
85
86 //! \brief return the underlying memory handle (implementation specific).
87 //! \return internal task handle representation
88 MemoryHandle* getHandle() override;
89
90 //-----------------------------------------------------------------------------
91 // Static interface (singleton) methods
92 //-----------------------------------------------------------------------------
93
94 //! \brief get system memory usage
95 //!
96 //! This method wraps delegates to the underlying implementation.
97 //!
98 //! \param memory_usage: (output) data structure used to store memory usage
99 //! \return: ERROR when error occurs, OK otherwise.
100 static Status getUsage(Usage& memory);
101
102 private:
103 // This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is
104 // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
105 // the byte-array here and set `handle` to that address for storage.
106 alignas(FW_HANDLE_ALIGNMENT) MemoryHandleStorage m_handle_storage; //!< Storage for aligned data
107 MemoryInterface& m_delegate; //!< Delegate for the real implementation
108 };
109 } // namespace Os
110 #endif // OS_CONDITION_HPP_
111