libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
sharedmemory.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <cstdint>
14#include <cstddef>
15#include <promeki/namespace.h>
16#include <promeki/string.h>
17#include <promeki/error.h>
18
19PROMEKI_NAMESPACE_BEGIN
20
80class SharedMemory {
81 public:
83 static constexpr uint32_t DefaultPermissions = 0600;
84
86 enum Access {
87 ReadOnly,
88 ReadWrite
89 };
90
95 static bool isSupported();
96
115 static Error unlink(const String &name);
116
118 SharedMemory();
119
121 ~SharedMemory();
122
123 SharedMemory(const SharedMemory &) = delete;
124 SharedMemory &operator=(const SharedMemory &) = delete;
125
127 SharedMemory(SharedMemory &&other) noexcept;
128
130 SharedMemory &operator=(SharedMemory &&other) noexcept;
131
149 Error create(const String &name, size_t size, uint32_t mode = DefaultPermissions,
150 const String &groupName = String());
151
163 Error open(const String &name, Access access = ReadOnly);
164
170 void close();
171
173 bool isValid() const { return _data != nullptr; }
174
176 bool isOwner() const { return _owner; }
177
179 void *data() { return _data; }
180
182 const void *data() const { return _data; }
183
185 size_t size() const { return _size; }
186
188 const String &name() const { return _name; }
189
191 Access access() const { return _access; }
192
193 private:
194 String _name;
195 void *_data = nullptr;
196 size_t _size = 0;
197 intptr_t _handle = -1; // fd (POSIX) or HANDLE (Windows)
198 bool _owner = false;
199 Access _access = ReadOnly;
200};
201
202PROMEKI_NAMESPACE_END
203
204#endif // PROMEKI_ENABLE_CORE