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 file_lock : public lock
00122   {
00123   public:
00129     file_lock (int fd);
00130 
00132     virtual ~file_lock ();
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 device_lock : public lock
00153   {
00154   public:
00160     device_lock (std::string const& device);
00161 
00163     virtual ~device_lock ();
00164 
00165     void
00166     set_lock (type         lock_type,
00167               unsigned int timeout);
00168 
00169     void
00170     unset_lock ();
00171 
00172   private:
00174     std::string device;
00175   };
00176 
00177 }
00178 
00179 #endif /* SBUILD_LOCK_H */
00180 
00181 /*
00182  * Local Variables:
00183  * mode:C++
00184  * End:
00185  */

Generated on Sun Mar 19 12:07:48 2006 for schroot by  doxygen 1.4.6