summaryrefslogtreecommitdiff
path: root/src/dbus-job.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-07-05 00:58:07 +0200
committerLennart Poettering <lennart@poettering.net>2010-07-05 00:58:07 +0200
commita567261a29b4e19c0c195240411b7562063d99f8 (patch)
treeaf4c229fcb9b96520dad8941188c225c031bfb73 /src/dbus-job.c
parent552e4331bf165290eb02596355d9570c1ef9af47 (diff)
dbus: send signals about jobs to the clients having created them unconditionally, and thus get rid of broadcast signals in most cases
Diffstat (limited to 'src/dbus-job.c')
-rw-r--r--src/dbus-job.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/dbus-job.c b/src/dbus-job.c
index 48b1588dee..0956dcff6f 100644
--- a/src/dbus-job.c
+++ b/src/dbus-job.c
@@ -146,6 +146,32 @@ 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;
@@ -156,7 +182,7 @@ void bus_job_send_change_signal(Job *j) {
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;
}
@@ -182,7 +208,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 +234,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 +253,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);