00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 SetupType
00049 {
00050 SETUP_START,
00051 SETUP_RECOVER,
00052 SETUP_STOP,
00053 RUN_START,
00054 RUN_STOP
00055 };
00056
00058 enum SessionFlags
00059 {
00060 SESSION_CREATE = 1 << 0
00061 };
00062
00064 typedef runtime_error_custom<Chroot> error;
00065
00067 typedef std::tr1::shared_ptr<Chroot> chroot_ptr;
00068
00069 protected:
00071 Chroot ();
00072
00079 Chroot (keyfile const& keyfile,
00080 std::string const& group);
00081 public:
00082
00084 virtual ~Chroot();
00085
00092 static chroot_ptr
00093 create (std::string const& type);
00094
00102 static chroot_ptr
00103 create (keyfile const& keyfile,
00104 std::string const& group);
00105
00111 virtual chroot_ptr
00112 clone () const = 0;
00113
00119 std::string const&
00120 get_name () const;
00121
00127 void
00128 set_name (std::string const& name);
00129
00135 std::string const&
00136 get_description () const;
00137
00143 void
00144 set_description (std::string const& description);
00145
00151 virtual std::string const&
00152 get_mount_location () const;
00153
00159 void
00160 set_mount_location (std::string const& location);
00161
00167 virtual std::string const&
00168 get_mount_device () const;
00169
00175 void
00176 set_mount_device (std::string const& device);
00177
00184 unsigned int
00185 get_priority () const;
00186
00196 void
00197 set_priority (unsigned int priority);
00198
00204 string_list const&
00205 get_groups () const;
00206
00212 void
00213 set_groups (string_list const& groups);
00214
00222 string_list const&
00223 get_root_groups () const;
00224
00232 void
00233 set_root_groups (string_list const& groups);
00234
00241 string_list const&
00242 get_aliases () const;
00243
00250 void
00251 set_aliases (string_list const& aliases);
00252
00258 bool
00259 get_active () const;
00260
00266 void
00267 set_active (bool active);
00268
00274 bool
00275 get_run_setup_scripts () const;
00276
00283 void
00284 set_run_setup_scripts (bool run_setup_scripts);
00285
00291 bool
00292 get_run_session_scripts () const;
00293
00300 void
00301 set_run_session_scripts (bool run_session_scripts);
00302
00308 virtual std::string const&
00309 get_chroot_type () const = 0;
00310
00317 virtual void
00318 setup_env (environment& env);
00319
00332 virtual void
00333 setup_lock (SetupType type,
00334 bool lock) = 0;
00335
00336 protected:
00342 virtual void
00343 setup_session_info (bool start);
00344
00345 public:
00352 virtual SessionFlags
00353 get_session_flags () const = 0;
00354
00362 virtual void
00363 print_details (std::ostream& stream) const;
00364
00374 virtual void
00375 print_config (std::ostream& stream) const;
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
00474 private:
00476 std::string name;
00478 std::string description;
00480 unsigned int priority;
00482 string_list groups;
00484 string_list root_groups;
00486 string_list aliases;
00488 std::string mount_location;
00490 std::string mount_device;
00492 bool active;
00494 bool run_setup_scripts;
00496 bool run_session_scripts;
00497 };
00498
00499 }
00500
00501 #endif
00502
00503
00504
00505
00506
00507