Plug dbus in the event loop.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
Pierre Habouzit 2008-06-16 23:32:20 +02:00
parent 8b61bf5197
commit 38f8d2fdce
3 changed files with 23 additions and 24 deletions

View File

@ -36,6 +36,7 @@
#include <signal.h>
#include <glib.h>
#include <ev.h>
#include <xcb/xcb.h>
#include <xcb/shape.h>
@ -261,7 +262,7 @@ main(int argc, char **argv)
{
char buf[1024];
const char *confpath = NULL;
int r, xfd, csfd, dbusfd, i, screen_nbr, opt;
int r, xfd, csfd, i, screen_nbr, opt;
ssize_t cmdlen = 1;
const xcb_query_extension_reply_t *shape_query, *randr_query;
fd_set rd;
@ -474,8 +475,7 @@ main(int argc, char **argv)
warn("error binding UNIX domain socket: %s", strerror(errno));
}
if(!a_dbus_init(&dbusfd))
dbusfd = -1;
a_dbus_init();
/* register function for signals */
signal(SIGINT, &exit_on_signal);
@ -492,8 +492,6 @@ main(int argc, char **argv)
FD_ZERO(&rd);
if(csfd >= 0)
FD_SET(csfd, &rd);
if(dbusfd >= 0)
FD_SET(dbusfd, &rd);
FD_SET(xfd, &rd);
if(timerisset(&globalconf.timer))
{
@ -509,7 +507,7 @@ main(int argc, char **argv)
else
timersub(&hook_nextrun, &now, &select_timeout);
}
if(select(MAX(MAX(xfd, csfd), dbusfd) + 1, &rd,
if(select(MAX(xfd, csfd) + 1, &rd,
NULL, NULL,
timerisset(&globalconf.timer) ? &select_timeout : NULL) == -1)
{
@ -533,9 +531,6 @@ main(int argc, char **argv)
luaA_docmd(buf);
}
if(dbusfd >= 0 && FD_ISSET(dbusfd, &rd))
a_dbus_process_requests(&dbusfd);
/* Two level polling:
* We need to first check we have an event to handle
* and if so, we handle them all in a round.

31
dbus.c
View File

@ -22,6 +22,7 @@
#ifdef WITH_DBUS
#include <ev.h>
#include <dbus/dbus.h>
#include "dbus.h"
@ -32,6 +33,7 @@ extern awesome_t globalconf;
static DBusError err;
static DBusConnection *dbus_connection = NULL;
ev_io dbusio = { .fd = -1 };
/** Check a dbus object path format and its number of element.
* \param path The path.
@ -98,13 +100,13 @@ a_dbus_process_widget_set(DBusMessage *req)
p_delete(&path);
}
void
a_dbus_process_requests(int *fd)
static void
a_dbus_process_requests(EV_P_ ev_io *w, int revents)
{
DBusMessage *msg;
int nmsg = 0;
if(!dbus_connection && !a_dbus_init(fd))
if(!dbus_connection && !a_dbus_init())
return;
while(true)
@ -134,9 +136,10 @@ a_dbus_process_requests(int *fd)
}
bool
a_dbus_init(int *fd)
a_dbus_init(void)
{
bool ret;
int fd;
dbus_error_init(&err);
@ -167,13 +170,16 @@ a_dbus_init(int *fd)
return false;
}
if(!dbus_connection_get_unix_fd(dbus_connection, fd))
if(!dbus_connection_get_unix_fd(dbus_connection, &fd))
{
warn("cannot get DBus connection file descriptor");
a_dbus_cleanup();
return false;
}
ev_io_init(&dbusio, a_dbus_process_requests, fd, EV_READ);
ev_io_start(EV_DEFAULT_UC_ &dbusio);
ev_unref(EV_DEFAULT_UC);
return true;
}
@ -185,6 +191,12 @@ a_dbus_cleanup(void)
dbus_error_free(&err);
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
*/
@ -196,16 +208,9 @@ a_dbus_cleanup(void)
#include "dbus.h"
void
a_dbus_process_requests(int *fd __attribute__((unused)))
{
/* empty */
}
bool
a_dbus_init(int *fd)
a_dbus_init(void)
{
*fd = -1;
return false;
}

3
dbus.h
View File

@ -24,8 +24,7 @@
#include <stdbool.h>
void a_dbus_process_requests(int *);
bool a_dbus_init(int *);
bool a_dbus_init(void);
void a_dbus_cleanup(void);
#endif