summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/LockFile.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/sys/LockFile.h')
-rw-r--r--cpp/src/qpid/sys/LockFile.h55
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*/