iceoryx_hoofs 2.0.3
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
iox::posix::FileLock Class Reference

Posix file lock C++ wrapping class Following RAII, the lock is acquired on creation and released on destruction. Releasing the locks works even if the process crashes with a segfault or using SIGKILL. 'lslocks' can be used to display all system-wide locks (see man page) More...

#include <iceoryx_hoofs/posix_wrapper/file_lock.hpp>

Inheritance diagram for iox::posix::FileLock:
Inheritance graph
[legend]
Collaboration diagram for iox::posix::FileLock:
Collaboration graph
[legend]

Public Types

using FileName_t = cxx::string< FILENAME_LENGTH >
 
using PathName_t = cxx::string< platform::IOX_MAX_PATH_LENGTH >
 
- Public Types inherited from DesignPattern::Creation< FileLock, FileLockError >
using CreationPattern_t = Creation< FileLock, FileLockError >
 
using result_t = iox::cxx::expected< FileLock, FileLockError >
 
using errorType_t = FileLockError
 

Public Member Functions

 FileLock (const FileLock &)=delete
 
FileLockoperator= (const FileLock &)=delete
 
 FileLock (FileLock &&rhs) noexcept
 
FileLockoperator= (FileLock &&rhs) noexcept
 
- Public Member Functions inherited from DesignPattern::Creation< FileLock, FileLockError >
 Creation (Creation &&rhs) noexcept
 
 Creation (const Creation &rhs) noexcept=default
 
Creationoperator= (Creation &&rhs) noexcept
 
Creationoperator= (const Creation &rhs) noexcept=default
 
bool isInitialized () const noexcept
 returns true if the object was constructed successfully, otherwise false
 

Static Public Attributes

static constexpr int32_t ERROR_CODE = -1
 
static constexpr int32_t INVALID_FD = -1
 
static constexpr const char LOCK_FILE_SUFFIX [] = ".lock"
 
static constexpr uint64_t FILENAME_LENGTH
 

Friends

class DesignPattern::Creation< FileLock, FileLockError >
 

Additional Inherited Members

- Static Public Member Functions inherited from DesignPattern::Creation< FileLock, FileLockError >
static result_t create (Targs &&... args) noexcept
 factory method which guarantees that either a working object is produced or an error value describing the error during construction More...
 
static result_t verify (FileLock &&newObject) noexcept
 verifies if a class was created successfully More...
 
static iox::cxx::expected< FileLockError > placementCreate (void *const memory, Targs &&... args) noexcept
 factory method which guarantees that either a working object is produced or an error value describing the error during construction More...
 
- Protected Attributes inherited from DesignPattern::Creation< FileLock, FileLockError >
bool m_isInitialized
 
FileLockError m_errorValue
 

Detailed Description

Posix file lock C++ wrapping class Following RAII, the lock is acquired on creation and released on destruction. Releasing the locks works even if the process crashes with a segfault or using SIGKILL. 'lslocks' can be used to display all system-wide locks (see man page)

.and_then([] { std::cout << "We aquired the lock!" << std::endl; })
.or_else([](auto& error) {
if (error == FileLockError::LOCKED_BY_OTHER_PROCESS)
{
std::cout << "Some other process is running and holds the lock!" << std::endl;
}
});
static result_t create(Targs &&... args) noexcept
factory method which guarantees that either a working object is produced or an error value describing...

Member Data Documentation

◆ FILENAME_LENGTH

constexpr uint64_t iox::posix::FileLock::FILENAME_LENGTH
staticconstexpr
Initial value:
= platform::IOX_MAX_FILENAME_LENGTH
- sizeof(platform::IOX_LOCK_FILE_PATH_PREFIX) / sizeof(char)
- sizeof(LOCK_FILE_SUFFIX) / sizeof(char)

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