HDLC-Daemon
LockGuard.h
Go to the documentation of this file.
1 
24 #ifndef LOCK_GUARD_H
25 #define LOCK_GUARD_H
26 
27 #include <memory>
28 class SerialPortHandler;
29 
35 class LockGuard {
36 public:
37  // CTOR, DTOR, and initializer
38  LockGuard();
39  ~LockGuard();
40  void Init(std::shared_ptr<SerialPortHandler> a_SerialPortHandler);
41 
42  // Influende the serial port, obtain and release locks, called by a ClientHandler
43  void AcquireLock();
44  void ReleaseLock();
45 
46  // Update the effective state of a serial port
47  bool UpdateSerialPortState(size_t a_LockHolders);
48 
49 
56  bool IsLocked() const { return (m_bLockedBySelf || m_bLockedByOthers); }
57 
64  bool IsLockedBySelf() const { return m_bLockedBySelf; }
65 
72  bool IsLockedByOthers() const { return m_bLockedByOthers; }
73 
74 private:
75  // Members
76  std::shared_ptr<SerialPortHandler> m_SerialPortHandler;
77  bool m_bLockedBySelf;
78  bool m_bLockedByOthers;
79  bool m_bLastLockedBySelf;
80  bool m_bLastLockedByOthers;
81 };
82 
83 #endif // LOCK_GUARD_H
Class LockGuard.
Definition: LockGuard.h:35
~LockGuard()
The destructor of LockGuard objects.
Definition: LockGuard.cpp:43
bool IsLockedByOthers() const
Query whether the serial device is currently "locked" by at least one other AccessClient entity...
Definition: LockGuard.h:72
bool IsLockedBySelf() const
Query whether the serial device is currently "locked" by the responsible AccessClient entity...
Definition: LockGuard.h:64
bool UpdateSerialPortState(size_t a_LockHolders)
Update the effective lock state of the related serial port.
Definition: LockGuard.cpp:96
void Init(std::shared_ptr< SerialPortHandler > a_SerialPortHandler)
Initializer method to register subsequent objects.
Definition: LockGuard.cpp:55
LockGuard()
The constructor of LockGuard objects.
Definition: LockGuard.cpp:31
bool IsLocked() const
Query the lock state of the related serial device.
Definition: LockGuard.h:56
void AcquireLock()
Method to aquire a lock.
Definition: LockGuard.cpp:67
void ReleaseLock()
Method to release a lock.
Definition: LockGuard.cpp:80