daemon: remove lash legacy code
[ladish.git] / dbus / signal.c
blobcaa838962b54630d3de5d5df4ba777ce635a0bbd
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
8 **************************************************************************
9 * This file contains D-Bus signal helpers
10 **************************************************************************
12 * Licensed under the Academic Free License version 2.1
14 * LADI Session Handler is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * LADI Session Handler is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
26 * or write to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "../common.h"
31 #include <stdarg.h>
32 #include "helpers.h"
34 static void dbus_signal_send(DBusConnection * connection_ptr, DBusMessage * message_ptr)
36 if (!dbus_connection_send(connection_ptr, message_ptr, NULL))
38 log_error("Ran out of memory trying to queue signal");
41 dbus_connection_flush(connection_ptr);
44 void
45 dbus_signal_emit(
46 DBusConnection * connection_ptr,
47 const char * path,
48 const char * interface,
49 const char * name,
50 const char * signature,
51 ...)
53 DBusMessage * message_ptr;
54 va_list ap;
55 int type;
56 DBusSignatureIter sig_iter;
57 DBusMessageIter iter;
58 void * parameter_ptr;
60 log_debug("Sending signal %s.%s from %s", interface, name, path);
62 va_start(ap, signature);
64 if (signature != NULL)
66 if (!dbus_signature_validate(signature, NULL))
68 log_error("signature '%s' is invalid", signature);
69 goto exit;
72 dbus_signature_iter_init(&sig_iter, signature);
74 message_ptr = dbus_message_new_signal(path, interface, name);
75 if (message_ptr == NULL)
77 log_error("dbus_message_new_signal() failed.");
78 goto exit;
81 dbus_message_iter_init_append(message_ptr, &iter);
83 while (*signature != '\0')
85 type = dbus_signature_iter_get_current_type(&sig_iter);
86 if (!dbus_type_is_basic(type))
88 log_error("non-basic input parameter '%c' (%d)", *signature, type);
89 goto unref;
92 parameter_ptr = va_arg(ap, void *);
94 if (!dbus_message_iter_append_basic(&iter, type, parameter_ptr))
96 log_error("dbus_message_iter_append_basic() failed.");
97 goto unref;
100 dbus_signature_iter_next(&sig_iter);
101 signature++;
104 dbus_signal_send(connection_ptr, message_ptr);
106 unref:
107 dbus_message_unref(message_ptr);
109 else
111 message_ptr = va_arg(ap, DBusMessage *);
112 dbus_signal_send(connection_ptr, message_ptr);
115 exit:
116 va_end(ap);