systemadm.vala revision 26742b3fd8776c6c64e3c1035adc2599ddeb76d1
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
}
}
public class RightLabel : Label {
set_selectable(true);
}
set_markup("<i>n/a</i>");
else
}
set_markup("<i>n/a</i>");
else
}
}
public class MainWindow : Window {
private string? current_unit_id;
private uint32 current_job_id;
private ListStore unit_model;
private Button start_button;
private Button stop_button;
private Button restart_button;
private Button reload_button;
private Button cancel_button;
private Entry unit_load_entry;
private Button unit_load_button;
private Button server_snapshot_button;
private Button server_reload_button;
private RightLabel unit_id_label;
private RightLabel unit_aliases_label;
private RightLabel unit_dependency_label;
private RightLabel unit_description_label;
private RightLabel unit_load_state_label;
private RightLabel unit_active_state_label;
private RightLabel unit_sub_state_label;
private RightLabel unit_fragment_path_label;
private RightLabel unit_can_start_label;
private RightLabel unit_can_reload_label;
private RightLabel unit_cgroup_label;
private RightLabel job_id_label;
private RightLabel job_state_label;
private RightLabel job_type_label;
private ComboBox unit_type_combo_box;
public MainWindow() throws IOError {
set_border_width(12);
unit_load_entry = new Entry();
unit_load_button.set_sensitive(false);
unit_model = new ListStore(7, typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(Unit));
job_model = new ListStore(6, typeof(string), typeof(string), typeof(string), typeof(string), typeof(Job), typeof(uint32));
unit_id_label = new RightLabel();
unit_aliases_label = new RightLabel();
unit_dependency_label = new RightLabel();
unit_description_label = new RightLabel();
unit_load_state_label = new RightLabel();
unit_active_state_label = new RightLabel();
unit_sub_state_label = new RightLabel();
unit_fragment_path_label = new RightLabel();
unit_can_start_label = new RightLabel();
unit_can_reload_label = new RightLabel();
unit_cgroup_label = new RightLabel();
job_id_label = new RightLabel();
job_state_label = new RightLabel();
job_type_label = new RightLabel();
unit_dependency_label.set_selectable(false);
unit_table.attach(unit_id_label, 1, 6, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Aliases:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_aliases_label, 1, 6, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Description:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_description_label, 1, 6, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Dependencies:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_dependency_label, 1, 6, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Fragment Path:"), 0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_fragment_path_label, 1, 6, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Control Group:"), 0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_cgroup_label, 1, 6, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Load State:"), 0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_load_state_label, 1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Active State:"), 0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_active_state_label, 1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Unit State:"), 0, 1, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_sub_state_label, 1, 2, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Active Enter Timestamp:"), 2, 3, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_active_enter_timestamp_label, 3, 4, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Active Exit Timestamp:"), 2, 3, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_active_exit_timestamp_label, 3, 4, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Can Start/Stop:"), 4, 5, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_can_start_label, 5, 6, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Can Reload:"), 4, 5, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_can_reload_label, 5, 6, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
job_table.attach(job_id_label, 1, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
job_table.attach(new LeftLabel("State:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
job_table.attach(job_state_label, 1, 2, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
job_table.attach(job_type_label, 1, 2, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
bbox = new HButtonBox();
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1");
clear_unit();
clear_job();
}
public void populate_unit_model() throws IOError {
unit_model.clear();
"org.freedesktop.systemd1",
i.unit_path);
"org.freedesktop.systemd1",
i.unit_path);
0, i.id,
1, i.description,
2, i.load_state,
3, i.active_state,
4, i.sub_state,
6, u);
}
}
public void populate_job_model() throws IOError {
"org.freedesktop.systemd1",
i.job_path);
"org.freedesktop.systemd1",
i.job_path);
1, i.name,
3, i.state,
4, j,
5, i.id);
}
}
public Unit? get_current_unit() {
TreePath p;
if (p == null)
return null;
Unit u;
return u;
}
public void unit_changed() {
Unit u = get_current_unit();
if (u == null)
clear_unit();
else
show_unit(u);
}
public void clear_unit() {
start_button.set_sensitive(false);
stop_button.set_sensitive(false);
reload_button.set_sensitive(false);
restart_button.set_sensitive(false);
}
string r;
r = "";
else
r = prefix;
if (r != "")
if (first) {
r += word;
first = false;
}
r += " <a href=\"" + i + "\">" + i + "</a>";
}
return r;
}
string a = "";
if (i == current_unit_id)
continue;
if (a == "")
a = i;
else
a += "\n" + i;
}
string[]
"requires", requires),
"overridable requires", requires_overridable),
"requisite", requisite),
"overridable requisite", requisite_overridable),
"wants", wants),
"conflicts", conflicts),
"required by", required_by),
"overridable required by", required_by_overridable),
"wanted by", wanted_by),
"after", after),
"before", before));
if (fp != "")
else
if (t > 0) {
} else
if (t > 0) {
} else
b = unit.can_reload;
}
public Job? get_current_job() {
TreePath p;
if (p == null)
return null;
Job *j;
return j;
}
public void job_changed() {
Job j = get_current_job();
if (j == null)
clear_job();
else
show_job(j);
}
public void clear_job() {
current_job_id = 0;
cancel_button.set_sensitive(false);
}
cancel_button.set_sensitive(true);
}
public void on_start() {
Unit u = get_current_unit();
if (u == null)
return;
try {
u.start("replace");
} catch (IOError e) {
show_error(e.message);
}
}
public void on_stop() {
Unit u = get_current_unit();
if (u == null)
return;
try {
u.stop("replace");
} catch (IOError e) {
show_error(e.message);
}
}
public void on_reload() {
Unit u = get_current_unit();
if (u == null)
return;
try {
u.reload("replace");
} catch (IOError e) {
show_error(e.message);
}
}
public void on_restart() {
Unit u = get_current_unit();
if (u == null)
return;
try {
u.restart("replace");
} catch (IOError e) {
show_error(e.message);
}
}
public void on_cancel() {
Job j = get_current_job();
if (j == null)
return;
try {
j.cancel();
} catch (IOError e) {
show_error(e.message);
}
}
try {
string t = "";
"org.freedesktop.systemd1",
t = j.job_type;
}
0, id,
1, u.description,
2, u.load_state,
3, u.active_state,
4, u.sub_state,
6, u);
} catch (IOError e) {
show_error(e.message);
}
}
try {
"org.freedesktop.systemd1",
path);
"org.freedesktop.systemd1",
path);
} catch (IOError e) {
show_error(e.message);
}
}
3, j.state,
4, j,
5, id);
}
try {
"org.freedesktop.systemd1",
path);
"org.freedesktop.systemd1",
path);
} catch (IOError e) {
show_error(e.message);
}
}
return;
do {
if (current_unit_id == name)
clear_unit();
break;
}
}
return;
do {
uint32 j;
if (id == j) {
if (current_job_id == j)
clear_job();
break;
}
}
public void on_unit_changed(Properties p, string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties) {
try {
p.get_name(),
p.get_object_path());
return;
do {
if (current_unit_id == id)
show_unit(u);
break;
}
} catch (IOError e) {
show_error(e.message);
}
}
public void on_job_changed(Properties p, string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties) {
try {
p.get_name(),
p.get_object_path());
return;
do {
uint32 k;
if (id == k) {
if (current_job_id == id)
show_job(j);
break;
}
} catch (IOError e) {
show_error(e.message);
}
}
return false;
switch (unit_type_combo_box.get_active()) {
case 0:
return true;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
}
return false;
}
public void unit_type_changed() {
}
public void on_server_reload() {
try {
} catch (IOError e) {
show_error(e.message);
}
}
public void on_server_snapshot() {
try {
} catch (IOError e) {
show_error(e.message);
}
}
public void on_unit_load() {
if (t == "")
return;
try {
"org.freedesktop.systemd1",
path);
var m = new MessageDialog(this,
"Unit available as id %s", u.id);
m.title = "Unit";
m.run();
m.destroy();
show_unit(u);
} catch (IOError e) {
show_error(e.message);
}
}
public void on_unit_load_entry_changed() {
}
try {
"org.freedesktop.systemd1",
path);
show_unit(u);
} catch (IOError e) {
show_error(e.message);
}
return true;
}
public void show_error(string e) {
var m = new MessageDialog(this,
m.title = "Error";
m.run();
m.destroy();
}
}
static const OptionEntry entries[] = {
{ null }
};
void show_error(string e) {
m.run();
m.destroy();
}
try {
} catch (IOError e) {
show_error(e.message);
show_error(e.message);
}
return 0;
}