2008-04-24 17:45:30 +02:00
|
|
|
/*
|
|
|
|
* dbus.c - awesome dbus support
|
|
|
|
*
|
2009-09-07 17:28:55 +02:00
|
|
|
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
|
2008-04-24 17:45:30 +02:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
2008-11-19 02:22:05 +01:00
|
|
|
|
2009-09-07 17:28:55 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
#include "dbus.h"
|
2008-05-30 21:20:23 +02:00
|
|
|
|
2008-06-16 23:48:07 +02:00
|
|
|
#ifdef WITH_DBUS
|
2008-04-24 17:45:30 +02:00
|
|
|
|
2008-06-16 23:32:20 +02:00
|
|
|
#include <ev.h>
|
2008-04-24 17:45:30 +02:00
|
|
|
#include <dbus/dbus.h>
|
2008-08-27 10:00:10 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2008-04-24 17:45:30 +02:00
|
|
|
|
2009-04-09 15:11:00 +02:00
|
|
|
#include "event.h"
|
2009-07-29 16:10:29 +02:00
|
|
|
#include "luaa.h"
|
2008-04-24 17:45:30 +02:00
|
|
|
|
2009-04-18 16:07:31 +02:00
|
|
|
static DBusConnection *dbus_connection_session = NULL;
|
|
|
|
static DBusConnection *dbus_connection_system = NULL;
|
|
|
|
ev_io dbusio_ses = { .fd = -1 };
|
|
|
|
ev_io dbusio_sys = { .fd = -1 };
|
2008-04-24 17:45:30 +02:00
|
|
|
|
2009-07-29 16:10:29 +02:00
|
|
|
static signal_array_t dbus_signals;
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Clean up the D-Bus connection data members
|
|
|
|
* \param dbus_connection The D-Bus connection to clean up
|
|
|
|
* \param dbusio The D-Bus event watcher
|
|
|
|
*/
|
2009-04-27 14:54:09 +02:00
|
|
|
static void
|
|
|
|
a_dbus_cleanup_bus(DBusConnection *dbus_connection, ev_io *dbusio)
|
|
|
|
{
|
|
|
|
if(!dbus_connection)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(dbusio->fd >= 0)
|
|
|
|
{
|
|
|
|
ev_ref(EV_DEFAULT_UC);
|
|
|
|
ev_io_stop(EV_DEFAULT_UC_ dbusio);
|
|
|
|
dbusio->fd = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is a shared connection owned by libdbus
|
|
|
|
* Do not close it, only unref
|
|
|
|
*/
|
|
|
|
dbus_connection_unref(dbus_connection);
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Iterate through the D-Bus messages counting each or traverse each sub message.
|
|
|
|
* \param iter The D-Bus message iterator pointer
|
|
|
|
* \return The number of arguments in the iterator
|
|
|
|
*/
|
2008-11-19 02:22:05 +01:00
|
|
|
static int
|
|
|
|
a_dbus_message_iter(DBusMessageIter *iter)
|
2008-07-08 10:54:57 +02:00
|
|
|
{
|
2008-11-19 02:22:05 +01:00
|
|
|
int nargs = 0;
|
2008-07-08 10:54:57 +02:00
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
switch(dbus_message_iter_get_arg_type(iter))
|
|
|
|
{
|
2009-03-10 09:17:00 +01:00
|
|
|
default:
|
|
|
|
lua_pushnil(globalconf.L);
|
|
|
|
nargs++;
|
|
|
|
break;
|
2008-11-19 02:22:05 +01:00
|
|
|
case DBUS_TYPE_INVALID:
|
|
|
|
break;
|
|
|
|
case DBUS_TYPE_VARIANT:
|
|
|
|
{
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
dbus_message_iter_recurse(iter, &subiter);
|
|
|
|
a_dbus_message_iter(&subiter);
|
|
|
|
}
|
|
|
|
nargs++;
|
|
|
|
break;
|
|
|
|
case DBUS_TYPE_DICT_ENTRY:
|
|
|
|
{
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
|
|
|
|
/* initialize a sub iterator */
|
|
|
|
dbus_message_iter_recurse(iter, &subiter);
|
|
|
|
/* create a new table to store the dict */
|
|
|
|
a_dbus_message_iter(&subiter);
|
|
|
|
}
|
|
|
|
nargs++;
|
|
|
|
break;
|
2009-03-11 16:19:30 +01:00
|
|
|
case DBUS_TYPE_STRUCT:
|
|
|
|
{
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
/* initialize a sub iterator */
|
|
|
|
dbus_message_iter_recurse(iter, &subiter);
|
2009-04-25 15:04:27 +02:00
|
|
|
|
2009-03-11 16:19:30 +01:00
|
|
|
int n = a_dbus_message_iter(&subiter);
|
|
|
|
|
2009-04-25 15:04:27 +02:00
|
|
|
/* create a new table to store all the value */
|
|
|
|
lua_createtable(globalconf.L, n, 0);
|
|
|
|
/* move the table before array elements */
|
|
|
|
lua_insert(globalconf.L, - n - 1);
|
|
|
|
|
2009-03-11 16:19:30 +01:00
|
|
|
for(int i = n; i > 0; i--)
|
|
|
|
lua_rawseti(globalconf.L, - i - 1, i);
|
|
|
|
}
|
|
|
|
nargs++;
|
|
|
|
break;
|
2008-11-19 02:22:05 +01:00
|
|
|
case DBUS_TYPE_ARRAY:
|
|
|
|
{
|
|
|
|
int array_type = dbus_message_iter_get_element_type(iter);
|
|
|
|
|
|
|
|
if(dbus_type_is_fixed(array_type))
|
2009-03-11 16:17:05 +01:00
|
|
|
{
|
|
|
|
DBusMessageIter sub;
|
|
|
|
dbus_message_iter_recurse(iter, &sub);
|
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
switch(array_type)
|
|
|
|
{
|
2009-03-11 16:17:05 +01:00
|
|
|
int datalen = 0;
|
2008-11-19 02:22:05 +01:00
|
|
|
#define DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER(type, dbustype) \
|
|
|
|
case dbustype: \
|
|
|
|
{ \
|
2009-03-11 16:19:40 +01:00
|
|
|
const type *data; \
|
2009-03-11 16:17:05 +01:00
|
|
|
dbus_message_iter_get_fixed_array(&sub, &data, &datalen); \
|
2009-04-25 15:04:27 +02:00
|
|
|
lua_createtable(globalconf.L, datalen, 0); \
|
2008-11-19 02:22:05 +01:00
|
|
|
for(int i = 0; i < datalen; i++) \
|
|
|
|
{ \
|
|
|
|
lua_pushnumber(globalconf.L, data[i]); \
|
|
|
|
lua_rawseti(globalconf.L, -2, i + 1); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER(int16_t, DBUS_TYPE_INT16)
|
|
|
|
DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER(uint16_t, DBUS_TYPE_UINT16)
|
|
|
|
DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER(int32_t, DBUS_TYPE_INT32)
|
|
|
|
DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER(uint32_t, DBUS_TYPE_UINT32)
|
|
|
|
DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER(int64_t, DBUS_TYPE_INT64)
|
|
|
|
DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER(uint64_t, DBUS_TYPE_UINT64)
|
2009-03-11 16:20:11 +01:00
|
|
|
DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER(double, DBUS_TYPE_DOUBLE)
|
2008-11-19 02:22:05 +01:00
|
|
|
#undef DBUS_MSG_HANDLE_ARRAY_TYPE_NUMBER
|
2009-03-11 16:19:40 +01:00
|
|
|
case DBUS_TYPE_BYTE:
|
|
|
|
{
|
|
|
|
const char *c;
|
|
|
|
dbus_message_iter_get_fixed_array(&sub, &c, &datalen);
|
|
|
|
lua_pushlstring(globalconf.L, c, datalen);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-11 16:22:21 +01:00
|
|
|
case DBUS_TYPE_BOOLEAN:
|
|
|
|
{
|
2009-04-28 22:40:02 +02:00
|
|
|
const dbus_bool_t *b;
|
2009-03-11 16:22:21 +01:00
|
|
|
dbus_message_iter_get_fixed_array(&sub, &b, &datalen);
|
2009-04-25 15:04:27 +02:00
|
|
|
lua_createtable(globalconf.L, datalen, 0);
|
2009-03-11 16:22:21 +01:00
|
|
|
for(int i = 0; i < datalen; i++)
|
|
|
|
{
|
|
|
|
lua_pushboolean(globalconf.L, b[i]);
|
|
|
|
lua_rawseti(globalconf.L, -2, i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-11-19 02:22:05 +01:00
|
|
|
}
|
2009-03-11 16:17:05 +01:00
|
|
|
}
|
2008-11-19 02:22:05 +01:00
|
|
|
else if(array_type == DBUS_TYPE_DICT_ENTRY)
|
|
|
|
{
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
/* initialize a sub iterator */
|
|
|
|
dbus_message_iter_recurse(iter, &subiter);
|
2009-04-25 15:04:27 +02:00
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
/* get the keys and the values
|
2009-04-25 15:04:27 +02:00
|
|
|
* n is the number of entry in dict */
|
2008-11-19 02:22:05 +01:00
|
|
|
int n = a_dbus_message_iter(&subiter);
|
|
|
|
|
2009-04-25 15:04:27 +02:00
|
|
|
/* create a new table to store all the value */
|
|
|
|
lua_createtable(globalconf.L, n, 0);
|
|
|
|
/* move the table before array elements */
|
|
|
|
lua_insert(globalconf.L, - (n * 2) - 1);
|
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
for(int i = 0; i < n; i ++)
|
|
|
|
lua_rawset(globalconf.L, - (n * 2) - 1 + i * 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
/* prepare to dig into the array*/
|
|
|
|
dbus_message_iter_recurse(iter, &subiter);
|
|
|
|
|
|
|
|
/* now iterate over every element of the array */
|
|
|
|
int n = a_dbus_message_iter(&subiter);
|
|
|
|
|
2009-04-25 15:04:27 +02:00
|
|
|
/* create a new table to store all the value */
|
|
|
|
lua_createtable(globalconf.L, n, 0);
|
|
|
|
/* move the table before array elements */
|
|
|
|
lua_insert(globalconf.L, - n - 1);
|
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
for(int i = n; i > 0; i--)
|
|
|
|
lua_rawseti(globalconf.L, - i - 1, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nargs++;
|
|
|
|
break;
|
|
|
|
case DBUS_TYPE_BOOLEAN:
|
|
|
|
{
|
2009-04-28 22:40:02 +02:00
|
|
|
dbus_bool_t b;
|
2008-11-19 02:22:05 +01:00
|
|
|
dbus_message_iter_get_basic(iter, &b);
|
|
|
|
lua_pushboolean(globalconf.L, b);
|
|
|
|
}
|
|
|
|
nargs++;
|
|
|
|
break;
|
|
|
|
case DBUS_TYPE_BYTE:
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
dbus_message_iter_get_basic(iter, &c);
|
|
|
|
lua_pushlstring(globalconf.L, &c, 1);
|
|
|
|
}
|
|
|
|
nargs++;
|
|
|
|
break;
|
|
|
|
#define DBUS_MSG_HANDLE_TYPE_NUMBER(type, dbustype) \
|
|
|
|
case dbustype: \
|
|
|
|
{ \
|
|
|
|
type ui; \
|
|
|
|
dbus_message_iter_get_basic(iter, &ui); \
|
|
|
|
lua_pushnumber(globalconf.L, ui); \
|
|
|
|
} \
|
|
|
|
nargs++; \
|
|
|
|
break;
|
|
|
|
DBUS_MSG_HANDLE_TYPE_NUMBER(int16_t, DBUS_TYPE_INT16)
|
|
|
|
DBUS_MSG_HANDLE_TYPE_NUMBER(uint16_t, DBUS_TYPE_UINT16)
|
|
|
|
DBUS_MSG_HANDLE_TYPE_NUMBER(int32_t, DBUS_TYPE_INT32)
|
|
|
|
DBUS_MSG_HANDLE_TYPE_NUMBER(uint32_t, DBUS_TYPE_UINT32)
|
|
|
|
DBUS_MSG_HANDLE_TYPE_NUMBER(int64_t, DBUS_TYPE_INT64)
|
|
|
|
DBUS_MSG_HANDLE_TYPE_NUMBER(uint64_t, DBUS_TYPE_UINT64)
|
|
|
|
#undef DBUS_MSG_HANDLE_TYPE_NUMBER
|
|
|
|
case DBUS_TYPE_STRING:
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
dbus_message_iter_get_basic(iter, &s);
|
|
|
|
lua_pushstring(globalconf.L, s);
|
|
|
|
}
|
|
|
|
nargs++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(dbus_message_iter_next(iter));
|
|
|
|
|
|
|
|
return nargs;
|
2008-07-08 10:54:57 +02:00
|
|
|
}
|
|
|
|
|
2009-12-22 14:31:11 +01:00
|
|
|
static bool
|
|
|
|
a_dbus_convert_value(lua_State *L, int idx, DBusMessageIter *iter)
|
|
|
|
{
|
|
|
|
/* i is the type name, i+1 the value */
|
|
|
|
size_t len;
|
|
|
|
const char *type = lua_tolstring(globalconf.L, idx, &len);
|
|
|
|
|
2009-12-22 15:10:23 +01:00
|
|
|
if(!type || len < 1)
|
2009-12-22 14:31:11 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
switch(*type)
|
|
|
|
{
|
2009-12-22 15:10:23 +01:00
|
|
|
case DBUS_TYPE_ARRAY:
|
|
|
|
{
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
|
|
|
|
type + 1,
|
|
|
|
&subiter);
|
|
|
|
|
|
|
|
int arraylen = lua_objlen(L, idx + 1);
|
|
|
|
|
|
|
|
if(arraylen % 2 != 0)
|
2010-06-06 10:46:01 +02:00
|
|
|
{
|
|
|
|
luaA_warn(globalconf.L,
|
|
|
|
"your D-Bus signal handling method returned wrong number of arguments");
|
2010-06-06 13:55:46 +02:00
|
|
|
return false;
|
2010-06-06 10:46:01 +02:00
|
|
|
}
|
2009-12-22 15:10:23 +01:00
|
|
|
|
|
|
|
/* Push the array */
|
|
|
|
lua_pushvalue(L, idx + 1);
|
|
|
|
|
|
|
|
for(int i = 1; i < arraylen; i += 2)
|
|
|
|
{
|
|
|
|
lua_rawgeti(L, -1, i);
|
|
|
|
lua_rawgeti(L, -2, i + 1);
|
|
|
|
if(!a_dbus_convert_value(L, -2, &subiter))
|
|
|
|
return false;
|
|
|
|
lua_pop(L, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the array */
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
dbus_message_iter_close_container(iter, &subiter);
|
|
|
|
}
|
|
|
|
break;
|
2009-12-22 14:31:11 +01:00
|
|
|
case DBUS_TYPE_BOOLEAN:
|
|
|
|
{
|
|
|
|
dbus_bool_t b = lua_toboolean(globalconf.L, idx + 1);
|
|
|
|
dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &b);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#define DBUS_MSG_RETURN_HANDLE_TYPE_STRING(dbustype) \
|
|
|
|
case dbustype: \
|
|
|
|
{ \
|
|
|
|
const char *s = lua_tostring(globalconf.L, idx + 1); \
|
|
|
|
if(s) \
|
|
|
|
dbus_message_iter_append_basic(iter, dbustype, &s); \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_STRING(DBUS_TYPE_STRING)
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_STRING(DBUS_TYPE_BYTE)
|
|
|
|
#undef DBUS_MSG_RETURN_HANDLE_TYPE_STRING
|
|
|
|
#define DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(type, dbustype) \
|
|
|
|
case dbustype: \
|
|
|
|
{ \
|
|
|
|
type num = lua_tonumber(globalconf.L, idx + 1); \
|
|
|
|
dbus_message_iter_append_basic(iter, dbustype, &num); \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(int16_t, DBUS_TYPE_INT16)
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(uint16_t, DBUS_TYPE_UINT16)
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(int32_t, DBUS_TYPE_INT32)
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(uint32_t, DBUS_TYPE_UINT32)
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(int64_t, DBUS_TYPE_INT64)
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(uint64_t, DBUS_TYPE_UINT64)
|
|
|
|
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(double, DBUS_TYPE_DOUBLE)
|
|
|
|
#undef DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Process a single request from D-Bus
|
|
|
|
* \param dbus_connection The connection to the D-Bus server.
|
2010-06-06 10:46:01 +02:00
|
|
|
* \param msg The D-Bus message request being sent to the D-Bus connection.
|
2009-09-04 16:31:29 +02:00
|
|
|
*/
|
2008-07-08 10:54:57 +02:00
|
|
|
static void
|
2009-04-18 16:07:31 +02:00
|
|
|
a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg)
|
2008-07-08 10:54:57 +02:00
|
|
|
{
|
2009-07-29 16:10:29 +02:00
|
|
|
const char *interface = dbus_message_get_interface(msg);
|
2010-10-31 14:59:59 +01:00
|
|
|
int old_top = lua_gettop(globalconf.L);
|
2008-07-08 10:54:57 +02:00
|
|
|
|
2009-04-25 15:04:27 +02:00
|
|
|
lua_createtable(globalconf.L, 0, 5);
|
2008-07-08 10:54:57 +02:00
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
switch(dbus_message_get_type(msg))
|
2008-07-08 10:54:57 +02:00
|
|
|
{
|
2008-11-19 02:22:05 +01:00
|
|
|
case DBUS_MESSAGE_TYPE_SIGNAL:
|
|
|
|
lua_pushliteral(globalconf.L, "signal");
|
|
|
|
break;
|
|
|
|
case DBUS_MESSAGE_TYPE_METHOD_CALL:
|
|
|
|
lua_pushliteral(globalconf.L, "method_call");
|
|
|
|
break;
|
|
|
|
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
|
|
|
|
lua_pushliteral(globalconf.L, "method_return");
|
|
|
|
break;
|
|
|
|
case DBUS_MESSAGE_TYPE_ERROR:
|
|
|
|
lua_pushliteral(globalconf.L, "error");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lua_pushliteral(globalconf.L, "unknown");
|
|
|
|
break;
|
2008-07-08 10:54:57 +02:00
|
|
|
}
|
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
lua_setfield(globalconf.L, -2, "type");
|
2008-07-08 10:54:57 +02:00
|
|
|
|
2009-11-09 20:49:02 +01:00
|
|
|
lua_pushstring(globalconf.L, interface);
|
2008-11-19 02:22:05 +01:00
|
|
|
lua_setfield(globalconf.L, -2, "interface");
|
|
|
|
|
2009-07-29 16:10:29 +02:00
|
|
|
const char *s = dbus_message_get_path(msg);
|
2009-11-09 20:49:02 +01:00
|
|
|
lua_pushstring(globalconf.L, s);
|
2008-11-19 02:22:05 +01:00
|
|
|
lua_setfield(globalconf.L, -2, "path");
|
|
|
|
|
|
|
|
s = dbus_message_get_member(msg);
|
2009-11-09 20:49:02 +01:00
|
|
|
lua_pushstring(globalconf.L, s);
|
2008-11-19 02:22:05 +01:00
|
|
|
lua_setfield(globalconf.L, -2, "member");
|
|
|
|
|
2009-04-18 16:07:31 +02:00
|
|
|
if(dbus_connection == dbus_connection_system)
|
|
|
|
lua_pushliteral(globalconf.L, "system");
|
|
|
|
else
|
|
|
|
lua_pushliteral(globalconf.L, "session");
|
|
|
|
lua_setfield(globalconf.L, -2, "bus");
|
|
|
|
|
2008-11-19 02:22:05 +01:00
|
|
|
/* + 1 for the table above */
|
|
|
|
DBusMessageIter iter;
|
|
|
|
int nargs = 1;
|
|
|
|
|
|
|
|
if(dbus_message_iter_init(msg, &iter))
|
|
|
|
nargs += a_dbus_message_iter(&iter);
|
|
|
|
|
2008-11-19 02:21:11 +01:00
|
|
|
if(dbus_message_get_no_reply(msg))
|
2010-08-26 18:07:09 +02:00
|
|
|
{
|
|
|
|
signal_t *sigfound = signal_array_getbyid(&dbus_signals,
|
|
|
|
a_strhash((const unsigned char *) NONULL(interface)));
|
2009-07-29 16:10:29 +02:00
|
|
|
/* emit signals */
|
2010-08-26 18:07:09 +02:00
|
|
|
if(sigfound)
|
|
|
|
signal_object_emit(globalconf.L, &dbus_signals, NONULL(interface), nargs);
|
|
|
|
}
|
2008-11-19 02:21:11 +01:00
|
|
|
else
|
2009-08-19 16:14:57 +02:00
|
|
|
{
|
|
|
|
signal_t *sig = signal_array_getbyid(&dbus_signals,
|
2009-11-09 20:49:15 +01:00
|
|
|
a_strhash((const unsigned char *) NONULL(interface)));
|
2009-08-19 16:14:57 +02:00
|
|
|
if(sig)
|
2009-07-29 16:10:29 +02:00
|
|
|
{
|
2009-08-19 16:14:57 +02:00
|
|
|
/* there can be only ONE handler to send reply */
|
|
|
|
void *func = (void *) sig->sigfuncs.tab[0];
|
|
|
|
|
|
|
|
int n = lua_gettop(globalconf.L) - nargs;
|
2008-11-19 02:21:11 +01:00
|
|
|
|
2009-08-19 16:14:57 +02:00
|
|
|
luaA_object_push(globalconf.L, (void *) func);
|
2009-07-29 16:10:29 +02:00
|
|
|
luaA_dofunction(globalconf.L, nargs, LUA_MULTRET);
|
2008-11-19 02:21:11 +01:00
|
|
|
|
2009-07-29 16:10:29 +02:00
|
|
|
n -= lua_gettop(globalconf.L);
|
2008-11-19 02:21:11 +01:00
|
|
|
|
2009-07-29 16:10:29 +02:00
|
|
|
DBusMessage *reply = dbus_message_new_method_return(msg);
|
2008-11-19 02:21:11 +01:00
|
|
|
|
2009-07-29 16:10:29 +02:00
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
2008-11-19 02:21:11 +01:00
|
|
|
|
2009-12-22 15:10:23 +01:00
|
|
|
if(n % 2 != 0)
|
2010-06-06 10:46:01 +02:00
|
|
|
{
|
|
|
|
luaA_warn(globalconf.L,
|
|
|
|
"your D-Bus signal handling method returned wrong number of arguments");
|
2010-10-31 14:59:59 +01:00
|
|
|
/* Restore stack */
|
|
|
|
lua_settop(globalconf.L, old_top);
|
2010-06-06 10:46:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-12-22 15:10:23 +01:00
|
|
|
|
2009-07-29 16:10:29 +02:00
|
|
|
/* i is negative */
|
|
|
|
for(int i = n; i < 0; i += 2)
|
2008-11-19 02:21:11 +01:00
|
|
|
{
|
2009-12-22 14:31:11 +01:00
|
|
|
if(!a_dbus_convert_value(globalconf.L, i, &iter))
|
2010-06-06 10:46:01 +02:00
|
|
|
{
|
|
|
|
luaA_warn(globalconf.L, "your D-Bus signal handling method returned bad data");
|
2010-10-31 14:59:59 +01:00
|
|
|
/* Restore stack */
|
|
|
|
lua_settop(globalconf.L, old_top);
|
2010-06-06 10:46:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-07-29 16:10:29 +02:00
|
|
|
|
|
|
|
lua_remove(globalconf.L, i);
|
|
|
|
lua_remove(globalconf.L, i + 1);
|
2008-11-19 02:21:11 +01:00
|
|
|
}
|
|
|
|
|
2009-07-29 16:10:29 +02:00
|
|
|
dbus_connection_send(dbus_connection, reply, NULL);
|
|
|
|
dbus_message_unref(reply);
|
2008-11-19 02:21:11 +01:00
|
|
|
}
|
2009-08-19 16:14:57 +02:00
|
|
|
}
|
2010-10-31 14:59:59 +01:00
|
|
|
/* Restore stack */
|
|
|
|
lua_settop(globalconf.L, old_top);
|
2008-07-08 10:54:57 +02:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Attempt to process all the requests in the D-Bus connection.
|
|
|
|
* \param dbus_connection The D-Bus connection to process from
|
|
|
|
* \param dbusio The D-Bus event watcher
|
|
|
|
*/
|
2008-06-16 23:32:20 +02:00
|
|
|
static void
|
2009-04-27 14:54:09 +02:00
|
|
|
a_dbus_process_requests_on_bus(DBusConnection *dbus_connection, ev_io *dbusio)
|
2008-04-24 17:45:30 +02:00
|
|
|
{
|
|
|
|
DBusMessage *msg;
|
|
|
|
int nmsg = 0;
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
2008-04-30 16:47:38 +02:00
|
|
|
dbus_connection_read_write(dbus_connection, 0);
|
2008-04-24 17:45:30 +02:00
|
|
|
|
2008-04-30 16:47:38 +02:00
|
|
|
if(!(msg = dbus_connection_pop_message(dbus_connection)))
|
2008-04-24 17:45:30 +02:00
|
|
|
break;
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
if(dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected"))
|
2008-04-24 17:45:30 +02:00
|
|
|
{
|
2009-04-27 14:54:09 +02:00
|
|
|
a_dbus_cleanup_bus(dbus_connection, dbusio);
|
2008-04-24 17:45:30 +02:00
|
|
|
dbus_message_unref(msg);
|
|
|
|
return;
|
|
|
|
}
|
2008-11-19 02:22:05 +01:00
|
|
|
else
|
2009-04-18 16:07:31 +02:00
|
|
|
a_dbus_process_request(dbus_connection, msg);
|
2008-04-24 17:45:30 +02:00
|
|
|
|
|
|
|
dbus_message_unref(msg);
|
|
|
|
|
|
|
|
nmsg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nmsg)
|
2008-04-30 16:47:38 +02:00
|
|
|
dbus_connection_flush(dbus_connection);
|
2008-04-24 17:45:30 +02:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Foreword D-Bus process session requests on too the correct function.
|
|
|
|
* \param w The D-Bus event watcher
|
|
|
|
* \param revents (not used)
|
|
|
|
*/
|
2009-04-18 16:07:31 +02:00
|
|
|
static void
|
|
|
|
a_dbus_process_requests_session(EV_P_ ev_io *w, int revents)
|
|
|
|
{
|
2009-04-27 14:54:09 +02:00
|
|
|
a_dbus_process_requests_on_bus(dbus_connection_session, w);
|
2009-04-18 16:07:31 +02:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Foreword D-Bus process system requests on too the correct function.
|
|
|
|
* \param w The D-Bus event watcher
|
|
|
|
* \param revents (not used)
|
|
|
|
*/
|
2009-04-18 16:07:31 +02:00
|
|
|
static void
|
|
|
|
a_dbus_process_requests_system(EV_P_ ev_io *w, int revents)
|
|
|
|
{
|
2009-04-27 14:54:09 +02:00
|
|
|
a_dbus_process_requests_on_bus(dbus_connection_system, w);
|
2009-04-18 16:07:31 +02:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Attempt to request a D-Bus name
|
|
|
|
* \param dbus_connection The application's connection to D-Bus
|
|
|
|
* \param name The D-Bus connection name to be requested
|
|
|
|
* \return true if the name is primary owner or the name is already
|
|
|
|
* the owner, otherwise false.
|
|
|
|
*/
|
2008-11-18 16:31:27 +01:00
|
|
|
static bool
|
2009-04-18 16:07:31 +02:00
|
|
|
a_dbus_request_name(DBusConnection *dbus_connection, const char *name)
|
2008-11-18 16:31:27 +01:00
|
|
|
{
|
2009-04-18 16:07:31 +02:00
|
|
|
DBusError err;
|
|
|
|
|
|
|
|
if(!dbus_connection)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dbus_error_init(&err);
|
|
|
|
|
2008-11-18 16:31:27 +01:00
|
|
|
int ret = dbus_bus_request_name(dbus_connection, name, 0, &err);
|
|
|
|
|
|
|
|
if(dbus_error_is_set(&err))
|
|
|
|
{
|
|
|
|
warn("failed to request D-Bus name: %s", err.message);
|
2009-04-18 16:07:31 +02:00
|
|
|
dbus_error_free(&err);
|
2008-11-18 16:31:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(ret)
|
|
|
|
{
|
|
|
|
case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
|
|
|
|
return true;
|
|
|
|
case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
|
|
|
|
warn("already primary D-Bus name owner for %s", name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Attempt to release the D-Bus name owner
|
|
|
|
* \param dbus_connection The application's connection to the D-Bus
|
|
|
|
* \param name The name to be released
|
|
|
|
* \return True on success. False if the name is not
|
|
|
|
* the owner, or does not exist.
|
|
|
|
*/
|
2008-11-18 17:07:49 +01:00
|
|
|
static bool
|
2009-04-18 16:07:31 +02:00
|
|
|
a_dbus_release_name(DBusConnection *dbus_connection, const char *name)
|
2008-11-18 17:07:49 +01:00
|
|
|
{
|
2009-04-18 16:07:31 +02:00
|
|
|
DBusError err;
|
|
|
|
|
|
|
|
if(!dbus_connection)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dbus_error_init(&err);
|
|
|
|
|
2008-11-18 17:07:49 +01:00
|
|
|
int ret = dbus_bus_release_name(dbus_connection, name, &err);
|
|
|
|
|
|
|
|
if(dbus_error_is_set(&err))
|
|
|
|
{
|
|
|
|
warn("failed to release D-Bus name: %s", err.message);
|
2009-04-18 16:07:31 +02:00
|
|
|
dbus_error_free(&err);
|
2008-11-18 17:07:49 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(ret)
|
|
|
|
{
|
|
|
|
case DBUS_RELEASE_NAME_REPLY_NOT_OWNER:
|
|
|
|
warn("not primary D-Bus name owner for %s", name);
|
|
|
|
return false;
|
|
|
|
case DBUS_RELEASE_NAME_REPLY_NON_EXISTENT:
|
|
|
|
warn("non existent D-Bus name: %s", name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Attempt to create a new connection to D-Bus
|
|
|
|
* \param type The bus type to use when connecting to D-Bus
|
|
|
|
* \param type_name The bus type name eg: "session" or "system"
|
|
|
|
* \param dbusio The D-Bus event watcher
|
|
|
|
* \param cb Function callback to use when processing requests
|
|
|
|
* \return The requested D-Bus connection on success, NULL on failure.
|
|
|
|
*/
|
2009-04-18 16:07:31 +02:00
|
|
|
static DBusConnection *
|
|
|
|
a_dbus_connect(DBusBusType type, const char *type_name,
|
|
|
|
ev_io *dbusio, void *cb)
|
2008-04-24 17:45:30 +02:00
|
|
|
{
|
2008-06-16 23:32:20 +02:00
|
|
|
int fd;
|
2009-04-18 16:07:31 +02:00
|
|
|
DBusConnection *dbus_connection;
|
|
|
|
DBusError err;
|
2008-04-24 17:45:30 +02:00
|
|
|
|
|
|
|
dbus_error_init(&err);
|
|
|
|
|
2009-04-18 16:07:31 +02:00
|
|
|
dbus_connection = dbus_bus_get(type, &err);
|
2008-04-24 17:45:30 +02:00
|
|
|
if(dbus_error_is_set(&err))
|
|
|
|
{
|
2009-04-18 16:07:31 +02:00
|
|
|
warn("D-Bus session bus %s failed: %s", type_name, err.message);
|
2008-04-30 16:47:38 +02:00
|
|
|
dbus_connection = NULL;
|
2008-04-24 17:45:30 +02:00
|
|
|
dbus_error_free(&err);
|
|
|
|
}
|
2009-04-18 16:07:31 +02:00
|
|
|
else
|
|
|
|
{
|
2009-06-17 10:27:54 +02:00
|
|
|
dbus_connection_set_exit_on_disconnect(dbus_connection, false);
|
2009-04-18 16:07:31 +02:00
|
|
|
if(dbus_connection_get_unix_fd(dbus_connection, &fd))
|
|
|
|
{
|
|
|
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
2008-04-24 17:45:30 +02:00
|
|
|
|
2009-04-18 16:07:31 +02:00
|
|
|
ev_io_init(dbusio, cb, fd, EV_READ);
|
|
|
|
ev_io_start(EV_DEFAULT_UC_ dbusio);
|
|
|
|
ev_unref(EV_DEFAULT_UC);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
warn("cannot get D-Bus connection file descriptor");
|
2009-04-27 14:54:09 +02:00
|
|
|
a_dbus_cleanup_bus(dbus_connection, dbusio);
|
2009-04-18 16:07:31 +02:00
|
|
|
}
|
2008-04-24 17:45:30 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 16:07:31 +02:00
|
|
|
return dbus_connection;
|
2008-04-24 17:45:30 +02:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Initialize the D-Bus session and system
|
|
|
|
*/
|
2008-04-24 17:45:30 +02:00
|
|
|
void
|
2009-04-18 16:07:31 +02:00
|
|
|
a_dbus_init(void)
|
|
|
|
{
|
|
|
|
dbus_connection_session = a_dbus_connect(DBUS_BUS_SESSION, "session",
|
|
|
|
&dbusio_ses, a_dbus_process_requests_session);
|
|
|
|
dbus_connection_system = a_dbus_connect(DBUS_BUS_SYSTEM, "system",
|
|
|
|
&dbusio_sys, a_dbus_process_requests_system);
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Cleanup the D-Bus session and system
|
|
|
|
*/
|
2009-04-18 16:07:31 +02:00
|
|
|
void
|
|
|
|
a_dbus_cleanup(void)
|
|
|
|
{
|
|
|
|
a_dbus_cleanup_bus(dbus_connection_session, &dbusio_ses);
|
|
|
|
a_dbus_cleanup_bus(dbus_connection_system, &dbusio_sys);
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Retrieve the D-Bus bus by it's name
|
|
|
|
* \param name The name of the bus
|
|
|
|
* \return The corresponding D-Bus connection
|
|
|
|
*/
|
2009-04-18 16:07:31 +02:00
|
|
|
static DBusConnection *
|
2010-09-02 19:02:21 +02:00
|
|
|
a_dbus_bus_getbyname(const char *name)
|
2009-04-18 16:07:31 +02:00
|
|
|
{
|
2010-09-02 19:02:21 +02:00
|
|
|
if(a_strcmp(name, "system") == 0)
|
2009-04-18 16:07:31 +02:00
|
|
|
return dbus_connection_system;
|
2010-09-02 19:02:21 +02:00
|
|
|
if(a_strcmp(name, "session") == 0)
|
2009-04-18 16:07:31 +02:00
|
|
|
return dbus_connection_session;
|
2010-09-02 19:02:21 +02:00
|
|
|
return NULL;
|
2008-04-24 17:45:30 +02:00
|
|
|
}
|
|
|
|
|
2008-11-18 16:31:27 +01:00
|
|
|
/** Register a D-Bus name to receive message from.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
2009-04-18 16:07:31 +02:00
|
|
|
* \lparam A string indicating if we are using system or session bus.
|
2009-05-16 12:22:20 +02:00
|
|
|
* \lparam A string with the name of the D-Bus name to register.
|
2008-11-18 16:31:27 +01:00
|
|
|
* \lreturn True if everything worked fine, false otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_dbus_request_name(lua_State *L)
|
|
|
|
{
|
2010-09-02 19:02:21 +02:00
|
|
|
const char *bus = luaL_checkstring(L, 1);
|
2009-04-18 16:07:31 +02:00
|
|
|
const char *name = luaL_checkstring(L, 2);
|
2010-09-02 19:02:21 +02:00
|
|
|
DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus);
|
2009-04-18 16:07:31 +02:00
|
|
|
lua_pushboolean(L, a_dbus_request_name(dbus_connection, name));
|
2008-11-18 16:31:27 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-18 17:07:49 +01:00
|
|
|
/** Release a D-Bus name.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
2009-04-18 16:07:31 +02:00
|
|
|
* \lparam A string indicating if we are using system or session bus.
|
2008-11-18 17:07:49 +01:00
|
|
|
* \lparam A string with the name of the D-Bus name to unregister.
|
|
|
|
* \lreturn True if everything worked fine, false otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_dbus_release_name(lua_State *L)
|
|
|
|
{
|
2010-09-02 19:02:21 +02:00
|
|
|
const char *bus = luaL_checkstring(L, 1);
|
2009-04-18 16:07:31 +02:00
|
|
|
const char *name = luaL_checkstring(L, 2);
|
2010-09-02 19:02:21 +02:00
|
|
|
DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus);
|
2009-04-18 16:07:31 +02:00
|
|
|
lua_pushboolean(L, a_dbus_release_name(dbus_connection, name));
|
2008-11-18 17:07:49 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-25 14:24:35 +01:00
|
|
|
/** Add a match rule to match messages going through the message bus.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
2009-04-18 16:07:31 +02:00
|
|
|
* \lparam A string indicating if we are using system or session bus.
|
2008-11-25 14:24:35 +01:00
|
|
|
* \lparam A string with the name of the match rule.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_dbus_add_match(lua_State *L)
|
|
|
|
{
|
2010-09-02 19:02:21 +02:00
|
|
|
const char *bus = luaL_checkstring(L, 1);
|
2009-04-18 16:07:31 +02:00
|
|
|
const char *name = luaL_checkstring(L, 2);
|
2010-09-02 19:02:21 +02:00
|
|
|
DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus);
|
2009-04-18 16:07:31 +02:00
|
|
|
|
|
|
|
if(dbus_connection)
|
|
|
|
{
|
|
|
|
dbus_bus_add_match(dbus_connection, name, NULL);
|
|
|
|
dbus_connection_flush(dbus_connection);
|
|
|
|
}
|
|
|
|
|
2008-11-25 14:24:35 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove a previously added match rule "by value"
|
|
|
|
* (the most recently-added identical rule gets removed).
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
2009-04-18 16:07:31 +02:00
|
|
|
* \lparam A string indicating if we are using system or session bus.
|
2008-11-25 14:24:35 +01:00
|
|
|
* \lparam A string with the name of the match rule.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_dbus_remove_match(lua_State *L)
|
|
|
|
{
|
2010-09-02 19:02:21 +02:00
|
|
|
const char *bus = luaL_checkstring(L, 1);
|
2009-04-18 16:07:31 +02:00
|
|
|
const char *name = luaL_checkstring(L, 2);
|
2010-09-02 19:02:21 +02:00
|
|
|
DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus);
|
2009-04-18 16:07:31 +02:00
|
|
|
|
|
|
|
if(dbus_connection)
|
|
|
|
{
|
|
|
|
dbus_bus_remove_match(dbus_connection, name, NULL);
|
|
|
|
dbus_connection_flush(dbus_connection);
|
|
|
|
}
|
|
|
|
|
2008-11-25 14:24:35 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:10:29 +02:00
|
|
|
/** Add a signal receiver on the D-Bus.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam A string with the interface name.
|
|
|
|
* \lparam The function to call.
|
|
|
|
*/
|
|
|
|
static int
|
2009-10-09 20:39:55 +02:00
|
|
|
luaA_dbus_connect_signal(lua_State *L)
|
2009-07-29 16:10:29 +02:00
|
|
|
{
|
|
|
|
const char *name = luaL_checkstring(L, 1);
|
|
|
|
luaA_checkfunction(L, 2);
|
2009-08-19 16:16:14 +02:00
|
|
|
signal_t *sig = signal_array_getbyid(&dbus_signals,
|
|
|
|
a_strhash((const unsigned char *) name));
|
|
|
|
if(sig)
|
|
|
|
luaA_warn(L, "cannot add signal %s on D-Bus, already existing", name);
|
|
|
|
else
|
2010-08-25 23:00:36 +02:00
|
|
|
{
|
|
|
|
signal_add(&dbus_signals, name);
|
2010-08-25 20:48:42 +02:00
|
|
|
signal_connect(&dbus_signals, name, luaA_object_ref(L, 2));
|
2010-08-25 23:00:36 +02:00
|
|
|
}
|
2009-07-29 16:10:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Add a signal receiver on the D-Bus.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam A string with the interface name.
|
|
|
|
* \lparam The function to call.
|
|
|
|
*/
|
|
|
|
static int
|
2009-10-09 20:39:55 +02:00
|
|
|
luaA_dbus_disconnect_signal(lua_State *L)
|
2009-07-29 16:10:29 +02:00
|
|
|
{
|
|
|
|
const char *name = luaL_checkstring(L, 1);
|
|
|
|
luaA_checkfunction(L, 2);
|
|
|
|
const void *func = lua_topointer(L, 2);
|
2010-08-25 20:48:42 +02:00
|
|
|
signal_disconnect(&dbus_signals, name, func);
|
2009-07-29 16:10:29 +02:00
|
|
|
luaA_object_unref(L, (void *) func);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-18 16:31:27 +01:00
|
|
|
const struct luaL_reg awesome_dbus_lib[] =
|
|
|
|
{
|
|
|
|
{ "request_name", luaA_dbus_request_name },
|
2008-11-18 17:07:49 +01:00
|
|
|
{ "release_name", luaA_dbus_release_name },
|
2008-11-25 14:24:35 +01:00
|
|
|
{ "add_match", luaA_dbus_add_match },
|
|
|
|
{ "remove_match", luaA_dbus_remove_match },
|
2009-10-09 20:39:55 +02:00
|
|
|
{ "connect_signal", luaA_dbus_connect_signal },
|
|
|
|
{ "disconnect_signal", luaA_dbus_disconnect_signal },
|
2008-11-18 16:31:27 +01:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
#else /* WITH_DBUS */
|
2008-05-30 21:20:23 +02:00
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Empty stub if dbus is not enabled */
|
2009-04-18 16:07:31 +02:00
|
|
|
void
|
2008-06-16 23:32:20 +02:00
|
|
|
a_dbus_init(void)
|
2008-05-30 21:20:23 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:31:29 +02:00
|
|
|
/** Empty stub if dbus is not enabled */
|
2008-05-30 21:20:23 +02:00
|
|
|
void
|
|
|
|
a_dbus_cleanup(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2008-04-24 17:45:30 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|