HDLC-Daemon
LockGuard Class Reference

Class LockGuard. More...

#include <LockGuard.h>

Public Member Functions

 LockGuard ()
 The constructor of LockGuard objects. More...
 
 ~LockGuard ()
 The destructor of LockGuard objects. More...
 
void Init (std::shared_ptr< SerialPortHandler > a_SerialPortHandler)
 Initializer method to register subsequent objects. More...
 
void AcquireLock ()
 Method to aquire a lock. More...
 
void ReleaseLock ()
 Method to release a lock. More...
 
bool UpdateSerialPortState (size_t a_LockHolders)
 Update the effective lock state of the related serial port. More...
 
bool IsLocked () const
 Query the lock state of the related serial device. More...
 
bool IsLockedBySelf () const
 Query whether the serial device is currently "locked" by the responsible AccessClient entity. More...
 
bool IsLockedByOthers () const
 Query whether the serial device is currently "locked" by at least one other AccessClient entity. More...
 

Detailed Description

Class LockGuard.

This guard object tracks whether a related device attached via serial connections is currently "locked" / suspended or "unlocked" / resumed

Definition at line 35 of file LockGuard.h.

Constructor & Destructor Documentation

LockGuard::LockGuard ( )

The constructor of LockGuard objects.

On creation, the serial port is "unlocked" / resumed

Definition at line 31 of file LockGuard.cpp.

LockGuard::~LockGuard ( )

The destructor of LockGuard objects.

Held locks are automatically released on deletion

Definition at line 43 of file LockGuard.cpp.

Member Function Documentation

void LockGuard::AcquireLock ( )

Method to aquire a lock.

Each ClientAcceptor can aquired a lock only once, subsequent calls have no impact. The serial port handler has a lock counter, so only the first lock attempt will suspend the serial port.

Definition at line 67 of file LockGuard.cpp.

Here is the caller graph for this function:

void LockGuard::Init ( std::shared_ptr< SerialPortHandler a_SerialPortHandler)

Initializer method to register subsequent objects.

Registers the serial port handler object that is not available yet on construction

Parameters
a_SerialPortHandlerthe serial port handler object

Definition at line 55 of file LockGuard.cpp.

Here is the caller graph for this function:

bool LockGuard::IsLocked ( ) const
inline

Query the lock state of the related serial device.

Query the lock state of the related serial device

Returns
bool indicates whether the serial port is currently "locked" / suspended or "unlocked" / resumed

Definition at line 56 of file LockGuard.h.

bool LockGuard::IsLockedByOthers ( ) const
inline

Query whether the serial device is currently "locked" by at least one other AccessClient entity.

Query whether the serial device is currently "locked" by at least one other AccessClient entity

Returns
bool indicates whether the serial port is currently "locked" by at least one other AccessClient entity

Definition at line 72 of file LockGuard.h.

Here is the caller graph for this function:

bool LockGuard::IsLockedBySelf ( ) const
inline

Query whether the serial device is currently "locked" by the responsible AccessClient entity.

Query whether the serial device is currently locked" by the responsible AccessClient entity

Returns
bool indicates whether the serial port is currently "locked" by the responsible AccessClient entity

Definition at line 64 of file LockGuard.h.

Here is the caller graph for this function:

void LockGuard::ReleaseLock ( )

Method to release a lock.

Each ClientAcceptor can release a held lock only once, subsequent calls have no impact. The serial port handler has a lock counter, so it may resume after this call, but this happens only if this was the last lock.

Definition at line 80 of file LockGuard.cpp.

Here is the caller graph for this function:

bool LockGuard::UpdateSerialPortState ( size_t  a_LockHolders)

Update the effective lock state of the related serial port.

This method gets the amount of locks regarding the related serial port. Thus, this entity is able to derive whether subsequent locks by other entities exist.

Parameters
a_LockHoldersthe amount of locks that currently force the related serial port to be suspended
Returns
bool indicates whether the internal state of this object changed

Definition at line 96 of file LockGuard.cpp.

Here is the caller graph for this function:


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