#include "checkExist.h" #include "parallelCall.h" #include "fileHandling.h" namespace { template 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 inline Utility::ResultExist objExists(const Zstring& filename, size_t timeout) //timeout in ms { typedef CheckObjectExists CheckObjEx; boost::shared_ptr 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(filename, timeout); } Utility::ResultExist Utility::dirExists(const Zstring& dirname, size_t timeout) //timeout in ms { return objExists(dirname, timeout); }