Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
fileMonitor Class Reference

Checking for changes to files. More...

Collaboration diagram for fileMonitor:
Collaboration graph
[legend]

Public Types

enum  fileState { UNMODIFIED = 0, MODIFIED = 1, DELETED = 2 }
 Enumeration defining the file state. More...
 

Public Member Functions

 ClassName ("fileMonitor")
 
 fileMonitor (const bool useInotify)
 Construct null. More...
 
 ~fileMonitor ()
 Destructor. More...
 
label addWatch (const fileName &)
 Add file to watch. Return watch descriptor. More...
 
bool removeWatch (const label watchFd)
 Remove file to watch. Return true if successful. More...
 
const fileNamegetFile (const label watchFd) const
 Get name of file being watched. More...
 
fileState getState (const label watchFd) const
 Check state using handle. More...
 
void updateStates (const bool masterOnly, const bool syncPar) const
 Check state of all files. Updates state_. More...
 
void setUnmodified (const label watchFd)
 Reset state (e.g. after having read it) using handle. More...
 

Static Public Attributes

static const NamedEnum< fileState, 3 > fileStateNames_
 

Private Member Functions

void checkFiles () const
 Update localState_ from any events. More...
 
 fileMonitor (const fileMonitor &)
 Disallow default bitwise copy construct. More...
 
void operator= (const fileMonitor &)
 Disallow default bitwise assignment. More...
 

Private Attributes

const bool useInotify_
 Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above) More...
 
DynamicList< fileStatelocalState_
 State for all watchFds based on local files. More...
 
DynamicList< fileStatestate_
 State for all watchFds - synchronised. More...
 
DynamicList< fileNamewatchFile_
 Filename for all watchFds. More...
 
DynamicList< labelfreeWatchFds_
 Free watchFds. More...
 
autoPtr< fileMonitorWatcherwatcher_
 Watch mechanism (stat or inotify) More...
 

Detailed Description

Checking for changes to files.

Note
The default is to use stat to get the timestamp.

Compile with FOAM_USE_INOTIFY to use the inotify (Linux specific, since 2.6.13) framework. The problem is that inotify does not work on nfs3 mounted directories!!

Source files

Definition at line 61 of file fileMonitor.H.

Member Enumeration Documentation

◆ fileState

enum fileState

Enumeration defining the file state.

Enumerator
UNMODIFIED 
MODIFIED 
DELETED 

Definition at line 69 of file fileMonitor.H.

Constructor & Destructor Documentation

◆ fileMonitor() [1/2]

fileMonitor ( const fileMonitor )
private

Disallow default bitwise copy construct.

◆ fileMonitor() [2/2]

fileMonitor ( const bool  useInotify)

Construct null.

Definition at line 429 of file fileMonitor.C.

◆ ~fileMonitor()

Destructor.

Definition at line 442 of file fileMonitor.C.

Member Function Documentation

◆ checkFiles()

void checkFiles ( ) const
private

◆ operator=()

void operator= ( const fileMonitor )
private

Disallow default bitwise assignment.

◆ ClassName()

ClassName ( "fileMonitor"  )

◆ addWatch()

Foam::label addWatch ( const fileName fName)

Add file to watch. Return watch descriptor.

Definition at line 450 of file fileMonitor.C.

References Foam::endl(), Foam::Pout, and WarningInFunction.

Here is the call graph for this function:

◆ removeWatch()

bool removeWatch ( const label  watchFd)

Remove file to watch. Return true if successful.

Definition at line 489 of file fileMonitor.C.

References Foam::endl(), and Foam::Pout.

Here is the call graph for this function:

◆ getFile()

const Foam::fileName & getFile ( const label  watchFd) const

Get name of file being watched.

Definition at line 502 of file fileMonitor.C.

◆ getState()

Foam::fileMonitor::fileState getState ( const label  watchFd) const

Check state using handle.

Definition at line 508 of file fileMonitor.C.

◆ updateStates()

void updateStates ( const bool  masterOnly,
const bool  syncPar 
) const

Check state of all files. Updates state_.

Definition at line 516 of file fileMonitor.C.

References Foam::endl(), forAll, Pstream::listCombineGather(), Pstream::listCombineScatter(), UPstream::master(), Foam::Pout, Foam::reduce(), Pstream::scatter(), PackedList::storage(), and WarningInFunction.

Here is the call graph for this function:

◆ setUnmodified()

void setUnmodified ( const label  watchFd)

Reset state (e.g. after having read it) using handle.

Definition at line 611 of file fileMonitor.C.

References Foam::lastModified().

Here is the call graph for this function:

Field Documentation

◆ fileStateNames_

const Foam::NamedEnum< Foam::fileMonitor::fileState, 3 > fileStateNames_
static

Definition at line 76 of file fileMonitor.H.

◆ useInotify_

const bool useInotify_
private

Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above)

Definition at line 82 of file fileMonitor.H.

Referenced by fileMonitor::checkFiles().

◆ localState_

DynamicList<fileState> localState_
mutableprivate

State for all watchFds based on local files.

Definition at line 85 of file fileMonitor.H.

Referenced by fileMonitor::checkFiles().

◆ state_

DynamicList<fileState> state_
mutableprivate

State for all watchFds - synchronised.

Definition at line 88 of file fileMonitor.H.

◆ watchFile_

DynamicList<fileName> watchFile_
private

Filename for all watchFds.

Definition at line 91 of file fileMonitor.H.

Referenced by fileMonitor::checkFiles().

◆ freeWatchFds_

DynamicList<label> freeWatchFds_
private

Free watchFds.

Definition at line 94 of file fileMonitor.H.

◆ watcher_

autoPtr<fileMonitorWatcher> watcher_
mutableprivate

Watch mechanism (stat or inotify)

Definition at line 97 of file fileMonitor.H.

Referenced by fileMonitor::checkFiles().


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