1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
8 static const char introspection[] =
9 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
11 " <interface name=\"org.freedesktop.systemd1.Job\">"
12 " <property name=\"Id\" type=\"u\" access=\"read\"/>"
13 " <property name=\"Unit\" type=\"(so)\" access=\"read\"/>"
14 " <property name=\"Type\" type=\"s\" access=\"read\"/>"
15 " <property name=\"State\" type=\"s\" access=\"read\"/>"
17 BUS_PROPERTIES_INTERFACE
18 BUS_INTROSPECTABLE_INTERFACE
21 static int bus_job_append_state(Manager *m, DBusMessageIter *i, const char *property, void *data) {
30 state = job_state_to_string(j->state);
32 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
38 static int bus_job_append_type(Manager *m, DBusMessageIter *i, const char *property, void *data) {
47 type = job_type_to_string(j->type);
49 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &type))
55 static int bus_job_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) {
66 if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
69 if (!(p = unit_dbus_path(j->unit)))
72 id = unit_id(j->unit);
74 if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
75 !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p)) {
82 if (!dbus_message_iter_close_container(i, &sub))
88 static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusMessage *message) {
90 const BusProperty properties[] = {
91 { "org.freedesktop.systemd1.Job", "Id", bus_property_append_uint32, "u", &j->id },
92 { "org.freedesktop.systemd1.Job", "State", bus_job_append_state, "s", j },
93 { "org.freedesktop.systemd1.Job", "Type", bus_job_append_type, "s", j },
94 { "org.freedesktop.systemd1.Job", "Unit", bus_job_append_unit, "(so)", j },
95 { NULL, NULL, NULL, NULL, NULL }
98 return bus_default_message_handler(j->manager, message, introspection, properties);
101 DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
110 log_debug("Got D-Bus request: %s.%s() on %s",
111 dbus_message_get_interface(message),
112 dbus_message_get_member(message),
113 dbus_message_get_path(message));
115 if ((r = manager_get_job_from_dbus_path(m, dbus_message_get_path(message), &j)) < 0) {
118 return DBUS_HANDLER_RESULT_NEED_MEMORY;
121 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
123 return bus_send_error_reply(m, message, NULL, r);
126 return bus_job_message_dispatch(j, message);
129 const DBusObjectPathVTable bus_job_vtable = {
130 .message_function = bus_job_message_handler