CMS 3D CMS Logo

FileNameLock.h

Go to the documentation of this file.
00001 #ifndef CLASSLIB_FILE_NAME_LOCK_H
00002 # define CLASSLIB_FILE_NAME_LOCK_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "classlib/iobase/Filename.h"
00007 # include "classlib/utils/Time.h"
00008 # include <string>
00009 
00010 namespace lat {
00011 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00012 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00013 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00014 
00015 class Filename;
00016 
00017 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00018 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00019 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00020 
00021 class FileNameLock
00022 {
00023 public:
00024     enum Kind {
00025         LockNone,
00026         LockSelf,
00027         LockOther,
00028         LockUnknown
00029     };
00030 
00031     enum Success {
00032         LockCreated,
00033         LockExists,
00034         LockFailure
00035     };
00036 
00037     class Info
00038     {
00039     public:
00040         Info (void);
00041         // implicit copy constructor
00042         // implicit destructor
00043         // implicit assignment operator
00044 
00045     private:
00046     };
00047 
00048     FileNameLock (void);
00049     FileNameLock (const Filename &name);
00050     ~FileNameLock (void);
00051 
00052     // Locking (see also filename autosave, backups)
00053     Kind                tryLock (const Filename &name);
00054     static bool         isLocked (const Filename &name, FileNameLock **lock);
00055 
00056     void                lock (const Filename &name);
00057     void                unlock (void);
00058 
00059     // Lock details
00060     bool                valid (void) const;
00061     const std::string & user (void) const;
00062     const std::string & host (void) const;
00063     pid_t               pid (void) const;
00064     Time                time (void) const;
00065 
00066 private:
00067     void                unlock (const Filename &name);
00068     // void             unlockAll (const Filename &name) const;
00069 
00070     static Filename     lockname (const Filename &name);
00071     Kind                locker (const Filename &name);
00072     Success             tryLock (const Filename &name, bool force);
00073 
00074     void                reset (void);
00075 
00076     FileNameLock &      now (void);
00077     Filename            format (void) const;
00078     bool                parse (const Filename &from);
00079 
00080     Filename            m_filename;
00081     std::string         m_user;
00082     std::string         m_host;
00083     pid_t               m_pid;
00084     Time                m_time;
00085 
00086     // undefined, no semantics (yet?)
00087     FileNameLock (const FileNameLock &);
00088     FileNameLock &operator= (const FileNameLock &);
00089 };
00090 
00091 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00092 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00093 
00094 } // namespace lat
00095 #endif // CLASSLIB_FILE_NAME_LOCK_H

Generated on Tue Jun 9 17:38:51 2009 for CMSSW by  doxygen 1.5.4