1 | /* Copyright © 2005-2007 Roger Leigh <rleigh@debian.org> |
---|
2 | * |
---|
3 | * schroot is free software: you can redistribute it and/or modify it |
---|
4 | * under the terms of the GNU General Public License as published by |
---|
5 | * the Free Software Foundation, either version 3 of the License, or |
---|
6 | * (at your option) any later version. |
---|
7 | * |
---|
8 | * schroot is distributed in the hope that it will be useful, but |
---|
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
11 | * General Public License for more details. |
---|
12 | * |
---|
13 | * You should have received a copy of the GNU General Public License |
---|
14 | * along with this program. If not, see |
---|
15 | * <http://www.gnu.org/licenses/>. |
---|
16 | * |
---|
17 | *********************************************************************/ |
---|
18 | |
---|
19 | #ifndef SCHROOT_MAIN_BASE_H |
---|
20 | #define SCHROOT_MAIN_BASE_H |
---|
21 | |
---|
22 | #include <schroot-base/schroot-base-main.h> |
---|
23 | #include <schroot/schroot-options-base.h> |
---|
24 | |
---|
25 | #include <sbuild/sbuild-custom-error.h> |
---|
26 | |
---|
27 | namespace schroot |
---|
28 | { |
---|
29 | |
---|
30 | /** |
---|
31 | * Frontend base for schroot programs. This class is used to "run" |
---|
32 | * schroot programs. This class contains functionality common to |
---|
33 | * all schroot programs (schroot, dchroot, dchroot-dsa). |
---|
34 | */ |
---|
35 | class main_base : public schroot_base::main |
---|
36 | { |
---|
37 | public: |
---|
38 | /// Error codes. |
---|
39 | enum error_code |
---|
40 | { |
---|
41 | CHROOTS_NOTFOUND, ///< Chroots not found. |
---|
42 | CHROOT_FILE, ///< No chroots are defined in .... |
---|
43 | CHROOT_FILE2, ///< No chroots are defined in ... or .... |
---|
44 | CHROOT_NOTDEFINED, ///< The specified chroots are not defined. |
---|
45 | CHROOT_NOTFOUND ///< Chroot not found. |
---|
46 | }; |
---|
47 | |
---|
48 | /// Exception type. |
---|
49 | typedef sbuild::custom_error<error_code> error; |
---|
50 | |
---|
51 | /** |
---|
52 | * The constructor. |
---|
53 | * |
---|
54 | * @param program_name the program name. |
---|
55 | * @param program_usage the program usage message. |
---|
56 | * @param options the command-line options to use. |
---|
57 | * @param use_syslog whether to open a connection to the system |
---|
58 | * logger. |
---|
59 | */ |
---|
60 | main_base (std::string const& program_name, |
---|
61 | std::string const& program_usage, |
---|
62 | options_base::ptr& options, |
---|
63 | bool use_syslog); |
---|
64 | |
---|
65 | /// The destructor. |
---|
66 | virtual ~main_base (); |
---|
67 | |
---|
68 | virtual void |
---|
69 | action_version (std::ostream& stream); |
---|
70 | |
---|
71 | /** |
---|
72 | * List chroots. |
---|
73 | */ |
---|
74 | virtual void |
---|
75 | action_list () = 0; |
---|
76 | |
---|
77 | /** |
---|
78 | * Print detailed information about chroots. |
---|
79 | */ |
---|
80 | virtual void |
---|
81 | action_info (); |
---|
82 | |
---|
83 | /** |
---|
84 | * Print location of chroots. |
---|
85 | */ |
---|
86 | virtual void |
---|
87 | action_location (); |
---|
88 | |
---|
89 | /** |
---|
90 | * Dump configuration file for chroots. |
---|
91 | */ |
---|
92 | virtual void |
---|
93 | action_config () = 0; |
---|
94 | |
---|
95 | protected: |
---|
96 | /** |
---|
97 | * Run the program. This is the program-specific run method which |
---|
98 | * must be implemented in a derived class. |
---|
99 | * |
---|
100 | * @returns 0 on success, 1 on failure or the exit status of the |
---|
101 | * chroot command. |
---|
102 | */ |
---|
103 | virtual int |
---|
104 | run_impl (); |
---|
105 | |
---|
106 | /** |
---|
107 | * Get a list of chroots based on the specified options (--all, --chroot). |
---|
108 | * |
---|
109 | * @returns a list of chroots. |
---|
110 | */ |
---|
111 | virtual sbuild::string_list |
---|
112 | get_chroot_options (); |
---|
113 | |
---|
114 | /** |
---|
115 | * Check compatibility. Does nothing, but derived classes may use |
---|
116 | * it as they see fit. |
---|
117 | */ |
---|
118 | virtual void |
---|
119 | compat_check (); |
---|
120 | |
---|
121 | /** |
---|
122 | * Load configuration. |
---|
123 | */ |
---|
124 | virtual void |
---|
125 | load_config (); |
---|
126 | |
---|
127 | /** |
---|
128 | * Create a session. This sets the session member. |
---|
129 | * |
---|
130 | * @param sess_op the session operation to perform. |
---|
131 | */ |
---|
132 | virtual void |
---|
133 | create_session (sbuild::session::operation sess_op) = 0; |
---|
134 | |
---|
135 | protected: |
---|
136 | /// The program options. |
---|
137 | options_base::ptr options; |
---|
138 | /// The chroot configuration. |
---|
139 | sbuild::chroot_config::ptr config; |
---|
140 | /// The chroots to use. |
---|
141 | sbuild::string_list chroots; |
---|
142 | /// The session. |
---|
143 | sbuild::session::ptr session; |
---|
144 | }; |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | #endif /* SCHROOT_MAIN_BASE_H */ |
---|
149 | |
---|
150 | /* |
---|
151 | * Local Variables: |
---|
152 | * mode:C++ |
---|
153 | * End: |
---|
154 | */ |
---|