Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
contur::SharedMemory Class Referencefinal

Named shared-memory IPC channel. More...

#include <shared_memory.h>

Inheritance diagram for contur::SharedMemory:

Public Member Functions

 SharedMemory (std::string name, std::size_t bytes)
 Creates a named shared-memory region.
 ~SharedMemory () override
 Destroys shared-memory channel.
 SharedMemory (const SharedMemory &)=delete
 Copy construction is disabled.
SharedMemoryoperator= (const SharedMemory &)=delete
 Copy assignment is disabled.
 SharedMemory (SharedMemory &&) noexcept
 Move-constructs shared-memory state.
SharedMemoryoperator= (SharedMemory &&) noexcept
 Move-assigns shared-memory state.
Result< std::size_t > write (std::span< const std::byte > data) override
 Writes bytes into the beginning of the shared region.
Result< std::size_t > read (std::span< std::byte > buffer) override
 Reads bytes from the beginning of the shared region.
void close () override
 Closes the region, clears attachments, and resets data.
bool isOpen () const noexcept override
 Returns whether the region is open.
std::string_view name () const noexcept override
 Region name.
Result< void > attach (ProcessId pid)
 Attaches a process to this region.
Result< void > detach (ProcessId pid)
 Detaches a process from this region.
bool isAttached (ProcessId pid) const noexcept
 Returns true if process is attached.
std::size_t attachedCount () const noexcept
 Number of attached processes.
std::size_t size () const noexcept
 Region size in bytes.
Public Member Functions inherited from contur::IIpcChannel
virtual ~IIpcChannel ()=default

Private Attributes

std::unique_ptr< Impl > impl_

Detailed Description

Named shared-memory IPC channel.

SharedMemory exposes a fixed-size byte region that can be attached by multiple processes. Attach/detach tracking is managed internally.

Definition at line 19 of file shared_memory.h.

Constructor & Destructor Documentation

◆ SharedMemory() [1/3]

contur::SharedMemory::SharedMemory ( std::string name,
std::size_t bytes )
explicit

Creates a named shared-memory region.

Parameters
nameChannel name.
bytesSize of memory region in bytes.

References name().

Referenced by operator=(), operator=(), SharedMemory(), and SharedMemory().

◆ ~SharedMemory()

contur::SharedMemory::~SharedMemory ( )
override

Destroys shared-memory channel.

◆ SharedMemory() [2/3]

contur::SharedMemory::SharedMemory ( const SharedMemory & )
delete

Copy construction is disabled.

References SharedMemory().

◆ SharedMemory() [3/3]

contur::SharedMemory::SharedMemory ( SharedMemory && )
noexcept

Move-constructs shared-memory state.

References SharedMemory().

Member Function Documentation

◆ attach()

Result< void > contur::SharedMemory::attach ( ProcessId pid)
nodiscard

Attaches a process to this region.

Parameters
pidProcess ID.
Returns
Ok on success, or InvalidPid/InvalidState.

References attach().

Referenced by attach().

◆ attachedCount()

std::size_t contur::SharedMemory::attachedCount ( ) const
nodiscardnoexcept

Number of attached processes.

References attachedCount().

Referenced by attachedCount().

◆ close()

void contur::SharedMemory::close ( )
overridevirtual

Closes the region, clears attachments, and resets data.

Implements contur::IIpcChannel.

References close().

Referenced by close().

◆ detach()

Result< void > contur::SharedMemory::detach ( ProcessId pid)
nodiscard

Detaches a process from this region.

Parameters
pidProcess ID.
Returns
Ok on success, or InvalidPid/NotFound.

References detach().

Referenced by detach().

◆ isAttached()

bool contur::SharedMemory::isAttached ( ProcessId pid) const
nodiscardnoexcept

Returns true if process is attached.

References isAttached().

Referenced by isAttached().

◆ isOpen()

bool contur::SharedMemory::isOpen ( ) const
nodiscardoverridevirtualnoexcept

Returns whether the region is open.

Implements contur::IIpcChannel.

References isOpen().

Referenced by isOpen().

◆ name()

std::string_view contur::SharedMemory::name ( ) const
nodiscardoverridevirtualnoexcept

Region name.

Implements contur::IIpcChannel.

References name().

Referenced by name(), and SharedMemory().

◆ operator=() [1/2]

SharedMemory & contur::SharedMemory::operator= ( const SharedMemory & )
delete

Copy assignment is disabled.

References SharedMemory().

◆ operator=() [2/2]

SharedMemory & contur::SharedMemory::operator= ( SharedMemory && )
noexcept

Move-assigns shared-memory state.

References SharedMemory().

◆ read()

Result< std::size_t > contur::SharedMemory::read ( std::span< std::byte > buffer)
nodiscardoverridevirtual

Reads bytes from the beginning of the shared region.

Returns
Number of bytes read (can be partial), or error.

Implements contur::IIpcChannel.

References read().

Referenced by read().

◆ size()

std::size_t contur::SharedMemory::size ( ) const
nodiscardnoexcept

Region size in bytes.

References size().

Referenced by size().

◆ write()

Result< std::size_t > contur::SharedMemory::write ( std::span< const std::byte > data)
nodiscardoverridevirtual

Writes bytes into the beginning of the shared region.

Returns
Number of bytes written (can be partial), or error.

Implements contur::IIpcChannel.

References write().

Referenced by write().

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> contur::SharedMemory::impl_
private

Definition at line 79 of file shared_memory.h.


The documentation for this class was generated from the following file: