1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 Checking for changes to files.
31 The default is to use stat to get the timestamp.
33 Compile with FOAM_USE_INOTIFY to use the inotify
34 (Linux specific, since 2.6.13) framework. The problem is that inotify does
35 not work on nfs3 mounted directories!!
40 \*---------------------------------------------------------------------------*/
45 #include <sys/types.h>
46 #include "NamedEnum.H"
47 #include "className.H"
48 #include "DynamicList.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 class fileMonitorWatcher;
58 /*---------------------------------------------------------------------------*\
59 Class fileMonitor Declaration
60 \*---------------------------------------------------------------------------*/
69 //- Enumeration defining the file state.
77 static const NamedEnum<fileState, 3> fileStateNames_;
82 //- Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above)
83 const bool useInotify_;
85 //- State for all watchFds based on local files
86 mutable DynamicList<fileState> localState_;
88 //- State for all watchFds - synchronised
89 mutable DynamicList<fileState> state_;
91 //- Filename for all watchFds
92 DynamicList<fileName> watchFile_;
95 DynamicList<label> freeWatchFds_;
97 //- Watch mechanism (stat or inotify)
98 mutable autoPtr<fileMonitorWatcher> watcher_;
101 // Private Member Functions
103 //- Update localState_ from any events.
104 void checkFiles() const;
106 //- Disallow default bitwise copy construct
107 fileMonitor(const fileMonitor&);
109 //- Disallow default bitwise assignment
110 void operator=(const fileMonitor&);
115 // Declare name of the class and its debug switch
116 ClassName("fileMonitor");
121 fileMonitor(const bool useInotify);
130 //- Add file to watch. Return watch descriptor
131 label addWatch(const fileName&);
133 //- Remove file to watch. Return true if successful
134 bool removeWatch(const label watchFd);
136 //- Get name of file being watched
137 const fileName& getFile(const label watchFd) const;
139 //- Check state using handle
140 fileState getState(const label watchFd) const;
142 //- Check state of all files. Updates state_.
145 const bool masterOnly,
149 //- Reset state (e.g. after having read it) using handle
150 void setUnmodified(const label watchFd);
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 // ************************************************************************* //