diff options
author | Stephen D. Huston <shuston@apache.org> | 2008-10-07 15:19:50 +0000 |
---|---|---|
committer | Stephen D. Huston <shuston@apache.org> | 2008-10-07 15:19:50 +0000 |
commit | 4eb2dca5b9ae07228f542cd798b44cc44ea96c09 (patch) | |
tree | 9d1de3abe8bca9ff0617432056217bfab12b00f5 /cpp/src/qpid/sys/LockFile.h | |
parent | cdae2a877123056b69a91dd8ca2196577654de2d (diff) | |
download | qpid-python-4eb2dca5b9ae07228f542cd798b44cc44ea96c09.tar.gz |
Abstract native file-locking and directory detection/creation to portable classes LockFile and FileSysDir; resolves QPID-1148
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@702513 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/LockFile.h')
-rw-r--r-- | cpp/src/qpid/sys/LockFile.h | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/cpp/src/qpid/sys/LockFile.h b/cpp/src/qpid/sys/LockFile.h index f06cd6a47d..2ff8c2f6d4 100644 --- a/cpp/src/qpid/sys/LockFile.h +++ b/cpp/src/qpid/sys/LockFile.h @@ -19,7 +19,60 @@ * */ -#include "posix/LockFile.h" +#include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> +#include <string> + +#include "IntegerTypes.h" + +namespace qpid { +namespace sys { + +class LockFilePrivate; + +/** + * @class LockFile + * + * LockFile represents a locked file suitable for a coarse-grain system + * lock. For example, the broker uses this to ensure that only one broker + * runs. A common usage idiom is to store the current "owner" process ID + * in the lock file - if the lock file exists, but the stored process ID + * doesn't, the old owner has probably died without cleaning up the lock + * file. + */ +class LockFile : private boost::noncopyable +{ + boost::shared_ptr<LockFilePrivate> impl; + + std::string path; + bool created; + +public: + LockFile(const std::string& path_, bool create); + ~LockFile(); + + /** + * Read the process ID from the lock file. This method assumes that + * if there is a process ID in the file, it was written there by + * writePid(); thus, it's at the start of the file. + * + * Throws an exception if there is an error reading the file. + * + * @returns The stored process ID. No validity check is done on it. + */ + pid_t readPid(void) const; + + /** + * Write the current process's ID to the lock file. It's written at + * the start of the file and will overwrite any other content that + * may be in the file. + * + * Throws an exception if the write fails. + */ + void writePid(void); +}; + +}} /* namespace qpid::sys */ #endif /*!_sys_LockFile_h*/ |