idle_detect  0.8.3.0
Provides overall idle detection for a linux computer
Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
EventDetect::Monitor Class Reference

The Monitor class provides the framework for monitoring event activity recorded by the EventRecorders class EventRecorder threads. It also monitors changes in the input event devices and resets the EventRecorder threads if they change. It also updates the m_last_active_time. The class is a singleton and has one instantiated thread. It uses locks to protect the event_monitor device paths and the thread. The m_last_active_time is an atomic and requires no explicit locking. More...

#include <event_detect.h>

Public Member Functions

 Monitor ()
 Constructor.
 
std::vector< fs::path > GetEventDevices () const
 Provides a copy of the m_event_device_paths private member. The copy is provided instead of a reference to minimize the lock time held on mtx_event_monitor. More...
 
void UpdateEventDevices ()
 This calls the private method EnumerateEventDevices() and updates the m_event_device_paths private member.
 
void EventActivityMonitorThread ()
 This is the function that is the entry point for the event activity monitor worker thread.
 
bool IsInitialized () const
 Provides a flag to indicate whether the monitor has been initialized. This is used in main in the application control paths. More...
 
int64_t GetLastActiveTime () const
 Provides the last active time on this machine globally based on the activated monitors/recorders. More...
 

Public Attributes

std::thread m_monitor_thread
 Holds the actual monitor thread.
 
std::condition_variable cv_monitor_thread
 Condition variable for control/synchronization of the monitor thread.
 
std::atomic< bool > m_interrupt_monitor
 Atomic boolean that interrupts the monitor thread.
 

Private Member Functions

void WriteLastActiveTimeToFile (const fs::path &filepath)
 This is the whole point of the application. This writes out the last active time determined by the monitor. More...
 

Static Private Member Functions

static std::vector< fs::path > EnumerateEventDevices ()
 This is a private method to determine the input event devices to monitor. In particular we only want to monitor pointing devices (mice). More...
 

Private Attributes

std::mutex mtx_event_monitor
 This is the mutex member that provides lock control for the event monitor object. This is used to ensure the event monitor is thread-safe.
 
std::mutex mtx_event_monitor_thread
 This provides lock control for the monitor worker thread itself.
 
std::vector< fs::path > m_event_device_paths
 Holds the paths of the input event devices to monitor.
 
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 written to/read from without holding the mtx_event_monitor lock.
 
std::atomic< bool > m_initialized
 This holds the flag as to whether the monitor has been initialized and is provided by the IsInitialized() public method.
 

Detailed Description

The Monitor class provides the framework for monitoring event activity recorded by the EventRecorders class EventRecorder threads. It also monitors changes in the input event devices and resets the EventRecorder threads if they change. It also updates the m_last_active_time. The class is a singleton and has one instantiated thread. It uses locks to protect the event_monitor device paths and the thread. The m_last_active_time is an atomic and requires no explicit locking.

Member Function Documentation

◆ EnumerateEventDevices()

std::vector< fs::path > Monitor::EnumerateEventDevices ( )
staticprivate

This is a private method to determine the input event devices to monitor. In particular we only want to monitor pointing devices (mice).

Returns
Here is the caller graph for this function:

◆ GetEventDevices()

std::vector< fs::path > Monitor::GetEventDevices ( ) const

Provides a copy of the m_event_device_paths private member. The copy is provided instead of a reference to minimize the lock time held on mtx_event_monitor.

Returns
std::vector<fs::path> of the input event device paths.
Here is the caller graph for this function:

◆ GetLastActiveTime()

int64_t Monitor::GetLastActiveTime ( ) const

Provides the last active time on this machine globally based on the activated monitors/recorders.

Returns

◆ IsInitialized()

bool Monitor::IsInitialized ( ) const

Provides a flag to indicate whether the monitor has been initialized. This is used in main in the application control paths.

Returns
boolean flag

◆ WriteLastActiveTimeToFile()

void Monitor::WriteLastActiveTimeToFile ( const fs::path &  filepath)
private

This is the whole point of the application. This writes out the last active time determined by the monitor.

Parameters
filepath
Here is the caller graph for this function:

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