2009-08-01 19:51:07 +03:00
|
|
|
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
2008-09-07 01:48:05 +03:00
|
|
|
/*
|
2009-08-01 19:51:07 +03:00
|
|
|
* LADI Session Handler (ladish)
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2011-09-10 03:35:48 +03:00
|
|
|
* Copyright (C) 2009,2010,2011 Nedko Arnaudov <nedko@arnaudov.name>
|
2009-08-01 19:51:07 +03:00
|
|
|
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-08-01 19:51:07 +03:00
|
|
|
**************************************************************************
|
|
|
|
* This file contains D-Bus signal helpers
|
|
|
|
**************************************************************************
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-09-05 00:11:33 +03:00
|
|
|
* Licensed under the Academic Free License version 2.1
|
|
|
|
*
|
2009-08-01 19:51:07 +03:00
|
|
|
* LADI Session Handler is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-08-01 19:51:07 +03:00
|
|
|
* LADI Session Handler is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
* or write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-09-07 01:48:05 +03:00
|
|
|
*/
|
|
|
|
|
2009-09-04 02:27:05 +03:00
|
|
|
#include "../common.h"
|
2008-09-07 01:48:05 +03:00
|
|
|
#include <stdarg.h>
|
2009-09-05 18:18:07 +03:00
|
|
|
#include "helpers.h"
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2011-09-10 03:35:48 +03:00
|
|
|
void cdbus_signal_send(DBusConnection * connection_ptr, DBusMessage * message_ptr)
|
2009-09-05 18:18:07 +03:00
|
|
|
{
|
2009-09-05 19:12:53 +03:00
|
|
|
if (!dbus_connection_send(connection_ptr, message_ptr, NULL))
|
2009-09-05 18:18:07 +03:00
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("Ran out of memory trying to queue signal");
|
2009-09-05 18:18:07 +03:00
|
|
|
}
|
|
|
|
|
2009-09-05 19:12:53 +03:00
|
|
|
dbus_connection_flush(connection_ptr);
|
2009-09-05 18:18:07 +03:00
|
|
|
}
|
2008-09-07 01:48:05 +03:00
|
|
|
|
|
|
|
void
|
2011-09-10 03:35:48 +03:00
|
|
|
cdbus_signal_emit(
|
2009-08-01 19:24:00 +03:00
|
|
|
DBusConnection * connection_ptr,
|
|
|
|
const char * path,
|
|
|
|
const char * interface,
|
|
|
|
const char * name,
|
2009-09-05 19:12:53 +03:00
|
|
|
const char * signature,
|
|
|
|
...)
|
2008-09-07 01:48:05 +03:00
|
|
|
{
|
2009-09-05 19:12:53 +03:00
|
|
|
DBusMessage * message_ptr;
|
|
|
|
va_list ap;
|
|
|
|
int type;
|
|
|
|
DBusSignatureIter sig_iter;
|
2009-07-13 00:15:44 +03:00
|
|
|
DBusMessageIter iter;
|
2009-09-05 19:12:53 +03:00
|
|
|
void * parameter_ptr;
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-09-20 18:23:42 +03:00
|
|
|
log_debug("Sending signal %s.%s from %s", interface, name, path);
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-09-05 19:12:53 +03:00
|
|
|
va_start(ap, signature);
|
|
|
|
|
2010-03-07 13:42:44 +02:00
|
|
|
ASSERT(signature != NULL);
|
|
|
|
|
|
|
|
if (!dbus_signature_validate(signature, NULL))
|
2009-09-05 19:12:53 +03:00
|
|
|
{
|
2010-03-07 13:42:44 +02:00
|
|
|
log_error("signature '%s' is invalid", signature);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_signature_iter_init(&sig_iter, signature);
|
|
|
|
|
|
|
|
message_ptr = dbus_message_new_signal(path, interface, name);
|
|
|
|
if (message_ptr == NULL)
|
|
|
|
{
|
|
|
|
log_error("dbus_message_new_signal() failed.");
|
|
|
|
goto exit;
|
|
|
|
}
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2010-03-07 13:42:44 +02:00
|
|
|
dbus_message_iter_init_append(message_ptr, &iter);
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2010-03-07 13:42:44 +02:00
|
|
|
while (*signature != '\0')
|
|
|
|
{
|
|
|
|
type = dbus_signature_iter_get_current_type(&sig_iter);
|
|
|
|
if (!dbus_type_is_basic(type))
|
2009-09-05 19:12:53 +03:00
|
|
|
{
|
2010-03-07 13:42:44 +02:00
|
|
|
log_error("non-basic input parameter '%c' (%d)", *signature, type);
|
|
|
|
goto unref;
|
2009-09-05 19:12:53 +03:00
|
|
|
}
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2010-03-07 13:42:44 +02:00
|
|
|
parameter_ptr = va_arg(ap, void *);
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2010-03-07 13:42:44 +02:00
|
|
|
if (!dbus_message_iter_append_basic(&iter, type, parameter_ptr))
|
2009-09-05 19:12:53 +03:00
|
|
|
{
|
2010-03-07 13:42:44 +02:00
|
|
|
log_error("dbus_message_iter_append_basic() failed.");
|
|
|
|
goto unref;
|
2009-07-13 00:15:44 +03:00
|
|
|
}
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2010-03-07 13:42:44 +02:00
|
|
|
dbus_signature_iter_next(&sig_iter);
|
|
|
|
signature++;
|
2009-07-13 00:15:44 +03:00
|
|
|
}
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2011-09-10 03:35:48 +03:00
|
|
|
cdbus_signal_send(connection_ptr, message_ptr);
|
2010-03-07 13:42:44 +02:00
|
|
|
|
|
|
|
unref:
|
|
|
|
dbus_message_unref(message_ptr);
|
|
|
|
|
2009-09-05 19:12:53 +03:00
|
|
|
exit:
|
|
|
|
va_end(ap);
|
2008-09-07 01:48:05 +03:00
|
|
|
}
|