libcamera v0.2.0
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
libcamera::SharedMemObject< T > Class Template Reference

Helper class for allocating objects in shared memory. More...

Public Member Functions

template<class... Args>
 SharedMemObject (const std::string &name, Args &&...args)
 Contstructor for the SharedMemObject.
 
 SharedMemObject (SharedMemObject< T > &&rhs)
 Move constructor for SharedMemObject.
 
 ~SharedMemObject ()
 SharedMemObject destructor.
 
SharedMemObject< T > & operator= (SharedMemObject< T > &&rhs)
 Operator= for SharedMemObject.
 
T * operator-> ()
 Operator-> for SharedMemObject.
 
const T * operator-> () const
 Operator-> for SharedMemObject.
 
T & operator* ()
 Operator* for SharedMemObject.
 
const T & operator* () const
 Operator* for SharedMemObject.
 
const SharedFDfd () const
 Gets the file descriptor for the underlaying storage file.
 
 operator bool () const
 Operator bool() for SharedMemObject.
 

Static Public Attributes

static constexpr std::size_t SIZE = sizeof(T)
 The size of the object that is going to be stored here.
 

Detailed Description

template<class T>
class libcamera::SharedMemObject< T >

Helper class for allocating objects in shared memory.

Memory is allocated and exposed as a SharedFD for use across IPC boundaries.

Given the type of the object to be created in shared memory and the arguments to pass to this object's constructor, SharedMemObject allocates the shared memory of the size of the object and constructs the object in this memory. To check that the SharedMemObject was created successfully, one needs to verify that the underlying SharedFD (the reference to it is returned by SharedMemObject::fd() member function) is valid. The object created in the shared memory can be accessed using the SharedMemObject::operator*() indirection operator. Its members can be accessed with the SharedMemObject::operator->() member of pointer operator.

To access the object from another process the SharedFD should be passed to that process, and the shared memory should be mapped by calling mmap().

A single memfd is created for every SharedMemObject. If there is a need to allocate a large number of objects in shared memory, these objects should be grouped into a single large object to keep the number of created memfd's reasonably small.

Constructor & Destructor Documentation

◆ SharedMemObject() [1/2]

template<class T >
template<class... Args>
libcamera::SharedMemObject< T >::SharedMemObject ( const std::string &  name,
Args &&...  args 
)
inline

Contstructor for the SharedMemObject.

Parameters
[in]nameName of the SharedMemObject
[in]argsArgs to pass to the constructor of the object in shared memory

◆ SharedMemObject() [2/2]

template<class T >
libcamera::SharedMemObject< T >::SharedMemObject ( SharedMemObject< T > &&  rhs)
inline

Move constructor for SharedMemObject.

Parameters
[in]rhsThe object to move

◆ ~SharedMemObject()

template<class T >
libcamera::SharedMemObject< T >::~SharedMemObject ( )
inline

SharedMemObject destructor.

Destroys the object created in the shared memory and then unmaps the shared memory. Decrements the shared memory descriptor use count.

Member Function Documentation

◆ fd()

template<class T >
libcamera::SharedMemObject< T >::fd ( ) const
inline

Gets the file descriptor for the underlaying storage file.

Returns
The shared memory file descriptor (as SharedFD)

◆ operator bool()

template<class T >
libcamera::SharedMemObject< T >::operator bool ( ) const
inlineexplicit

Operator bool() for SharedMemObject.

Returns
True if the object was created OK in the shared memory, false otherwise

◆ operator*() [1/2]

template<class T >
libcamera::SharedMemObject< T >::operator* ( )
inline

Operator* for SharedMemObject.

Returns
The reference to the object

◆ operator*() [2/2]

template<class T >
const T & libcamera::SharedMemObject< T >::operator* ( ) const
inline

Operator* for SharedMemObject.

Returns
Const reference to the object

◆ operator->() [1/2]

template<class T >
libcamera::SharedMemObject< T >::operator-> ( )
inline

Operator-> for SharedMemObject.

Returns
The pointer to the object

◆ operator->() [2/2]

template<class T >
const T * libcamera::SharedMemObject< T >::operator-> ( ) const
inline

Operator-> for SharedMemObject.

Returns
The pointer to the const object

◆ operator=()

template<class T >
libcamera::SharedMemObject< T >::operator= ( SharedMemObject< T > &&  rhs)
inline

Operator= for SharedMemObject.

Parameters
[in]rhsThe SharedMemObject object to take the data from

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