contur2
Loading...
Searching...
No Matches
shared_memory.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <memory>
7#include <string>
8
9#include "contur/core/types.h"
10
12
13namespace contur {
14
19 class SharedMemory final : public IIpcChannel
20 {
21 public:
25 explicit SharedMemory(std::string name, std::size_t bytes);
26 ~SharedMemory() override;
27
28 SharedMemory(const SharedMemory &) = delete;
31 SharedMemory &operator=(SharedMemory &&) noexcept;
32
35 [[nodiscard]] Result<std::size_t> write(std::span<const std::byte> data) override;
36
39 [[nodiscard]] Result<std::size_t> read(std::span<std::byte> buffer) override;
40
42 void close() override;
43
45 [[nodiscard]] bool isOpen() const noexcept override;
46
48 [[nodiscard]] std::string_view name() const noexcept override;
49
53 [[nodiscard]] Result<void> attach(ProcessId pid);
54
58 [[nodiscard]] Result<void> detach(ProcessId pid);
59
61 [[nodiscard]] bool isAttached(ProcessId pid) const noexcept;
62
64 [[nodiscard]] std::size_t attachedCount() const noexcept;
65
67 [[nodiscard]] std::size_t size() const noexcept;
68
69 private:
70 struct Impl;
71 std::unique_ptr<Impl> impl_;
72 };
73
74} // namespace contur
Common interface for IPC channels.
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
bool isAttached(ProcessId pid) const noexcept
Returns true if process is attached.
void close() override
Closes the region, clears attachments, and resets data.
SharedMemory(const SharedMemory &)=delete
Result< std::size_t > write(std::span< const std::byte > data) override
Writes bytes into the beginning of the shared region.
std::size_t size() const noexcept
Region size in bytes.
Result< std::size_t > read(std::span< std::byte > buffer) override
Reads bytes from the beginning of the shared region.
SharedMemory(SharedMemory &&) noexcept
Result< void > detach(ProcessId pid)
Detaches a process from this region.
bool isOpen() const noexcept override
Returns whether the region is open.
std::size_t attachedCount() const noexcept
Number of attached processes.
std::string_view name() const noexcept override
Region name.
~SharedMemory() override
std::unique_ptr< Impl > impl_
Result< void > attach(ProcessId pid)
Attaches a process to this region.
SharedMemory & operator=(const SharedMemory &)=delete
SharedMemory(std::string name, std::size_t bytes)
Creates a named shared-memory region.
IIpcChannel interface for inter-process communication channels.
Definition block.h:15
std::uint32_t ProcessId
Unique identifier for a process.
Definition types.h:12
Common type aliases, sentinel constants, and forward declarations used throughout the Contur 2 kernel...