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 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
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_session_scripts () const;
00306
00313 void
00314 set_run_session_scripts (bool run_session_scripts);
00315
00321 virtual std::string const&
00322 get_chroot_type () const = 0;
00323
00330 virtual void
00331 setup_env (environment& env);
00332
00345 virtual void
00346 setup_lock (setup_type type,
00347 bool lock) = 0;
00348
00349 protected:
00355 virtual void
00356 setup_session_info (bool start);
00357
00358 public:
00365 virtual session_flags
00366 get_session_flags () const = 0;
00367
00377 friend std::ostream&
00378 operator << (std::ostream& stream,
00379 ptr const& rhs)
00380 {
00381 rhs->print_details(stream);
00382 return stream;
00383 }
00384
00388 friend
00389 keyfile const&
00390 operator >> (keyfile const& keyfile,
00391 ptr& rhs)
00392 {
00393 rhs->set_keyfile(keyfile);
00394 return keyfile;
00395 }
00396
00400 friend
00401 keyfile&
00402 operator << (keyfile& keyfile,
00403 ptr const& rhs)
00404 {
00405 rhs->get_keyfile(keyfile);
00406 return keyfile;
00407 }
00408
00409
00410 protected:
00414 template<typename T>
00415 class format_detail
00416 {
00424 public:
00425 format_detail (std::string const& name,
00426 T const& value):
00427 name(name),
00428 value(value)
00429 {}
00430
00438 friend std::ostream&
00439 operator << (std::ostream& stream,
00440 format_detail<T> const& rhs)
00441 {
00442 return stream << " "
00443 << std::setw(22) << std::left << rhs.name
00444 << rhs.value << '\n';
00445 }
00446
00455 friend std::ostream&
00456 operator << (std::ostream& stream,
00457 format_detail<bool> const& rhs)
00458 {
00459 const char *desc = 0;
00460 if (rhs.value)
00461 desc = _("true");
00462 else
00463 desc = _("false");
00464 return stream << format_detail<std::string>(rhs.name, desc);
00465 }
00466
00475 friend std::ostream&
00476 operator << (std::ostream& stream,
00477 format_detail<string_list> const& rhs)
00478 {
00479 return stream <<
00480 format_detail<std::string>(rhs.name,
00481 string_list_to_string(rhs.value, " "));
00482 }
00483
00484 private:
00486 std::string const& name;
00488 T const& value;
00489 };
00490
00499 template<typename T>
00500 format_detail<T>
00501 format_details (std::string const& name,
00502 T const& value) const
00503 {
00504 return format_detail<T>(name, value);
00505 }
00506
00514 virtual void
00515 print_details (std::ostream& stream) const;
00516
00524 virtual void
00525 get_keyfile (keyfile& keyfile) const;
00526
00534 virtual void
00535 set_keyfile (keyfile const& keyfile);
00536
00537 private:
00539 std::string name;
00541 std::string description;
00543 unsigned int priority;
00545 string_list groups;
00547 string_list root_groups;
00549 string_list aliases;
00551 std::string mount_location;
00553 std::string location;
00555 std::string mount_device;
00557 bool active;
00559 bool run_setup_scripts;
00561 bool run_session_scripts;
00562 };
00563
00564 }
00565
00566 #endif
00567
00568
00569
00570
00571
00572