libzypp 8.13.6
|
00001 00002 #ifndef ZYPP_BASE_INTER_PROCESS_MUTEX_H 00003 #define ZYPP_BASE_INTER_PROCESS_MUTEX_H 00004 00005 #include <string> 00006 #include "zypp/base/Fd.h" 00007 #include "zypp/base/Exception.h" 00008 #include "zypp/base/NonCopyable.h" 00009 #include "zypp/Pathname.h" 00010 00011 namespace zypp 00012 { 00013 namespace base 00014 { 00015 00016 class ZYppLockedException : public Exception 00017 { 00018 public: 00019 ZYppLockedException( const std::string & msg_r, 00020 const std::string &name, 00021 pid_t locker_pid ); 00022 virtual ~ZYppLockedException() throw(); 00023 pid_t locker_pid() const { return _locker_pid; } 00024 std::string name() const { return _name; } 00025 private: 00026 pid_t _locker_pid; 00027 std::string _name; 00028 }; 00029 00043 class InterProcessMutex : private base::NonCopyable 00044 { 00045 public: 00050 enum ConsumerType 00051 { 00052 Reader, 00053 Writer 00054 }; 00055 00059 class Options 00060 { 00061 public: 00077 Options( ConsumerType ptype, 00078 const std::string &pname = "zypp", 00079 int ptimeout = -1 ); 00080 00085 void setPath( const Pathname &base ); 00086 00087 std::string name; 00088 int timeout; 00089 ConsumerType type; 00090 Pathname base; 00091 }; 00092 00108 InterProcessMutex( const Options &poptions ); 00109 00114 ~InterProcessMutex(); 00115 00116 private: 00117 bool isProcessRunning(pid_t pid_r); 00118 Pathname lockFilePath() const; 00119 private: 00120 shared_ptr<Fd> _fd; 00121 Options _options; 00122 }; 00123 00124 00125 } } 00126 00127 00128 #endif 00129