Skip to content

iox::posix::FileLock🔗

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 <file_lock.hpp>

Inherits from DesignPattern::Creation< FileLock, FileLockError >

Public Types🔗

Name
using cxx::string< 250 > FileName_t
using cxx::string< 1024 > PathName_t

Public Functions🔗

Name
FileLock(const FileLock & )
FileLock & operator=(const FileLock & )
FileLock(FileLock && rhs)
FileLock & operator=(FileLock && rhs)
~FileLock()

Public Attributes🔗

Name
constexpr int32_t ERROR_CODE
constexpr int32_t INVALID_FD

Friends🔗

Name
class DesignPattern::Creation< FileLock, FileLockError >

Additional inherited members🔗

Public Types inherited from DesignPattern::Creation< FileLock, FileLockError >

Name
using Creation< DerivedClass, ErrorType > CreationPattern_t
using iox::cxx::expected< DerivedClass, ErrorType > result_t
using ErrorType errorType_t

Public Functions inherited from DesignPattern::Creation< FileLock, FileLockError >

Name
template \<typename... Targs>
result_t
create(Targs &&... args)
factory method which guarantees that either a working object is produced or an error value describing the error during construction
result_t verify(DerivedClass && newObject)
verifies if a class was created successfully
template \<typename... Targs>
iox::cxx::expected< ErrorType >
placementCreate(void *const memory, Targs &&... args)
factory method which guarantees that either a working object is produced or an error value describing the error during construction
Creation() =default
Creation(Creation && rhs)
Creation(const Creation & rhs) =default
bool isInitialized() const
returns true if the object was constructed successfully, otherwise false

Protected Attributes inherited from DesignPattern::Creation< FileLock, FileLockError >

Name
bool m_isInitialized
ErrorType m_errorValue

Detailed Description🔗

class iox::posix::FileLock;

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)

iox::posix::FileLock::create(nameOfmyLock)
    .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;
        }
    });

Public Types Documentation🔗

using FileName_t🔗

using iox::posix::FileLock::FileName_t =  cxx::string<250>;

using PathName_t🔗

using iox::posix::FileLock::PathName_t =  cxx::string<1024>;

Public Functions Documentation🔗

function FileLock🔗

FileLock(
    const FileLock & 
)

function operator=🔗

FileLock & operator=(
    const FileLock & 
)

function FileLock🔗

FileLock(
    FileLock && rhs
)

function operator=🔗

FileLock & operator=(
    FileLock && rhs
)

function ~FileLock🔗

~FileLock()

Public Attributes Documentation🔗

variable ERROR_CODE🔗

static constexpr int32_t ERROR_CODE = -1;

variable INVALID_FD🔗

static constexpr int32_t INVALID_FD = -1;

Friends🔗

friend DesignPattern::Creation< FileLock, FileLockError >🔗

friend class DesignPattern::Creation< FileLock, FileLockError >;

Updated on 31 May 2022 at 15:29:15 CEST