/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . Class fileMonitor \*----------------------------------------------------------------------------*/ #include "fileMonitor.H" #include "IOstreams.H" #include "Pstream.H" #include "PackedList.H" #include "PstreamReduceOps.H" #include "OSspecific.H" #include "regIOobject.H" // for fileModificationSkew symbol #ifdef FOAM_USE_INOTIFY # include # include # include # define EVENT_SIZE ( sizeof (struct inotify_event) ) # define EVENT_LEN (EVENT_SIZE + 16) # define EVENT_BUF_LEN ( 1024 * EVENT_LEN ) #else # include "OSspecific.H" #endif // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeNameAndDebug(Foam::fileMonitor, 0); const Foam::NamedEnum Foam::fileMonitor::fileStateNames_; namespace Foam { template<> const char* Foam::NamedEnum < Foam::fileMonitor::fileState, 3 >::names[] = { "unmodified", "modified", "deleted" }; //- Reduction operator for PackedList of fileState class reduceFileStates { public: unsigned int operator()(const unsigned int x, const unsigned int y) const { // x,y are sets of 2bits representing fileState unsigned int mask = 3u; unsigned int shift = 0; unsigned int result = 0; while (mask) { // Combine state unsigned int xState = (x & mask) >> shift; unsigned int yState = (y & mask) >> shift; // Combine and add to result. Combine is such that UNMODIFIED // wins. unsigned int state = min(xState, yState); result |= (state << shift); shift += 2; mask <<= 2; } return result; } }; //- Combine operator for PackedList of fileState class combineReduceFileStates { public: void operator()(unsigned int& x, const unsigned int y) const { x = reduceFileStates()(x, y); } }; //! @cond internalClass //- Internal tracking via stat(3p) or inotify(7) class fileMonitorWatcher { public: const bool useInotify_; // For inotify //- File descriptor for the inotify instance int inotifyFd_; //- Current watchIDs and corresponding directory id DynamicList