Loading...
Searching...
No Matches
fileMonitor.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2017-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::fileMonitor
29
30Description
31 Checking for changes to files.
32
33Note
34 The default is to use stat to get the timestamp.
35
36 Compile with FOAM_USE_INOTIFY to use the inotify
37 (Linux specific, since 2.6.13) framework. The problem is that inotify does
38 not work on nfs3 mounted directories!!
39
40SourceFiles
41 fileMonitor.C
42
43\*---------------------------------------------------------------------------*/
44
45#ifndef Foam_fileMonitor_H
46#define Foam_fileMonitor_H
47
48#include "DynamicList.H"
49#include <memory>
50#include <sys/types.h>
51
52// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53
54namespace Foam
55{
56
57// Forward Declarations
58class fileMonitor;
60template<class EnumType> class Enum;
62/*---------------------------------------------------------------------------*\
63 Class fileMonitor Declaration
64\*---------------------------------------------------------------------------*/
65
66class fileMonitor
67{
68public:
69
70 // Public Data Types
71
72 //- Enumeration defining the file state.
74 {
75 UNMODIFIED = 0,
76 MODIFIED = 1,
78 };
79
81
82private:
83
84 // Private Data
85
86 //- Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above)
87 const bool useInotify_;
88
89 //- State for all watchFds based on local files
90 mutable DynamicList<fileState> localState_;
91
92 //- State for all watchFds - synchronised
93 mutable DynamicList<fileState> state_;
94
95 //- Filename for all watchFds
96 DynamicList<fileName> watchFile_;
97
98 //- Free watchFds
99 DynamicList<label> freeWatchFds_;
100
101 //- Watch mechanism (stat or inotify)
102 mutable std::unique_ptr<fileMonitorWatcher> watcher_;
103
104
105 // Private Member Functions
106
107 //- Update localState_ from any events.
108 void checkFiles() const;
109
110 //- No copy construct
111 fileMonitor(const fileMonitor&) = delete;
112
113 //- No copy assignment
114 void operator=(const fileMonitor&) = delete;
115
116
117public:
118
119 //- Named/registered debug switch: 'fileMonitor'
120 static int debug;
121
122
123 // Constructors
124
125 //- Construct with specified inotify use
126 explicit fileMonitor(const bool useInotify);
127
128
129 //- Destructor
130 ~fileMonitor();
131
132
133 // Member Functions
134
135 //- Add file to watch. Return watch descriptor
136 label addWatch(const fileName&);
138 //- Remove file to watch. Return true if successful
139 bool removeWatch(const label watchFd);
140
141 //- Get name of file being watched
142 const fileName& getFile(const label watchFd) const;
143
144 //- Check state using handle
145 fileState getState(const label watchFd) const;
146
147 //- Check state of all files. Updates state_.
148 void updateStates
149 (
150 const bool masterOnly,
151 const bool syncPar
152 ) const;
153
154 //- Reset state (e.g. after having read it) using handle
155 void setUnmodified(const label watchFd);
156};
157
158
159// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160
161} // End namespace Foam
162
163// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164
165#endif
166
167// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
Internal tracking via stat(3p) or inotify(7).
Checking for changes to files.
Definition fileMonitor.H:62
fileState getState(const label watchFd) const
Check state using handle.
label addWatch(const fileName &)
Add file to watch. Return watch descriptor.
void setUnmodified(const label watchFd)
Reset state (e.g. after having read it) using handle.
~fileMonitor()
Destructor.
const fileName & getFile(const label watchFd) const
Get name of file being watched.
void updateStates(const bool masterOnly, const bool syncPar) const
Check state of all files. Updates state_.
static int debug
Named/registered debug switch: 'fileMonitor'.
static const Enum< fileState > fileStateNames_
Definition fileMonitor.H:77
fileState
Enumeration defining the file state.
Definition fileMonitor.H:71
bool removeWatch(const label watchFd)
Remove file to watch. Return true if successful.
A class for handling file names.
Definition fileName.H:75
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.