sbuild-chroot.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_CHROOT_H
00021 #define SBUILD_CHROOT_H
00022 
00023 #include <iomanip>
00024 #include <ostream>
00025 #include <string>
00026 #include <vector>
00027 #include <tr1/memory>
00028 
00029 #include "sbuild-error.h"
00030 #include "sbuild-environment.h"
00031 #include "sbuild-keyfile.h"
00032 #include "sbuild-util.h"
00033 
00034 namespace sbuild
00035 {
00036 
00044   class chroot
00045   {
00046   public:
00048     enum setup_type
00049       {
00050         SETUP_START,   
00051         SETUP_RECOVER, 
00052         SETUP_STOP,    
00053         EXEC_START,     
00054         EXEC_STOP       
00055       };
00056 
00058     enum session_flags
00059       {
00060         SESSION_CREATE = 1 << 0 
00061       };
00062 
00064     typedef runtime_error_custom<chroot> error;
00065 
00067     typedef std::tr1::shared_ptr<chroot> ptr;
00068 
00069   protected:
00071     chroot ();
00072 
00073   public:
00075     virtual ~chroot ();
00076 
00083     static ptr
00084     create (std::string const& type);
00085 
00091     virtual ptr
00092     clone () const = 0;
00093 
00099     std::string const&
00100     get_name () const;
00101 
00107     void
00108     set_name (std::string const& name);
00109 
00115     std::string const&
00116     get_description () const;
00117 
00123     void
00124     set_description (std::string const& description);
00125 
00131     virtual std::string const&
00132     get_mount_location () const;
00133 
00139     void
00140     set_mount_location (std::string const& location);
00141 
00149     virtual std::string const&
00150     get_location () const;
00151 
00152   protected:
00160     virtual void
00161     set_location (std::string const& location);
00162 
00163   public:
00172     virtual std::string
00173     get_path () const;
00174 
00180     virtual std::string const&
00181     get_mount_device () const;
00182 
00188     void
00189     set_mount_device (std::string const& device);
00190 
00197     unsigned int
00198     get_priority () const;
00199 
00209     void
00210     set_priority (unsigned int priority);
00211 
00217     string_list const&
00218     get_groups () const;
00219 
00225     void
00226     set_groups (string_list const& groups);
00227 
00235     string_list const&
00236     get_root_groups () const;
00237 
00245     void
00246     set_root_groups (string_list const& groups);
00247 
00254     string_list const&
00255     get_aliases () const;
00256 
00263     void
00264     set_aliases (string_list const& aliases);
00265 
00271     bool
00272     get_active () const;
00273 
00279     void
00280     set_active (bool active);
00281 
00287     bool
00288     get_run_setup_scripts () const;
00289 
00296     void
00297     set_run_setup_scripts (bool run_setup_scripts);
00298 
00304     bool
00305     get_run_exec_scripts () const;
00306 
00313     void
00314     set_run_exec_scripts (bool run_exec_scripts);
00315 
00322     string_list const&
00323     get_command_prefix () const;
00324 
00331     void
00332     set_command_prefix (string_list const& command_prefix);
00333 
00339     virtual std::string const&
00340     get_chroot_type () const = 0;
00341 
00348     virtual void
00349     setup_env (environment& env);
00350 
00363     virtual void
00364     setup_lock (setup_type type,
00365                 bool       lock) = 0;
00366 
00367   protected:
00373     virtual void
00374     setup_session_info (bool start);
00375 
00376   public:
00383     virtual session_flags
00384     get_session_flags () const = 0;
00385 
00395     friend std::ostream&
00396     operator << (std::ostream& stream,
00397                  ptr const&    rhs)
00398     {
00399       rhs->print_details(stream);
00400       return stream;
00401     }
00402 
00406     friend
00407     keyfile const&
00408     operator >> (keyfile const& keyfile,
00409                  ptr&           rhs)
00410     {
00411       rhs->set_keyfile(keyfile);
00412       return keyfile;
00413     }
00414 
00418     friend
00419     keyfile&
00420     operator << (keyfile&   keyfile,
00421                  ptr const& rhs)
00422     {
00423       rhs->get_keyfile(keyfile);
00424       return keyfile;
00425     }
00426 
00427 
00428   protected:
00432     template<typename T>
00433     class format_detail
00434     {
00442     public:
00443       format_detail (std::string const& name,
00444                      T const&           value):
00445         name(name),
00446         value(value)
00447       {}
00448 
00456       friend std::ostream&
00457       operator << (std::ostream&           stream,
00458                    format_detail<T> const& rhs)
00459       {
00460         return stream << "  "
00461                       << std::setw(22) << std::left << rhs.name
00462                       << rhs.value << '\n';
00463       }
00464 
00473       friend std::ostream&
00474       operator << (std::ostream&              stream,
00475                    format_detail<bool> const& rhs)
00476       {
00477         const char *desc = 0;
00478         if (rhs.value)
00479           desc =  _("true");
00480         else
00481           desc = _("false");
00482         return stream << format_detail<std::string>(rhs.name, desc);
00483       }
00484 
00493       friend std::ostream&
00494       operator << (std::ostream&                     stream,
00495                    format_detail<string_list> const& rhs)
00496       {
00497         return stream <<
00498           format_detail<std::string>(rhs.name,
00499                                      string_list_to_string(rhs.value, " "));
00500       }
00501 
00502     private:
00504       std::string const& name;
00506       T const&           value;
00507     };
00508 
00517     template<typename T>
00518     format_detail<T>
00519     format_details (std::string const& name,
00520                     T const&           value) const
00521     {
00522       return format_detail<T>(name, value);
00523     }
00524 
00532     virtual void
00533     print_details (std::ostream& stream) const;
00534 
00542     virtual void
00543     get_keyfile (keyfile& keyfile) const;
00544 
00552     virtual void
00553     set_keyfile (keyfile const& keyfile);
00554 
00555   private:
00557     std::string   name;
00559     std::string   description;
00561     unsigned int  priority;
00563     string_list   groups;
00565     string_list   root_groups;
00567     string_list   aliases;
00569     std::string   mount_location;
00571     std::string   location;
00573     std::string   mount_device;
00575     bool          active;
00577     bool          run_setup_scripts;
00579     bool          run_exec_scripts;
00581     string_list   command_prefix;
00582   };
00583 
00584 }
00585 
00586 #endif /* SBUILD_CHROOT_H */
00587 
00588 /*
00589  * Local Variables:
00590  * mode:C++
00591  * End:
00592  */

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