00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__util__PidFile_H__
00010 #define __libutilxx__sella__util__PidFile_H__
00011
00012 #include "../../common.h"
00013 #include "PidFileException.h"
00014
00015 #include <unistd.h>
00016 #include <sys/types.h>
00017
00018 #include <string>
00019 #include <memory>
00020
00021 namespace sella {
00022 namespace util {
00023 class PidFile;
00024 }
00025 }
00026
00027 class sella::util::PidFile {
00028 public:
00029 typedef std::shared_ptr<PidFile> shared;
00030 typedef PidFile* ptr;
00031
00032 public:
00033 PidFile(const std::string &file, uid_t uid = -1, gid_t gid = -1) throw ();
00034 PidFile(const PidFile &other);
00035 virtual ~PidFile();
00036
00037 PidFile& operator=(const PidFile &other) throw ();
00038 bool operator==(const PidFile &other) const throw () = delete;
00039 bool operator!=(const PidFile &other) const throw () = delete;
00040
00041 const std::string& get(void) const throw ();
00042 int read(void) const throw (PidFileException);
00043 int write(void) const throw (PidFileException);
00044 void remove(void) const throw (PidFileException);
00045
00046 bool isOwner(void) const throw ();
00047 bool isLive(void) const throw ();
00048 bool isFile(void) const throw ();
00049
00050 static const PidFile::shared shared_ptr(const std::string &file, uid_t uid = -1, gid_t gid = -1) throw ();
00051
00052 private:
00053 std::string file;
00054 uid_t uid;
00055 gid_t gid;
00056 };
00057
00058 #endif
00059
00060
00061
00062