diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:07:43 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:07:43 +0200 |
commit | 4226e548662339ea1ca37b45385a7cf9b237ff1e (patch) | |
tree | 9a3fa54b85d97f05164e41bdb96b82f748a37342 /shared/checkExist.cpp | |
parent | 3.7 (diff) | |
download | FreeFileSync-4226e548662339ea1ca37b45385a7cf9b237ff1e.tar.gz FreeFileSync-4226e548662339ea1ca37b45385a7cf9b237ff1e.tar.bz2 FreeFileSync-4226e548662339ea1ca37b45385a7cf9b237ff1e.zip |
3.8
Diffstat (limited to 'shared/checkExist.cpp')
-rw-r--r-- | shared/checkExist.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/shared/checkExist.cpp b/shared/checkExist.cpp new file mode 100644 index 00000000..3f71afb8 --- /dev/null +++ b/shared/checkExist.cpp @@ -0,0 +1,54 @@ +#include "checkExist.h" +#include "parallelCall.h" +#include "fileHandling.h" + + +namespace +{ +template <bool (*testExist)(const Zstring&)> +class CheckObjectExists : public Async::Procedure +{ +public: + CheckObjectExists(const Zstring& filename) : + filename_(filename.c_str()), //deep copy: worker thread may run longer than main! Avoid shared data + isExisting(false) {} + + virtual void doWork() + { + isExisting = testExist(filename_); //throw() + } + + bool doesExist() const //retrieve result + { + return isExisting; + } + +private: + const Zstring filename_; //no reference, lifetime not known + bool isExisting; +}; + + +template <bool (*testExist)(const Zstring&)> +inline +Utility::ResultExist objExists(const Zstring& filename, size_t timeout) //timeout in ms +{ + typedef CheckObjectExists<testExist> CheckObjEx; + boost::shared_ptr<CheckObjEx> proc(new CheckObjEx(filename)); + + return Async::execute(proc, timeout) == Async::TIMEOUT ? Utility::EXISTING_TIMEOUT : + (proc->doesExist() ? Utility::EXISTING_TRUE : Utility::EXISTING_FALSE); +} +} + + +Utility::ResultExist Utility::fileExists(const Zstring& filename, size_t timeout) //timeout in ms +{ + return objExists<FreeFileSync::fileExists>(filename, timeout); +} + + +Utility::ResultExist Utility::dirExists(const Zstring& dirname, size_t timeout) //timeout in ms +{ + return objExists<FreeFileSync::dirExists>(dirname, timeout); +} |