summaryrefslogtreecommitdiff
path: root/lib/NativeSharedMemory.hpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-10-09 14:12:49 +0200
committerChristoph Berg <myon@debian.org>2026-10-09 14:12:49 +0200
commit76956486fa7ef52a51d4e56df1e13a9f19a6c93c (patch)
treefe0c394439fdc167d1970372e8998874090854dd /lib/NativeSharedMemory.hpp
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
parentffc62c792c9a5196cb4ce7a353287dfe20db6524 (diff)
Update upstream source from tag 'upstream/3.3.0_beta1+dfsg'
Update to upstream version '3.3.0~beta1+dfsg' with Debian dir 85037bbb9376721108594b59b54ead82ac6924a3
Diffstat (limited to 'lib/NativeSharedMemory.hpp')
-rw-r--r--lib/NativeSharedMemory.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/NativeSharedMemory.hpp b/lib/NativeSharedMemory.hpp
new file mode 100644
index 00000000..7c8d25b5
--- /dev/null
+++ b/lib/NativeSharedMemory.hpp
@@ -0,0 +1,44 @@
+#ifndef WSJTX_NATIVE_SHARED_MEMORY_HPP
+#define WSJTX_NATIVE_SHARED_MEMORY_HPP
+
+#include <cstddef>
+#include <string>
+
+class NativeSharedMemory final
+{
+public:
+ NativeSharedMemory () = default;
+ ~NativeSharedMemory ();
+ NativeSharedMemory (NativeSharedMemory const&) = delete;
+ NativeSharedMemory& operator= (NativeSharedMemory const&) = delete;
+
+ bool create (std::string const& name, std::size_t bytes);
+ bool attach (std::string const& name);
+ bool detach () noexcept;
+ static bool remove (std::string const& name, std::string * error = nullptr);
+
+ void * data () const noexcept { return data_; }
+ std::size_t size () const noexcept { return size_; }
+ bool isAttached () const noexcept { return data_ != nullptr; }
+ bool alreadyExists () const noexcept;
+ bool notFound () const noexcept;
+ std::string errorString () const;
+
+private:
+ bool begin (std::string const& name);
+ bool fail (char const * operation, unsigned long code) noexcept;
+
+ std::string name_;
+ void * data_ {nullptr};
+ std::size_t size_ {0};
+ bool owner_ {false};
+ char const * operation_ {nullptr};
+ unsigned long error_ {0};
+#ifdef _WIN32
+ void * handle_ {nullptr};
+#else
+ int descriptor_ {-1};
+#endif
+};
+
+#endif