[Pommed-commits] r475 - in trunk: . gpomme
jblache at alioth.debian.org
jblache at alioth.debian.org
Sat May 31 17:59:03 UTC 2008
Author: jblache
Date: 2008-05-31 17:59:02 +0000 (Sat, 31 May 2008)
New Revision: 475
Modified:
trunk/ChangeLog
trunk/INSTALL
trunk/gpomme/Makefile
trunk/gpomme/gpomme.c
Log:
Integrate DBus messaging into the main loop.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-05-30 20:37:38 UTC (rev 474)
+++ trunk/ChangeLog 2008-05-31 17:59:02 UTC (rev 475)
@@ -3,6 +3,8 @@
version 1.19:
- pommed: get rid of the libsmbios dependency on Intel machines.
+ - gpomme: integrate config file monitoring and DBus messaging into
+ the main loop. Get rid of the 10 times per second polling.
version 1.18:
- pommed: add more IDs for Apple external keyboards
Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL 2008-05-30 20:37:38 UTC (rev 474)
+++ trunk/INSTALL 2008-05-31 17:59:02 UTC (rev 475)
@@ -21,6 +21,7 @@
gpomme requires:
- libdbus
+ - libdbus-glib
- GTK+ 2.0
- glade 2.0
Modified: trunk/gpomme/Makefile
===================================================================
--- trunk/gpomme/Makefile 2008-05-30 20:37:38 UTC (rev 474)
+++ trunk/gpomme/Makefile 2008-05-31 17:59:02 UTC (rev 475)
@@ -9,13 +9,16 @@
DBUS_CFLAGS = $(shell pkg-config dbus-1 --cflags) -DDBUS_API_SUBJECT_TO_CHANGE
DBUS_LIBS = $(shell pkg-config dbus-1 --libs)
+DBUSGLIB_CFLAGS = $(shell pkg-config dbus-glib-1 --cflags)
+DBUSGLIB_LIBS = $(shell pkg-config dbus-glib-1 --libs)
+
CONFUSE_CFLAGS = $(shell pkg-config libconfuse --cflags)
CONFUSE_LIBS = $(shell pkg-config libconfuse --libs)
INOTIFY_CFLAGS = $(shell test -e /usr/include/sys/inotify.h || echo -DNO_SYS_INOTIFY_H)
-CFLAGS = -g -O2 -Wall $(DBUS_CFLAGS) $(GTK_CFLAGS) $(CONFUSE_CFLAGS) $(GLADE_CFLAGS) $(INOTIFY_CFLAGS)
-LDFLAGS = -lpthread $(DBUS_LIBS) $(GTK_LIBS) $(CONFUSE_LIBS) $(GLADE_LIBS)
+CFLAGS = -g -O2 -Wall $(DBUS_CFLAGS) $(DBUSGLIB_CFLAGS) $(GTK_CFLAGS) $(CONFUSE_CFLAGS) $(GLADE_CFLAGS) $(INOTIFY_CFLAGS)
+LDFLAGS = -lpthread $(DBUS_LIBS) $(DBUSGLIB_LIBS) $(GTK_LIBS) $(CONFUSE_LIBS) $(GLADE_LIBS)
SOURCES = gpomme.c theme.c conffile.c \
../client-common/dbus-client.c \
Modified: trunk/gpomme/gpomme.c
===================================================================
--- trunk/gpomme/gpomme.c 2008-05-30 20:37:38 UTC (rev 474)
+++ trunk/gpomme/gpomme.c 2008-05-31 17:59:02 UTC (rev 475)
@@ -48,6 +48,8 @@
#include <X11/Xlib.h>
#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
#include "gpomme.h"
#include "theme.h"
@@ -70,7 +72,9 @@
DBusError dbus_err;
DBusConnection *conn;
+dbus_uint32_t mute_serial = 0;
+
/* Timer callback */
gboolean
hide_window(gpointer userdata)
@@ -249,43 +253,121 @@
}
-void
-audio_getmute_cb(DBusPendingCall *pending, void *status)
+static gboolean
+mbp_dbus_reconnect(gpointer userdata);
+
+static DBusHandlerResult
+mbp_dbus_listen(DBusConnection *lconn, DBusMessage *msg, gpointer userdata)
{
- DBusMessage *msg;
+ int scratch;
+ int cur;
+ int max;
+ int who;
+ double ratio;
- msg = dbus_pending_call_steal_reply(pending);
+ Display *dpy;
- if (msg == NULL)
+ if (dbus_message_is_signal(msg, "org.pommed.signal.lcdBacklight", "lcdBacklight"))
{
- printf("Could not steal reply\n");
+ dbus_message_get_args(msg, &dbus_err,
+ DBUS_TYPE_UINT32, &cur,
+ DBUS_TYPE_UINT32, &scratch, /* previous */
+ DBUS_TYPE_UINT32, &max,
+ DBUS_TYPE_UINT32, &who,
+ DBUS_TYPE_INVALID);
- dbus_pending_call_unref(pending);
+ if (who == LCD_USER)
+ {
+ ratio = (double)cur / (double)max;
- return;
+ show_window(IMG_LCD_BCK, _("LCD backlight level"), ratio);
+ }
}
+ else if (dbus_message_is_signal(msg, "org.pommed.signal.kbdBacklight", "kbdBacklight"))
+ {
+ dbus_message_get_args(msg, &dbus_err,
+ DBUS_TYPE_UINT32, &cur,
+ DBUS_TYPE_UINT32, &scratch, /* previous */
+ DBUS_TYPE_UINT32, &max,
+ DBUS_TYPE_UINT32, &who,
+ DBUS_TYPE_INVALID);
- dbus_pending_call_unref(pending);
+ if (who == KBD_USER)
+ {
+ ratio = (double)cur / (double)max;
- if (!mbp_dbus_check_error(msg))
+ show_window(IMG_KBD_BCK, _("Keyboard backlight level"), ratio);
+ }
+ }
+ else if (dbus_message_is_signal(msg, "org.pommed.signal.audioVolume", "audioVolume"))
{
dbus_message_get_args(msg, &dbus_err,
+ DBUS_TYPE_UINT32, &cur,
+ DBUS_TYPE_UINT32, &scratch, /* previous */
+ DBUS_TYPE_UINT32, &max,
+ DBUS_TYPE_INVALID);
+
+ ratio = (double)cur / (double)max;
+
+ if (!mbp.muted)
+ show_window(IMG_AUDIO_VOL_ON, _("Sound volume"), ratio);
+ else
+ show_window(IMG_AUDIO_VOL_OFF, _("Sound volume (muted)"), ratio);
+ }
+ else if (dbus_message_is_signal(msg, "org.pommed.signal.audioMute", "audioMute"))
+ {
+ dbus_message_get_args(msg, &dbus_err,
DBUS_TYPE_BOOLEAN, &mbp.muted,
DBUS_TYPE_INVALID);
+
+ if (mbp.muted)
+ show_window(IMG_AUDIO_MUTE, _("Sound muted"), -1.0);
+ else
+ show_window(IMG_AUDIO_MUTE, _("Sound unmuted"), -1.0);
}
+ else if (dbus_message_is_signal(msg, "org.pommed.signal.cdEject", "cdEject"))
+ {
+ show_window(IMG_CD_EJECT, _("Eject"), -1.0);
+ }
+ else if (dbus_message_is_signal(msg, "org.pommed.signal.videoSwitch", "videoSwitch"))
+ {
+ dpy = GDK_WINDOW_XDISPLAY(GTK_WIDGET(mbp_w.window)->window);
+ mbp_video_switch(dpy);
+ }
+ else if (dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected"))
+ {
+ printf("DBus disconnected\n");
+
+ g_timeout_add(200, mbp_dbus_reconnect, NULL);
+
+ mbp_dbus_cleanup();
+ }
else
- *(int *)status = -1;
+ {
+ if ((dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
+ && (dbus_message_get_reply_serial(msg) == mute_serial))
+ {
+ dbus_message_get_args(msg, &dbus_err,
+ DBUS_TYPE_BOOLEAN, &mbp.muted,
+ DBUS_TYPE_INVALID);
+ }
+ else
+ {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ }
- dbus_message_unref(msg);
+ return DBUS_HANDLER_RESULT_HANDLED;
}
-
int
mbp_dbus_connect(void)
{
unsigned int signals;
+
+ DBusMessage *msg;
+
int ret;
- int cbret;
signals = MBP_DBUS_SIG_LCD | MBP_DBUS_SIG_KBD
| MBP_DBUS_SIG_VOL | MBP_DBUS_SIG_MUTE
@@ -296,131 +378,49 @@
if (conn == NULL)
return -1;
- ret = mbp_call_audio_getmute(audio_getmute_cb, &cbret);
- if ((ret < 0) || (cbret < 0))
- {
- printf("audio getMute call failed !\n");
- }
+ dbus_connection_setup_with_g_main(conn, NULL);
- return 0;
-}
+ dbus_connection_add_filter (conn, mbp_dbus_listen, NULL, NULL);
-void
-mbp_dbus_listen(gpointer userdata)
-{
- DBusMessage *msg;
+ /* Get the mute state */
+ msg = dbus_message_new_method_call("org.pommed", "/org/pommed/audio",
+ "org.pommed.audio", "getMute");
- int ret;
-
- int scratch;
- int cur;
- int max;
- int who;
- double ratio;
-
- Display *dpy;
-
- /* Disconnected, try to reconnect */
- if (conn == NULL)
+ if (msg == NULL)
{
- ret = mbp_dbus_connect();
+ printf("Failed to create method call message for audio getMute\n");
- if (ret < 0)
- return;
+ return 0;
}
- while (1)
+ ret = dbus_connection_send(conn, msg, &mute_serial);
+ if (ret == FALSE)
{
- dbus_connection_read_write(conn, 0);
+ printf("Could not send method call for audio getMute\n");
- msg = dbus_connection_pop_message(conn);
+ dbus_message_unref(msg);
- if (msg == NULL)
- return;
+ return 0;
+ }
- if (dbus_message_is_signal(msg, "org.pommed.signal.lcdBacklight", "lcdBacklight"))
- {
- dbus_message_get_args(msg, &dbus_err,
- DBUS_TYPE_UINT32, &cur,
- DBUS_TYPE_UINT32, &scratch, /* previous */
- DBUS_TYPE_UINT32, &max,
- DBUS_TYPE_UINT32, &who,
- DBUS_TYPE_INVALID);
+ dbus_connection_flush(conn);
- if (who == LCD_USER)
- {
- ratio = (double)cur / (double)max;
+ dbus_message_unref(msg);
- show_window(IMG_LCD_BCK, _("LCD backlight level"), ratio);
- }
- }
- else if (dbus_message_is_signal(msg, "org.pommed.signal.kbdBacklight", "kbdBacklight"))
- {
- dbus_message_get_args(msg, &dbus_err,
- DBUS_TYPE_UINT32, &cur,
- DBUS_TYPE_UINT32, &scratch, /* previous */
- DBUS_TYPE_UINT32, &max,
- DBUS_TYPE_UINT32, &who,
- DBUS_TYPE_INVALID);
+ return 0;
+}
- if (who == KBD_USER)
- {
- ratio = (double)cur / (double)max;
+static gboolean
+mbp_dbus_reconnect(gpointer userdata)
+{
+ if (mbp_dbus_connect() < 0)
+ return TRUE;
- show_window(IMG_KBD_BCK, _("Keyboard backlight level"), ratio);
- }
- }
- else if (dbus_message_is_signal(msg, "org.pommed.signal.audioVolume", "audioVolume"))
- {
- dbus_message_get_args(msg, &dbus_err,
- DBUS_TYPE_UINT32, &cur,
- DBUS_TYPE_UINT32, &scratch, /* previous */
- DBUS_TYPE_UINT32, &max,
- DBUS_TYPE_INVALID);
-
- ratio = (double)cur / (double)max;
-
- if (!mbp.muted)
- show_window(IMG_AUDIO_VOL_ON, _("Sound volume"), ratio);
- else
- show_window(IMG_AUDIO_VOL_OFF, _("Sound volume (muted)"), ratio);
- }
- else if (dbus_message_is_signal(msg, "org.pommed.signal.audioMute", "audioMute"))
- {
- dbus_message_get_args(msg, &dbus_err,
- DBUS_TYPE_BOOLEAN, &mbp.muted,
- DBUS_TYPE_INVALID);
-
- if (mbp.muted)
- show_window(IMG_AUDIO_MUTE, _("Sound muted"), -1.0);
- else
- show_window(IMG_AUDIO_MUTE, _("Sound unmuted"), -1.0);
- }
- else if (dbus_message_is_signal(msg, "org.pommed.signal.cdEject", "cdEject"))
- {
- show_window(IMG_CD_EJECT, _("Eject"), -1.0);
- }
- else if (dbus_message_is_signal(msg, "org.pommed.signal.videoSwitch", "videoSwitch"))
- {
- dpy = GDK_WINDOW_XDISPLAY(GTK_WIDGET(mbp_w.window)->window);
- mbp_video_switch(dpy);
- }
- else if (dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected"))
- {
- printf("DBus disconnected\n");
-
- mbp_dbus_cleanup();
-
- dbus_message_unref(msg);
-
- break;
- }
-
- dbus_message_unref(msg);
- }
+ return FALSE;
}
+
gboolean
mbp_check_config(GIOChannel *ch, GIOCondition condition, gpointer userdata)
{
@@ -454,15 +454,7 @@
return FALSE;
}
-gboolean
-mbp_check_events(gpointer userdata)
-{
- mbp_dbus_listen(userdata);
- return TRUE;
-}
-
-
static void
usage(void)
{
@@ -476,7 +468,8 @@
}
-void sig_int_term_handler(int signo)
+void
+sig_int_term_handler(int signo)
{
gtk_main_quit();
}
@@ -493,7 +486,8 @@
while (ret > 0);
}
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
int c;
int ret;
@@ -543,12 +537,6 @@
fd = config_monitor();
- signal(SIGINT, sig_int_term_handler);
- signal(SIGTERM, sig_int_term_handler);
- signal(SIGCHLD, sig_chld_handler);
-
- create_window();
-
if (fd > 0)
{
ch = g_io_channel_unix_new(fd);
@@ -556,8 +544,12 @@
g_io_add_watch(ch, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, mbp_check_config, NULL);
}
- g_timeout_add(100, mbp_check_events, NULL);
+ signal(SIGINT, sig_int_term_handler);
+ signal(SIGTERM, sig_int_term_handler);
+ signal(SIGCHLD, sig_chld_handler);
+ create_window();
+
gtk_main();
mbp_dbus_cleanup();
More information about the Pommed-commits
mailing list