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 "sbuild-config.h"
00024 
00025 #include <iomanip>
00026 #include <ostream>
00027 #include <string>
00028 #include <vector>
00029 
00030 #ifdef HAVE_TR1_MEMORY
00031 #include <tr1/memory>
00032 #elif HAVE_BOOST_SHARED_PTR_HPP
00033 #include <boost/shared_ptr.hpp>
00034 namespace std { namespace tr1 { using boost::shared_ptr; } }
00035 #else
00036 #error A shared_ptr implementation is not available
00037 #endif
00038 
00039 #include "sbuild-error.h"
00040 #include "sbuild-environment.h"
00041 #include "sbuild-keyfile.h"
00042 #include "sbuild-util.h"
00043 
00044 namespace sbuild
00045 {
00046 
00054   class chroot
00055   {
00056   public:
00058     enum setup_type
00059       {
00060         SETUP_START,   
00061         SETUP_RECOVER, 
00062         SETUP_STOP,    
00063         EXEC_START,     
00064         EXEC_STOP       
00065       };
00066 
00068     enum session_flags
00069       {
00070         SESSION_CREATE = 1 << 0 
00071       };
00072 
00074     typedef runtime_error_custom<chroot> error;
00075 
00077     typedef std::tr1::shared_ptr<chroot> ptr;
00078 
00079   protected:
00081     chroot ();
00082 
00083   public:
00085     virtual ~chroot ();
00086 
00093     static ptr
00094     create (std::string const& type);
00095 
00101     virtual ptr
00102     clone () const = 0;
00103 
00109     std::string const&
00110     get_name () const;
00111 
00117     void
00118     set_name (std::string const& name);
00119 
00125     std::string const&
00126     get_description () const;
00127 
00133     void
00134     set_description (std::string const& description);
00135 
00141     virtual std::string const&
00142     get_mount_location () const;
00143 
00149     void
00150     set_mount_location (std::string const& location);
00151 
00159     virtual std::string const&
00160     get_location () const;
00161 
00162   protected:
00170     virtual void
00171     set_location (std::string const& location);
00172 
00173   public:
00182     virtual std::string
00183     get_path () const;
00184 
00190     virtual std::string const&
00191     get_mount_device () const;
00192 
00198     void
00199     set_mount_device (std::string const& device);
00200 
00207     unsigned int
00208     get_priority () const;
00209 
00219     void
00220     set_priority (unsigned int priority);
00221 
00227     string_list const&
00228     get_groups () const;
00229 
00235     void
00236     set_groups (string_list const& groups);
00237 
00245     string_list const&
00246     get_root_groups () const;
00247 
00255     void
00256     set_root_groups (string_list const& groups);
00257 
00264     string_list const&
00265     get_aliases () const;
00266 
00273     void
00274     set_aliases (string_list const& aliases);
00275 
00281     bool
00282     get_active () const;
00283 
00289     void
00290     set_active (bool active);
00291 
00297     bool
00298     get_run_setup_scripts () const;
00299 
00306     void
00307     set_run_setup_scripts (bool run_setup_scripts);
00308 
00314     bool
00315     get_run_exec_scripts () const;
00316 
00323     void
00324     set_run_exec_scripts (bool run_exec_scripts);
00325 
00332     string_list const&
00333     get_command_prefix () const;
00334 
00341     void
00342     set_command_prefix (string_list const& command_prefix);
00343 
00349     virtual std::string const&
00350     get_chroot_type () const = 0;
00351 
00358     virtual void
00359     setup_env (environment& env);
00360 
00372     void
00373     lock (setup_type type);
00374 
00388     void
00389     unlock (setup_type type,
00390             int        status);
00391 
00392   protected:
00398     virtual void
00399     setup_session_info (bool start);
00400 
00415     virtual void
00416     setup_lock(setup_type type,
00417                bool       lock,
00418                int        status) = 0;
00419 
00420   public:
00427     virtual session_flags
00428     get_session_flags () const = 0;
00429 
00439     friend std::ostream&
00440     operator << (std::ostream& stream,
00441                  ptr const&    rhs)
00442     {
00443       rhs->print_details(stream);
00444       return stream;
00445     }
00446 
00450     friend
00451     keyfile const&
00452     operator >> (keyfile const& keyfile,
00453                  ptr&           rhs)
00454     {
00455       rhs->set_keyfile(keyfile);
00456       return keyfile;
00457     }
00458 
00462     friend
00463     keyfile&
00464     operator << (keyfile&   keyfile,
00465                  ptr const& rhs)
00466     {
00467       rhs->get_keyfile(keyfile);
00468       return keyfile;
00469     }
00470 
00471 
00472   protected:
00480     virtual void
00481     print_details (std::ostream& stream) const;
00482 
00490     virtual void
00491     get_keyfile (keyfile& keyfile) const;
00492 
00500     virtual void
00501     set_keyfile (keyfile const& keyfile);
00502 
00503   private:
00505     std::string   name;
00507     std::string   description;
00509     unsigned int  priority;
00511     string_list   groups;
00513     string_list   root_groups;
00515     string_list   aliases;
00517     std::string   mount_location;
00519     std::string   location;
00521     std::string   mount_device;
00523     bool          active;
00525     bool          run_setup_scripts;
00527     bool          run_exec_scripts;
00529     string_list   command_prefix;
00530   };
00531 
00532 }
00533 
00534 #endif /* SBUILD_CHROOT_H */
00535 
00536 /*
00537  * Local Variables:
00538  * mode:C++
00539  * End:
00540  */

Generated on Sat Jun 10 10:05:12 2006 for schroot by  doxygen 1.4.6