X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fdbus-job.c;h=0f76c7d8433cb061e3f2e53dfedfc65e55c0cee5;hp=48b1588deea8b133c8343f9ef25187cbd643941a;hb=334d0069f5c5239a30329e370827cfe6f13de3ea;hpb=5e8d1c9a9f15b7453474dc4879bdb4021c3f50a1 diff --git a/src/dbus-job.c b/src/dbus-job.c index 48b1588de..0f76c7d84 100644 --- a/src/dbus-job.c +++ b/src/dbus-job.c @@ -1,4 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8 -*-*/ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ /*** This file is part of systemd. @@ -28,7 +28,6 @@ #define BUS_JOB_INTERFACE \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ @@ -40,11 +39,16 @@ "\n" \ BUS_JOB_INTERFACE \ BUS_PROPERTIES_INTERFACE \ + BUS_PEER_INTERFACE \ BUS_INTROSPECTABLE_INTERFACE \ "\n" const char bus_job_interface[] = BUS_JOB_INTERFACE; +#define INVALIDATING_PROPERTIES \ + "State\0" \ + "\0" \ + 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); @@ -123,11 +127,6 @@ static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBu assert(message); assert(m); - log_debug("Got D-Bus request: %s.%s() on %s", - dbus_message_get_interface(message), - dbus_message_get_member(message), - dbus_message_get_path(message)); - if ((r = manager_get_job_from_dbus_path(m, dbus_message_get_path(message), &j)) < 0) { if (r == -ENOMEM) @@ -146,17 +145,44 @@ const DBusObjectPathVTable bus_job_vtable = { .message_function = bus_job_message_handler }; +static int job_send_message(Job *j, DBusMessage *m) { + int r; + + assert(j); + assert(m); + + if (bus_has_subscriber(j->manager)) { + if ((r = bus_broadcast(j->manager, m)) < 0) + return r; + + } else if (j->bus_client) { + /* If nobody is subscribed, we just send the message + * to the client which created the job */ + + assert(j->bus); + + if (!dbus_message_set_destination(m, j->bus_client)) + return -ENOMEM; + + if (!dbus_connection_send(j->bus, m, NULL)) + return -ENOMEM; + } + + return 0; +} + void bus_job_send_change_signal(Job *j) { char *p = NULL; DBusMessage *m = NULL; assert(j); - assert(j->in_dbus_queue); - LIST_REMOVE(Job, dbus_queue, j->manager->dbus_job_queue, j); - j->in_dbus_queue = false; + if (j->in_dbus_queue) { + LIST_REMOVE(Job, dbus_queue, j->manager->dbus_job_queue, j); + j->in_dbus_queue = false; + } - if (set_isempty(j->manager->subscribed)) { + if (!bus_has_subscriber(j->manager) && !j->bus_client) { j->sent_dbus_new_signal = true; return; } @@ -165,10 +191,11 @@ void bus_job_send_change_signal(Job *j) { goto oom; if (j->sent_dbus_new_signal) { - /* Send a change signal */ + /* Send a properties changed signal */ - if (!(m = dbus_message_new_signal(p, "org.freedesktop.systemd1.Job", "Changed"))) + if (!(m = bus_properties_changed_new(p, "org.freedesktop.systemd1.Job", INVALIDATING_PROPERTIES))) goto oom; + } else { /* Send a new signal */ @@ -182,7 +209,7 @@ void bus_job_send_change_signal(Job *j) { goto oom; } - if (bus_broadcast(j->manager, m) < 0) + if (job_send_message(j, m) < 0) goto oom; free(p); @@ -208,7 +235,7 @@ void bus_job_send_removed_signal(Job *j, bool success) { assert(j); - if (set_isempty(j->manager->subscribed)) + if (!bus_has_subscriber(j->manager) && !j->bus_client) return; if (!j->sent_dbus_new_signal) @@ -227,7 +254,7 @@ void bus_job_send_removed_signal(Job *j, bool success) { DBUS_TYPE_INVALID)) goto oom; - if (bus_broadcast(j->manager, m) < 0) + if (job_send_message(j, m) < 0) goto oom; free(p);