libcluon  0.0.148
cluon::SharedMemory Class Reference

#include <SharedMemory.hpp>

Public Member Functions

 SharedMemory (const std::string &name, uint32_t size=0) noexcept
 
 ~SharedMemory () noexcept
 
bool isLocked () const noexcept
 
void lock () noexcept
 
void unlock () noexcept
 
void wait () noexcept
 
void notifyAll () noexcept
 
bool setTimeStamp (const cluon::data::TimeStamp &ts) noexcept
 
std::pair< bool, cluon::data::TimeStamp > getTimeStamp () noexcept
 
bool valid () noexcept
 
char * data () noexcept
 
uint32_t size () const noexcept
 
const std::string name () const noexcept
 

Constructor & Destructor Documentation

◆ SharedMemory()

cluon::SharedMemory::SharedMemory ( const std::string &  name,
uint32_t  size = 0 
)
noexcept

Constructor.

Parameters
nameName of the shared memory area; must start with / and must not be longer than NAME_MAX (255) on POSIX or PATH_MAX on WIN32. If the name is missing a leading '/' or is longer than 255, it will be adjusted accordingly.
sizeof the shared memory area to create; if size is 0, the class tries to attach to an existing area.

◆ ~SharedMemory()

cluon::SharedMemory::~SharedMemory ( )
noexcept

Member Function Documentation

◆ data()

char * cluon::SharedMemory::data ( )
noexcept
Returns
Pointer to the raw shared memory or nullptr in case of invalid shared memory.

◆ getTimeStamp()

std::pair< bool, cluon::data::TimeStamp > cluon::SharedMemory::getTimeStamp ( )
noexcept

This method returns the sample time stamp.

This method is only allowed when the shared memory is locked.

Returns
(true, sample time stamp) or (false, 0) in case if the shared memory was not locked.

References retVal.

◆ isLocked()

bool cluon::SharedMemory::isLocked ( ) const
noexcept
Returns
true when this shared memory area is locked.

◆ lock()

void cluon::SharedMemory::lock ( )
noexcept

This method locks the shared memory area.

◆ name()

const std::string cluon::SharedMemory::name ( ) const
noexcept
Returns
Name the shared memory area.

References retVal, and semun::val.

◆ notifyAll()

void cluon::SharedMemory::notifyAll ( )
noexcept

This method notifies all threads waiting on the shared condition.

◆ setTimeStamp()

bool cluon::SharedMemory::setTimeStamp ( const cluon::data::TimeStamp &  ts)
noexcept

This method sets the time stamp that can be used to express the sample time stamp of the data in residing in the shared memory.

This method is only allowed when the shared memory is locked.

Parameters
tsTimeStamp.
Returns
true if the timestamp could set; false if the shared memory was not locked.

References retVal.

◆ size()

uint32_t cluon::SharedMemory::size ( ) const
noexcept
Returns
The size of the shared memory area.

◆ unlock()

void cluon::SharedMemory::unlock ( )
noexcept

This method unlocks the shared memory area.

◆ valid()

bool cluon::SharedMemory::valid ( )
noexcept
Returns
True if the shared memory area is existing and usable.

◆ wait()

void cluon::SharedMemory::wait ( )
noexcept

This method waits for being notified from the shared condition.