11 #include <condition_variable> 212 void ResetEventRecorders();
295 explicit Tty(
const fs::path& tty_device_path);
516 std::string m_shm_name;
518 int64_t* m_mapped_ptr;
521 std::atomic<bool> m_is_initialized;
528 void Shutdown(
const int &exit_code = 0);
541 #endif // EVENT_DETECT_H bool IsInitialized() const
Provides a flag to indicate whether the monitor has been initialized. This is used in main in the app...
Definition: event_detect.cpp:828
std::condition_variable cv_tty_monitor_thread
Condition variable for control/synchronization of the tty monitor threads.
Definition: event_detect.h:244
std::atomic< int64_t > m_last_active_time
holds the last active time determined by the monitor. This is an atomic, which means it can be writte...
Definition: event_detect.h:114
static std::vector< fs::path > EnumerateTtyDevices()
Provides the enumerated pts/tty devices.
Definition: event_detect.cpp:523
int64_t GetLastTtyActiveTime() const
Returns the overall last active time of all of the monitored pts/ttys.
Definition: event_detect.cpp:517
int64_t GetLastActiveTime() const
Provides the last active time on this machine globally based on the activated monitors/recorders.
Definition: event_detect.cpp:215
void EventActivityMonitorThread()
This is the function that is the entry point for the event activity monitor worker thread...
Definition: event_detect.cpp:92
std::mutex mtx_event_monitor_thread
This provides lock control for the monitor worker thread itself.
Definition: event_detect.h:103
bool IsInitialized() const
Provides a flag to indicate whether the monitor has been initialized. This is used in main in the app...
Definition: event_detect.cpp:512
std::condition_variable cv_monitor_thread
Condition variable for control/synchronization of the monitor thread.
Definition: event_detect.h:38
std::mutex mtx_event_monitor
This is the mutex member that provides lock control for the event monitor object. This is used to ens...
Definition: event_detect.h:98
bool UpdateTimestamps(int64_t update_time, int64_t last_active_time)
Updates both timestamps in the mapped shared memory.
Definition: event_detect.cpp:1069
int64_t m_tty_last_active_time
Holds the last active time of the pts/tty.
Definition: event_detect.h:305
The Tty class is a small class to hold pts/tty information. It is essentially a struct with a paramet...
Definition: event_detect.h:288
Manages a POSIX shared memory segment for exporting timestamps. Stores an array of two int64_t: {upda...
Definition: event_detect.h:451
std::string StateToString() const
Returns the string representation of the idle monitor object state.
Definition: event_detect.cpp:865
std::atomic< int64_t > m_last_ttys_active_time
Atomic that holds the overall last active time across all of the monitored pts/ttys.
Definition: event_detect.h:340
fs::path m_tty_device_path
Holds the pts/tty device path.
Definition: event_detect.h:300
void TtyMonitorThread()
Method to instantiate the tty monitor thread.
Definition: event_detect.cpp:554
bool UnlinkSegment()
Explicitly unlinks the shared memory segment. Call during clean shutdown if desired. Idempotent.
Definition: event_detect.cpp:1108
std::condition_variable cv_idle_detect_monitor_thread
Condition variable for control/synchronization of the idle_detect monitor threads.
Definition: event_detect.h:367
Definition: event_detect.h:233
TtyMonitor()
Constructor.
Definition: event_detect.cpp:481
The Config class is a singleton that stores program config read from the config file, with applied defaults if the config file cannot be read, or a config parameter is not in the config file.
Definition: util.h:233
std::atomic< bool > m_initialized
This holds the flag as to whether the monitor has been initialized and is provided by the IsInitializ...
Definition: event_detect.h:120
std::vector< fs::path > GetEventDevices() const
Provides a copy of the m_event_device_paths private member. The copy is provided instead of a referen...
Definition: event_detect.cpp:287
int64_t GetLastIdleDetectActiveTime() const
Returns the overall last active time of all of the message receipts from idle_detect instances...
Definition: event_detect.cpp:833
bool IsInitialized() const
Checks if the shared memory was successfully initialized (opened and mapped).
Definition: event_detect.cpp:1083
std::atomic< bool > m_interrupt_monitor
Atomic boolean that interrupts the monitor thread.
Definition: event_detect.h:43
std::thread m_tty_monitor_thread
Holds the actual tty monitor thread.
Definition: event_detect.h:239
void WriteLastActiveTimeToFile(const fs::path &filepath)
This is the whole point of the application. This writes out the last active time determined by the mo...
Definition: event_detect.cpp:260
std::atomic< bool > m_interrupt_tty_monitor
Atomic boolean that interrupts the tty monitor thread.
Definition: event_detect.h:249
The EventDetectConfig class. This specializes the Config class and implements the virtual method Proc...
Definition: event_detect.h:536
std::vector< Tty > m_ttys
std::vector holding the tty objects.
Definition: event_detect.h:335
Definition: event_detect.h:18
std::mutex mtx_tty_monitor
This is the mutex member that provides lock control for the tty monitor object. This is used to ensur...
Definition: event_detect.h:319
std::atomic< State > m_state
Holds the current state of the idle monitor. NORMAL means idle detect follows the normal threshold (t...
Definition: event_detect.h:437
void Cleanup()
Performs resource cleanup (munmap). Called by destructor.
Definition: event_detect.cpp:1087
std::mutex mtx_idle_detect_monitor_thread
This provides lock control for the tty monitor worker thread itself.
Definition: event_detect.h:424
void IdleDetectMonitorThread()
Method to instantiate the tty monitor thread.
Definition: event_detect.cpp:629
Monitor()
Constructor.
Definition: event_detect.cpp:85
bool IsInitialized() const
Provides a flag to indicate whether the monitor has been initialized. This is used in main in the app...
Definition: event_detect.cpp:210
void ProcessArgs() override
Private helper method used by ReadAndUpdateConfig. Note this is pure virtual. It must be implemented ...
Definition: event_detect.cpp:872
SharedMemoryTimestampExporter(const std::string &name)
Construct with the desired shared memory name.
Definition: event_detect.cpp:973
std::vector< fs::path > GetTtyDevices() const
Returns a copy of the vector of pts/tty paths. A copy is returned to avoid holding the lock on mtx_tt...
Definition: event_detect.cpp:489
~SharedMemoryTimestampExporter()
Destructor handles unmapping and potentially unlinking the shared memory.
Definition: event_detect.cpp:986
std::atomic< bool > m_initialized
This holds the flag as to whether the tty monitor has been initialized and is provided by the IsIniti...
Definition: event_detect.h:346
bool CreateOrOpen(mode_t mode=0666)
Creates (if necessary) and opens the shared memory segment, sets its size (to sizeof(int64_t[2])), and maps it for writing. Must be called before UpdateTimestamps or IsInitialized.
Definition: event_detect.cpp:991
std::atomic< int64_t > m_last_idle_detect_active_time
Atomic that holds the overall last active time across all of the monitored pts/ttys.
Definition: event_detect.h:429
std::vector< fs::path > m_event_device_paths
Holds the paths of the input event devices to monitor.
Definition: event_detect.h:108
std::vector< fs::path > m_tty_device_paths
Holds the device paths of the monitored pts/ttys. Note that this is duplicative of information in the...
Definition: event_detect.h:330
The Monitor class provides the framework for monitoring event activity recorded by the EventRecorders...
Definition: event_detect.h:27
std::thread m_idle_detect_monitor_thread
Holds the actual idle_detect monitor thread.
Definition: event_detect.h:362
Tty(const fs::path &tty_device_path)
Parameterized constructor.
Definition: event_detect.cpp:615
std::mutex mtx_shmem
This protects against multiple threads in the event_detect process from simultaneously accessing and ...
Definition: event_detect.h:514
std::atomic< bool > m_interrupt_idle_detect_monitor
Atomic boolean that interrupts the idle_detect monitor thread.
Definition: event_detect.h:372
std::thread m_monitor_thread
Holds the actual monitor thread.
Definition: event_detect.h:33
void UpdateTtyDevices()
Initializes/Updates the pts/tty device paths to monitor.
Definition: event_detect.cpp:496
std::mutex mtx_tty_monitor_thread
This provides lock control for the tty monitor worker thread itself.
Definition: event_detect.h:324
Definition: event_detect.h:349
IdleDetectMonitor()
Constructor.
Definition: event_detect.cpp:623
State GetState() const
Returns the state of the idle monitor. This is NORMAL, FORCED_ACTIVE or FORCED_IDLE.
Definition: event_detect.cpp:838
std::mutex mtx_idle_detect_monitor
This is the mutex member that provides lock control for the tty monitor object. This is used to ensur...
Definition: event_detect.h:419
std::atomic< bool > m_initialized
This holds the flag as to whether the tty monitor has been initialized and is provided by the IsIniti...
Definition: event_detect.h:443
void UpdateEventDevices()
This calls the private method EnumerateEventDevices() and updates the m_event_device_paths private me...
Definition: event_detect.cpp:294
static std::vector< fs::path > EnumerateEventDevices()
This is a private method to determine the input event devices to monitor. In particular we only want ...
Definition: event_detect.cpp:220