+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_state, job_state, JobState);
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_type, job_type, JobType);
+
+static int bus_job_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+ Job *j = data;
+ DBusMessageIter sub;
+ char *p;
+
+ assert(m);
+ assert(i);
+ assert(property);
+ assert(j);
+
+ if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
+ return -ENOMEM;
+
+ if (!(p = unit_dbus_path(j->unit)))
+ return -ENOMEM;
+
+ if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &j->unit->meta.id) ||
+ !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p)) {
+ free(p);
+ return -ENOMEM;
+ }
+
+ free(p);
+
+ if (!dbus_message_iter_close_container(i, &sub))
+ return -ENOMEM;
+
+ return 0;
+}
+
+static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusMessage *message) {
+ const BusProperty properties[] = {
+ { "org.freedesktop.systemd1.Job", "Id", bus_property_append_uint32, "u", &j->id },
+ { "org.freedesktop.systemd1.Job", "State", bus_job_append_state, "s", &j->state },
+ { "org.freedesktop.systemd1.Job", "JobType", bus_job_append_type, "s", &j->type },
+ { "org.freedesktop.systemd1.Job", "Unit", bus_job_append_unit, "(so)", j },
+ { NULL, NULL, NULL, NULL, NULL }
+ };
+
+ DBusMessage *reply = NULL;
+ Manager *m = j->manager;
+
+ if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Job", "Cancel")) {
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ job_free(j);
+
+ } else
+ return bus_default_message_handler(j->manager, message, introspection, properties);
+
+ if (reply) {
+ if (!dbus_connection_send(m->api_bus, reply, NULL))
+ goto oom;
+
+ dbus_message_unref(reply);
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+oom:
+ if (reply)
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
+static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {