diff --git a/src/OSspecific/MSWindows/MSwindows.C b/src/OSspecific/MSWindows/MSwindows.C index 0afceab45..96474a78e 100644 --- a/src/OSspecific/MSWindows/MSwindows.C +++ b/src/OSspecific/MSWindows/MSwindows.C @@ -43,6 +43,8 @@ Description #include // Windows system header files +// DebugInfo macro defined in messageStream.H clashes with Windows headers +#undef DebugInfo #include // _close #include #include @@ -372,7 +374,7 @@ string getEnv(const word& envName) bool setEnv ( const word& envName, - const string& value, + const std::string& value, const bool overwrite ) { @@ -382,9 +384,8 @@ bool setEnv } -word hostName() +string hostName(bool full) { - const bool full = true; const DWORD bufferSize = MAX_COMPUTERNAME_LENGTH + 1; TCHAR buffer[bufferSize]; DWORD actualBufferSize = bufferSize; @@ -392,6 +393,17 @@ word hostName() const bool success = ::GetComputerName(buffer, &actualBufferSize); const string computerName = success ? buffer : string::null; + + // implementation as per hostname from net-tools + if (full) + { + struct hostent *hp = gethostbyname(computerName.c_str()); + if (hp) + { + return hp->h_name; + } + } + return computerName; } @@ -405,7 +417,7 @@ string domainName() } -word userName() +string userName() { std::string name = getEnv("USERNAME"); @@ -438,7 +450,7 @@ fileName home() } -fileName home(const word& userName) +fileName home(const string& userName) { return home(); } @@ -1287,7 +1299,7 @@ void* dlOpen(const fileName& libName, const bool check) // Assumes libName = name winLibName = "lib"; winLibName += libName; - winLibName += dllExt; + winLibName += ".dll"; handle = ::LoadLibrary(winLibName.c_str()); } diff --git a/src/OSspecific/MSWindows/Make/files b/src/OSspecific/MSWindows/Make/files index 2cdd725c5..ebd6e82d7 100644 --- a/src/OSspecific/MSWindows/Make/files +++ b/src/OSspecific/MSWindows/Make/files @@ -9,6 +9,17 @@ MSwindows.C cpuTime/cpuTime.C clockTime/clockTime.C multiThreader/multiThreader.C + +/* + * Note: fileMonitor assumes inotify by default. Compile with -DFOAM_USE_STAT + * to use stat (=timestamps) instead of inotify + */ +fileMonitor.C + +#ifdef SunOS64 +dummyPrintStack.C +#else printStack.C +#endif LIB = $(FOAM_LIBBIN)/libOSspecific diff --git a/src/OSspecific/MSWindows/fileMonitor.C b/src/OSspecific/MSWindows/fileMonitor.C new file mode 100644 index 000000000..ad0fd807e --- /dev/null +++ b/src/OSspecific/MSWindows/fileMonitor.C @@ -0,0 +1,427 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.1 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#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 +# error "fileMonitor.C: FOAM_USE_INOTIFY is not supported on MSWindows" +#else +# include "OSspecific.H" +#endif + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const Foam::NamedEnum + Foam::fileMonitor::fileStateNames_; + +namespace Foam +{ + defineTypeNameAndDebug(fileMonitor, 0); + + 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); + } + }; + + + + //- 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