Fix more warnings
[lash.git] / dbus / signal.c
blob3d47370b96d9f6f99e8ea69db8ff96ccf029a52e
1 /*
2 * LASH
4 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdarg.h>
23 #include "common/debug.h"
24 #include "dbus/signal.h"
25 #include "dbus/service.h"
27 static void
28 signal_send(signal_msg_t *signal);
30 void
31 signal_new_single(service_t *service,
32 const char *path,
33 const char *interface,
34 const char *name,
35 int type,
36 const void *arg)
38 signal_msg_t signal;
39 DBusMessageIter iter;
41 lash_debug("Sending signal %s.%s from %s", interface, name, path);
43 if ((signal.message = dbus_message_new_signal(path, interface, name))) {
44 dbus_message_iter_init_append(signal.message, &iter);
45 if (dbus_message_iter_append_basic(&iter, type, arg)) {
46 signal.connection = service->connection;
47 signal_send(&signal);
48 } else {
49 lash_error("Ran out of memory trying to append signal argument");
52 dbus_message_unref(signal.message);
53 signal.message = NULL;
55 return;
58 lash_error("Ran out of memory trying to create new signal");
61 void
62 signal_new_valist (service_t *service,
63 const char *path,
64 const char *interface,
65 const char *name,
66 int type,
67 ...)
69 signal_msg_t signal;
70 va_list argp;
72 lash_debug("Sending signal %s.%s from %s", interface, name, path);
74 if ((signal.message = dbus_message_new_signal (path, interface, name))) {
75 va_start(argp, type);
76 if (dbus_message_append_args_valist(signal.message, type, argp)) {
77 signal.connection = service->connection;
78 signal_send(&signal);
79 } else {
80 lash_error("Ran out of memory trying to append signal argument(s)");
82 va_end(argp);
84 dbus_message_unref(signal.message);
85 signal.message = NULL;
87 return;
90 lash_error("Ran out of memory trying to create new signal");
93 static void
94 signal_send(signal_msg_t *signal)
96 if (!dbus_connection_send(signal->connection, signal->message, NULL)) {
97 lash_error("Ran out of memory trying to queue signal");
100 dbus_connection_flush(signal->connection);
103 /* EOF */