F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Memory.hpp
Go to the documentation of this file.
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
10namespace Os {
11
13class MemoryHandle {};
14
17 public:
20
22 MemoryInterface() = default;
24 virtual ~MemoryInterface() = default;
25
27 MemoryInterface(const MemoryInterface& other) = delete;
28
30 virtual MemoryInterface& operator=(const MemoryInterface& other) = delete;
31
36 virtual Status _getUsage(Usage& memory_usage) = 0;
37
40 virtual MemoryHandle* getHandle() = 0;
41
43 static MemoryInterface* getDelegate(MemoryHandleStorage& aligned_new_memory);
44};
45
47class Memory final : public MemoryInterface {
48 public:
50 Memory();
51
53 ~Memory() final;
54
56 Memory(const MemoryInterface& other) = delete;
57
59 Memory(const MemoryInterface* other) = delete;
60
62 MemoryInterface& operator=(const MemoryInterface& other) override = delete;
63
64 //-----------------------------------------------------------------------------
65 // Interface methods
66 //-----------------------------------------------------------------------------
67 public:
68
70 static void init();
71
73 static Memory& getSingleton();
74
75 //-----------------------------------------------------------------------------
76 // Delegating methods
77 //-----------------------------------------------------------------------------
78
85 Status _getUsage(Usage& memory_usage) override;
86
87
90 MemoryHandle* getHandle() override;
91
92 //-----------------------------------------------------------------------------
93 // Static interface (singleton) methods
94 //-----------------------------------------------------------------------------
95
102 static Status getUsage(Usage& memory);
103
104 private:
105
106 // This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is
107 // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
108 // the byte-array here and set `handle` to that address for storage.
109 alignas(FW_HANDLE_ALIGNMENT) MemoryHandleStorage m_handle_storage;
110 MemoryInterface& m_delegate;
111};
112}
113#endif //OS_CONDITION_HPP_
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition FpConfig.h:440
U8 MemoryHandleStorage[FW_MEMORY_HANDLE_MAX_SIZE]
Definition Os.hpp:19
Memory variable handle parent.
Definition Memory.hpp:13
memory implementation
Definition Memory.hpp:47
Memory()
default constructor
Definition Memory.cpp:10
MemoryInterface & operator=(const MemoryInterface &other) override=delete
assignment operator is forbidden
Memory(const MemoryInterface *other)=delete
copy constructor is forbidden
Memory(const MemoryInterface &other)=delete
copy constructor is forbidden
static Status getUsage(Usage &memory)
get system memory usage
Definition Memory.cpp:30
static void init()
initialize the singleton
Definition Memory.cpp:16
~Memory() final
default virtual destructor
Definition Memory.cpp:12
MemoryHandle * getHandle() override
return the underlying memory handle (implementation specific).
Definition Memory.cpp:34
Status _getUsage(Usage &memory_usage) override
get system memory usage
Definition Memory.cpp:25
static Memory & getSingleton()
return singleton
Definition Memory.cpp:20
interface for memory implementation
Definition Memory.hpp:16
virtual MemoryInterface & operator=(const MemoryInterface &other)=delete
assignment operator is forbidden
virtual MemoryHandle * getHandle()=0
return the underlying memory handle (implementation specific).
virtual Status _getUsage(Usage &memory_usage)=0
get system memory usage
MemoryInterface(const MemoryInterface &other)=delete
copy constructor is forbidden
virtual ~MemoryInterface()=default
Default destructor.
MemoryInterface()=default
Default constructor.
static MemoryInterface * getDelegate(MemoryHandleStorage &aligned_new_memory)
provide a pointer to a Mutex delegate object
Status
Generic OK/ERROR status.
Definition Os.hpp:25
Generic used/total struct.
Definition Os.hpp:31