using Gtk;
using GLib;
-using DBus;
using Pango;
static bool user = false;
private Button server_snapshot_button;
private Button server_reload_button;
- private Connection bus;
private Manager manager;
private RightLabel unit_id_label;
private ComboBox unit_type_combo_box;
- public MainWindow() throws DBus.Error {
+ public MainWindow() throws IOError {
title = user ? "systemd User Service Manager" : "systemd System Manager";
- position = WindowPosition.CENTER;
+ set_position(WindowPosition.CENTER);
set_default_size(1000, 700);
set_border_width(12);
destroy.connect(Gtk.main_quit);
bbox.pack_start(cancel_button, false, true, 0);
- bus = DBus.Bus.get(user ? DBus.BusType.SESSION : DBus.BusType.SYSTEM);
-
- manager = bus.get_object(
+ manager = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager") as Manager;
+ "/org/freedesktop/systemd1");
manager.unit_new.connect(on_unit_new);
manager.job_new.connect(on_job_new);
populate_job_model();
}
- public void populate_unit_model() throws DBus.Error {
+ public void populate_unit_model() throws IOError {
unit_model.clear();
var list = manager.list_units();
foreach (var i in list) {
TreeIter iter;
- Properties p = bus.get_object(
+ Properties p = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- i.unit_path,
- "org.freedesktop.DBus.Properties") as Properties;
-
+ i.unit_path);
p.properties_changed.connect(on_unit_changed);
- Unit u = bus.get_object(
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- i.unit_path,
- "org.freedesktop.systemd1.Unit") as Unit;
+ i.unit_path);
unit_model.append(out iter);
unit_model.set(iter,
}
}
- public void populate_job_model() throws DBus.Error {
+ public void populate_job_model() throws IOError {
job_model.clear();
var list = manager.list_jobs();
foreach (var i in list) {
TreeIter iter;
- Properties p = bus.get_object(
+ Properties p = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- i.job_path,
- "org.freedesktop.DBus.Properties") as Properties;
+ i.job_path);
p.properties_changed.connect(on_job_changed);
- Job j = bus.get_object(
+ Job j = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- i.job_path,
- "org.freedesktop.systemd1.Job") as Job;
+ i.job_path);
job_model.append(out iter);
job_model.set(iter,
try {
u.start("replace");
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
u.stop("replace");
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
u.reload("replace");
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
u.restart("replace");
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
j.cancel();
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
public void update_unit_iter(TreeIter iter, string id, Unit u) {
- string t = "";
- Unit.JobLink jl = u.job;
+ try {
+ string t = "";
+ Unit.JobLink jl = u.job;
- if (jl.id != 0) {
- Job j = bus.get_object(
- "org.freedesktop.systemd1",
- jl.path,
- "org.freedesktop.systemd1.Job") as Job;
+ if (jl.id != 0) {
+ Job j = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ jl.path);
- t = j.job_type;
- }
+ t = j.job_type;
+ }
- unit_model.set(iter,
- 0, id,
- 1, u.description,
- 2, u.load_state,
- 3, u.active_state,
- 4, u.sub_state,
- 5, t != "" ? "→ %s".printf(t) : "",
- 6, u);
+ unit_model.set(iter,
+ 0, id,
+ 1, u.description,
+ 2, u.load_state,
+ 3, u.active_state,
+ 4, u.sub_state,
+ 5, t != "" ? "→ %s".printf(t) : "",
+ 6, u);
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public void on_unit_new(string id, ObjectPath path) {
- Properties p = bus.get_object(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.DBus.Properties") as Properties;
+ try {
- p.properties_changed.connect(on_unit_changed);
+ Properties p = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ path);
- TreeIter iter;
- unit_model.append(out iter);
+ p.properties_changed.connect(on_unit_changed);
- Unit u = bus.get_object(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.systemd1.Unit") as Unit;
+ TreeIter iter;
+ unit_model.append(out iter);
+
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ path);
- update_unit_iter(iter, id, u);
+ update_unit_iter(iter, id, u);
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public void update_job_iter(TreeIter iter, uint32 id, Job j) {
public void on_job_new(uint32 id, ObjectPath path) {
- Properties p = bus.get_object(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.DBus.Properties") as Properties;
+ try {
- p.properties_changed.connect(on_job_changed);
+ Properties p = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ path);
- TreeIter iter;
- job_model.append(out iter);
+ p.properties_changed.connect(on_job_changed);
- Job j = bus.get_object(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.systemd1.Job") as Job;
+ TreeIter iter;
+ job_model.append(out iter);
+
+ Job j = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ path);
+
+ update_job_iter(iter, id, j);
- update_job_iter(iter, id, j);
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public void on_unit_removed(string id, ObjectPath path) {
}
public void on_unit_changed(Properties p, string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties) {
- TreeIter iter;
- string id;
- Unit u = bus.get_object(
- p.get_bus_name(),
- p.get_path(),
- "org.freedesktop.systemd1.Unit") as Unit;
+ try {
+ TreeIter iter;
+ string id;
- if (!(unit_model.get_iter_first(out iter)))
- return;
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ p.get_name(),
+ p.get_object_path());
- id = u.id;
+ if (!(unit_model.get_iter_first(out iter)))
+ return;
- do {
- string name;
+ id = u.id;
- unit_model.get(iter, 0, out name);
+ do {
+ string name;
- if (id == name) {
- update_unit_iter(iter, id, u);
+ unit_model.get(iter, 0, out name);
- if (current_unit_id == id)
- show_unit(u);
+ if (id == name) {
+ update_unit_iter(iter, id, u);
- break;
- }
+ if (current_unit_id == id)
+ show_unit(u);
- } while (unit_model.iter_next(ref iter));
+ break;
+ }
+
+ } while (unit_model.iter_next(ref iter));
+
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public void on_job_changed(Properties p, string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties) {
- TreeIter iter;
- uint32 id;
+ try {
+ TreeIter iter;
+ uint32 id;
- Job j = bus.get_object(
- p.get_bus_name(),
- p.get_path(),
- "org.freedesktop.systemd1.Job") as Job;
+ Job j = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ p.get_name(),
+ p.get_object_path());
- if (!(job_model.get_iter_first(out iter)))
- return;
+ if (!(job_model.get_iter_first(out iter)))
+ return;
- id = j.id;
+ id = j.id;
- do {
- uint32 k;
+ do {
+ uint32 k;
- job_model.get(iter, 5, out k);
+ job_model.get(iter, 5, out k);
- if (id == k) {
- update_job_iter(iter, id, j);
+ if (id == k) {
+ update_job_iter(iter, id, j);
- if (current_job_id == id)
- show_job(j);
+ if (current_job_id == id)
+ show_job(j);
- break;
- }
+ break;
+ }
- } while (job_model.iter_next(ref iter));
+ } while (job_model.iter_next(ref iter));
+
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public bool unit_filter(TreeModel model, TreeIter iter) {
public void on_server_reload() {
try {
manager.reload();
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
if (unit_type_combo_box.get_active() != 0)
unit_type_combo_box.set_active(8);
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
var path = manager.load_unit(t);
- Unit u = bus.get_object(
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- path,
- "org.freedesktop.systemd1.Unit") as Unit;
+ path);
var m = new MessageDialog(this,
DialogFlags.DESTROY_WITH_PARENT,
m.destroy();
show_unit(u);
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
string path = manager.get_unit(uri);
- Unit u = bus.get_object(
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- path,
- "org.freedesktop.systemd1.Unit") as Unit;
+ path);
show_unit(u);
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
window.show_all();
Gtk.main();
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
} catch (GLib.Error e) {
show_error(e.message);
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-using DBus;
-
[DBus (name = "org.freedesktop.systemd1.Manager")]
-public interface Manager : DBus.Object {
+public interface Manager : DBusProxy {
public struct UnitInfo {
string id;
public abstract string[] environment { owned get; }
- public abstract UnitInfo[] list_units() throws DBus.Error;
- public abstract JobInfo[] list_jobs() throws DBus.Error;
+ public abstract UnitInfo[] list_units() throws IOError;
+ public abstract JobInfo[] list_jobs() throws IOError;
- public abstract ObjectPath get_unit(string name) throws DBus.Error;
- public abstract ObjectPath get_unit_by_pid(uint32 pid) throws DBus.Error;
- public abstract ObjectPath load_unit(string name) throws DBus.Error;
- public abstract ObjectPath get_job(uint32 id) throws DBus.Error;
+ public abstract ObjectPath get_unit(string name) throws IOError;
+ public abstract ObjectPath get_unit_by_pid(uint32 pid) throws IOError;
+ public abstract ObjectPath load_unit(string name) throws IOError;
+ public abstract ObjectPath get_job(uint32 id) throws IOError;
- public abstract ObjectPath start_unit(string name, string mode = "replace") throws DBus.Error;
- public abstract ObjectPath stop_unit(string name, string mode = "replace") throws DBus.Error;
- public abstract ObjectPath reload_unit(string name, string mode = "replace") throws DBus.Error;
- public abstract ObjectPath restart_unit(string name, string mode = "replace") throws DBus.Error;
- public abstract ObjectPath try_restart_unit(string name, string mode = "replace") throws DBus.Error;
- public abstract ObjectPath reload_or_restart_unit(string name, string mode = "replace") throws DBus.Error;
- public abstract ObjectPath reload_or_try_restart_unit(string name, string mode = "replace") throws DBus.Error;
+ public abstract ObjectPath start_unit(string name, string mode = "replace") throws IOError;
+ public abstract ObjectPath stop_unit(string name, string mode = "replace") throws IOError;
+ public abstract ObjectPath reload_unit(string name, string mode = "replace") throws IOError;
+ public abstract ObjectPath restart_unit(string name, string mode = "replace") throws IOError;
+ public abstract ObjectPath try_restart_unit(string name, string mode = "replace") throws IOError;
+ public abstract ObjectPath reload_or_restart_unit(string name, string mode = "replace") throws IOError;
+ public abstract ObjectPath reload_or_try_restart_unit(string name, string mode = "replace") throws IOError;
- public abstract void reset_failed_unit(string name = "") throws DBus.Error;
+ public abstract void reset_failed_unit(string name = "") throws IOError;
- public abstract void clear_jobs() throws DBus.Error;
+ public abstract void clear_jobs() throws IOError;
- public abstract void subscribe() throws DBus.Error;
- public abstract void unsubscribe() throws DBus.Error;
+ public abstract void subscribe() throws IOError;
+ public abstract void unsubscribe() throws IOError;
- public abstract string dump() throws DBus.Error;
+ public abstract string dump() throws IOError;
- public abstract void reload() throws DBus.Error;
- public abstract void reexecute() throws DBus.Error;
- public abstract void exit() throws DBus.Error;
- public abstract void halt() throws DBus.Error;
- public abstract void power_off() throws DBus.Error;
- public abstract void reboot() throws DBus.Error;
- public abstract void kexec() throws DBus.Error;
+ public abstract void reload() throws IOError;
+ public abstract void reexecute() throws IOError;
+ public abstract void exit() throws IOError;
+ public abstract void halt() throws IOError;
+ public abstract void power_off() throws IOError;
+ public abstract void reboot() throws IOError;
+ public abstract void kexec() throws IOError;
- public abstract ObjectPath create_snapshot(string name = "", bool cleanup = false) throws DBus.Error;
+ public abstract ObjectPath create_snapshot(string name = "", bool cleanup = false) throws IOError;
- public abstract void set_environment(string[] names) throws DBus.Error;
- public abstract void unset_environment(string[] names) throws DBus.Error;
+ public abstract void set_environment(string[] names) throws IOError;
+ public abstract void unset_environment(string[] names) throws IOError;
public abstract signal void unit_new(string id, ObjectPath path);
public abstract signal void unit_removed(string id, ObjectPath path);
}
[DBus (name = "org.freedesktop.systemd1.Unit")]
-public interface Unit : DBus.Object {
+public interface Unit : DBusProxy {
public struct JobLink {
uint32 id;
ObjectPath path;
public abstract bool need_daemon_reload { owned get; }
public abstract uint64 job_timeout_usec { owned get; }
- public abstract ObjectPath start(string mode = "replace") throws DBus.Error;
- public abstract ObjectPath stop(string mode = "replace") throws DBus.Error;
- public abstract ObjectPath reload(string mode = "replace") throws DBus.Error;
- public abstract ObjectPath restart(string mode = "replace") throws DBus.Error;
- public abstract ObjectPath try_restart(string mode = "replace") throws DBus.Error;
- public abstract ObjectPath reload_or_restart(string mode = "replace") throws DBus.Error;
- public abstract ObjectPath reload_or_try_restart(string mode = "replace") throws DBus.Error;
+ public abstract ObjectPath start(string mode = "replace") throws IOError;
+ public abstract ObjectPath stop(string mode = "replace") throws IOError;
+ public abstract ObjectPath reload(string mode = "replace") throws IOError;
+ public abstract ObjectPath restart(string mode = "replace") throws IOError;
+ public abstract ObjectPath try_restart(string mode = "replace") throws IOError;
+ public abstract ObjectPath reload_or_restart(string mode = "replace") throws IOError;
+ public abstract ObjectPath reload_or_try_restart(string mode = "replace") throws IOError;
- public abstract void reset_failed() throws DBus.Error;
+ public abstract void reset_failed() throws IOError;
}
[DBus (name = "org.freedesktop.systemd1.Job")]
-public interface Job : DBus.Object {
+public interface Job : DBusProxy {
public struct UnitLink {
string id;
ObjectPath path;
public abstract string job_type { owned get; }
public abstract UnitLink unit { owned get; }
- public abstract void cancel() throws DBus.Error;
+ public abstract void cancel() throws IOError;
}
-[DBus (name = "org.freedesktop.DBus.Properties")]
-public interface Properties : DBus.Object {
- public abstract Value? get(string iface, string property) throws DBus.Error;
- public abstract signal void properties_changed(string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties);
+[DBus (name = "org.freedesktop.Properties")]
+public interface Properties : DBusProxy {
+ public abstract Variant? get(string iface, string property) throws IOError;
+ public abstract signal void properties_changed(string iface, HashTable<string, Variant?> changed_properties, string[] invalidated_properties);
}