sbuild-lock.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software; you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 2 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00016  * MA  02111-1307  USA
00017  *
00018  *********************************************************************/
00019 
00020 #ifndef SBUILD_LOCK_H
00021 #define SBUILD_LOCK_H
00022 
00023 #include <string>
00024 
00025 #include <sys/time.h>
00026 #include <fcntl.h>
00027 #include <signal.h>
00028 #include <unistd.h>
00029 
00030 #include "sbuild-error.h"
00031 
00032 namespace sbuild
00033 {
00034 
00039   class Lock
00040   {
00041   public:
00043     enum Type
00044       {
00045         LOCK_SHARED    = F_RDLCK, 
00046         LOCK_EXCLUSIVE = F_WRLCK, 
00047         LOCK_NONE      = F_UNLCK  
00048       };
00049 
00051     typedef runtime_error_custom<Lock> error;
00052 
00059     virtual void
00060     set_lock (Type         lock_type,
00061               unsigned int timeout) = 0;
00062 
00067     virtual void
00068     unset_lock () = 0;
00069 
00070   protected:
00072     Lock();
00074     virtual ~Lock();
00075 
00081     void
00082     set_alarm ();
00083 
00088     void
00089     clear_alarm ();
00090 
00100     void
00101     set_timer(struct itimerval const& timer);
00102 
00109     void
00110     unset_timer();
00111 
00112   private:
00114     struct sigaction saved_signals;
00115   };
00116 
00121   class FileLock : public Lock
00122   {
00123   public:
00129     FileLock (int fd);
00130 
00132     virtual ~FileLock();
00133 
00134     void
00135     set_lock (Type         lock_type,
00136               unsigned int timeout);
00137 
00138     void
00139     unset_lock ();
00140 
00141   private:
00143     int fd;
00144   };
00145 
00152   class DeviceLock : public Lock
00153   {
00154   public:
00160     DeviceLock (std::string const& device);
00161     virtual ~DeviceLock();
00162 
00163     void
00164     set_lock (Type         lock_type,
00165               unsigned int timeout);
00166 
00167     void
00168     unset_lock ();
00169 
00170   private:
00172     std::string device;
00173   };
00174 
00175 }
00176 
00177 #endif /* SBUILD_LOCK_H */
00178 
00179 /*
00180  * Local Variables:
00181  * mode:C++
00182  * End:
00183  */

Generated on Mon Jan 30 13:22:57 2006 for schroot by  doxygen 1.4.6