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         RUN_START,     
00054         RUN_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 
00147     virtual std::string const&
00148     get_mount_device () const;
00149 
00155     void
00156     set_mount_device (std::string const& device);
00157 
00164     unsigned int
00165     get_priority () const;
00166 
00176     void
00177     set_priority (unsigned int priority);
00178 
00184     string_list const&
00185     get_groups () const;
00186 
00192     void
00193     set_groups (string_list const& groups);
00194 
00202     string_list const&
00203     get_root_groups () const;
00204 
00212     void
00213     set_root_groups (string_list const& groups);
00214 
00221     string_list const&
00222     get_aliases () const;
00223 
00230     void
00231     set_aliases (string_list const& aliases);
00232 
00238     bool
00239     get_active () const;
00240 
00246     void
00247     set_active (bool active);
00248 
00254     bool
00255     get_run_setup_scripts () const;
00256 
00263     void
00264     set_run_setup_scripts (bool run_setup_scripts);
00265 
00271     bool
00272     get_run_session_scripts () const;
00273 
00280     void
00281     set_run_session_scripts (bool run_session_scripts);
00282 
00288     virtual std::string const&
00289     get_chroot_type () const = 0;
00290 
00297     virtual void
00298     setup_env (environment& env);
00299 
00312     virtual void
00313     setup_lock (setup_type type,
00314                 bool       lock) = 0;
00315 
00316   protected:
00322     virtual void
00323     setup_session_info (bool start);
00324 
00325   public:
00332     virtual session_flags
00333     get_session_flags () const = 0;
00334 
00344     friend std::ostream&
00345     operator << (std::ostream& stream,
00346                  ptr const&    rhs)
00347     {
00348       rhs->print_details(stream);
00349       return stream;
00350     }
00351 
00355     friend
00356     keyfile const&
00357     operator >> (keyfile const& keyfile,
00358                  ptr&           rhs)
00359     {
00360       rhs->set_keyfile(keyfile);
00361       return keyfile;
00362     }
00363 
00367     friend
00368     keyfile&
00369     operator << (keyfile&   keyfile,
00370                  ptr const& rhs)
00371     {
00372       rhs->get_keyfile(keyfile);
00373       return keyfile;
00374     }
00375 
00376 
00377   protected:
00381     template<typename T>
00382     class format_detail
00383     {
00391     public:
00392       format_detail (std::string const& name,
00393                      T const&           value):
00394         name(name),
00395         value(value)
00396       {}
00397 
00405       friend std::ostream&
00406       operator << (std::ostream&           stream,
00407                    format_detail<T> const& rhs)
00408       {
00409         return stream << "  "
00410                       << std::setw(22) << std::left << rhs.name
00411                       << rhs.value << '\n';
00412       }
00413 
00422       friend std::ostream&
00423       operator << (std::ostream&              stream,
00424                    format_detail<bool> const& rhs)
00425       {
00426         const char *desc = 0;
00427         if (rhs.value)
00428           desc =  _("true");
00429         else
00430           desc = _("false");
00431         return stream << format_detail<std::string>(rhs.name, desc);
00432       }
00433 
00442       friend std::ostream&
00443       operator << (std::ostream&                     stream,
00444                    format_detail<string_list> const& rhs)
00445       {
00446         return stream <<
00447           format_detail<std::string>(rhs.name,
00448                                      string_list_to_string(rhs.value, " "));
00449       }
00450 
00451     private:
00453       std::string const& name;
00455       T const&           value;
00456     };
00457 
00466     template<typename T>
00467     format_detail<T>
00468     format_details (std::string const& name,
00469                     T const&           value) const
00470     {
00471       return format_detail<T>(name, value);
00472     }
00473 
00481     virtual void
00482     print_details (std::ostream& stream) const;
00483 
00491     virtual void
00492     get_keyfile (keyfile& keyfile) const;
00493 
00501     virtual void
00502     set_keyfile (keyfile const& keyfile);
00503 
00504   private:
00506     std::string   name;
00508     std::string   description;
00510     unsigned int  priority;
00512     string_list   groups;
00514     string_list   root_groups;
00516     string_list   aliases;
00518     std::string   mount_location;
00520     std::string   mount_device;
00522     bool          active;
00524     bool          run_setup_scripts;
00526     bool          run_session_scripts;
00527   };
00528 
00529 }
00530 
00531 #endif /* SBUILD_CHROOT_H */
00532 
00533 /*
00534  * Local Variables:
00535  * mode:C++
00536  * End:
00537  */

Generated on Tue Feb 21 11:01:27 2006 for schroot by  doxygen 1.4.6