[Pommed-commits] r481 - in trunk: . pommed

jblache at alioth.debian.org jblache at alioth.debian.org
Mon Jun 2 18:22:00 UTC 2008


Author: jblache
Date: 2008-06-02 18:21:57 +0000 (Mon, 02 Jun 2008)
New Revision: 481

Added:
   trunk/pommed/evloop.c
   trunk/pommed/evloop.h
Modified:
   trunk/ChangeLog
   trunk/pommed/Makefile
   trunk/pommed/beep.c
   trunk/pommed/beep.h
   trunk/pommed/evdev.c
   trunk/pommed/evdev.h
   trunk/pommed/pommed.c
Log:
New event loop.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-06-02 17:02:50 UTC (rev 480)
+++ trunk/ChangeLog	2008-06-02 18:21:57 UTC (rev 481)
@@ -5,6 +5,7 @@
 	- 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.
+	- pommed: new event loop.
 
 version 1.18:
 	- pommed: add more IDs for Apple external keyboards

Modified: trunk/pommed/Makefile
===================================================================
--- trunk/pommed/Makefile	2008-06-02 17:02:50 UTC (rev 480)
+++ trunk/pommed/Makefile	2008-06-02 18:21:57 UTC (rev 481)
@@ -24,7 +24,7 @@
 OFLIB ?=
 
 SOURCES = pommed.c cd_eject.c evdev.c conffile.c audio.c \
-		dbus.c power.c beep.c video.c \
+		evloop.c dbus.c power.c beep.c video.c \
 		pmac/sysfs_backlight.c pmac/pmu.c \
 		pmac/kbd_backlight.c pmac/ambient.c
 
@@ -56,7 +56,7 @@
 endif
 
 SOURCES = pommed.c cd_eject.c evdev.c conffile.c audio.c \
-		dbus.c power.c beep.c video.c \
+		evloop.c dbus.c power.c beep.c video.c \
 		mactel/x1600_backlight.c mactel/gma950_backlight.c \
 		mactel/nv8600mgt_backlight.c \
 		mactel/kbd_backlight.c mactel/ambient.c mactel/acpi.c
@@ -67,12 +67,14 @@
 
 pommed: $(OBJS) $(LIBS)
 
-pommed.o: pommed.c pommed.h kbd_backlight.h lcd_backlight.h cd_eject.h evdev.h conffile.h audio.h dbus.h beep.h
+pommed.o: pommed.c pommed.h evloop.h kbd_backlight.h lcd_backlight.h cd_eject.h evdev.h conffile.h audio.h dbus.h beep.h
 
 cd_eject.o: cd_eject.c cd_eject.h pommed.h conffile.h dbus.h
 
-evdev.o: evdev.c evdev.h pommed.h kbd_backlight.h lcd_backlight.h cd_eject.h conffile.h audio.h video.h beep.h
+evdev.o: evdev.c evdev.h evloop.h pommed.h kbd_backlight.h lcd_backlight.h cd_eject.h conffile.h audio.h video.h beep.h
 
+evloop.o: evloop.c evloop.h pommed.h
+
 conffile.o: conffile.c conffile.h pommed.h lcd_backlight.h kbd_backlight.h cd_eject.h audio.h beep.h
 
 audio.o: audio.c audio.h pommed.h conffile.h dbus.h
@@ -81,7 +83,7 @@
 
 power.o: power.c power.h pommed.h lcd_backlight.h
 
-beep.o: beep.c beep.h pommed.h audio.h
+beep.o: beep.c beep.h pommed.h evloop.h audio.h
 
 video.o: video.c video.h pommed.h dbus.h
 

Modified: trunk/pommed/beep.c
===================================================================
--- trunk/pommed/beep.c	2008-06-02 17:02:50 UTC (rev 480)
+++ trunk/pommed/beep.c	2008-06-02 18:21:57 UTC (rev 481)
@@ -3,7 +3,7 @@
  *
  * $Id$
  *
- * Copyright (C) 2006-2007 Julien BLACHE <jb at jblache.org>
+ * Copyright (C) 2006-2008 Julien BLACHE <jb at jblache.org>
  * Copyright (C) 2006 Soeren SONNENBURG <debian at nn7.de>
  *
  * Portions of the code below dealing with the audio thread were shamelessly
@@ -33,6 +33,8 @@
 
 #include <syslog.h>
 
+#include <sys/epoll.h>
+
 #include <linux/input.h>
 #include <linux/uinput.h>
 
@@ -44,6 +46,7 @@
 #include <audiofile.h>
 
 #include "pommed.h"
+#include "evloop.h"
 #include "conffile.h"
 #include "audio.h"
 #include "beep.h"
@@ -56,7 +59,7 @@
 #endif
 
 
-struct _beep_info beep_info;
+static int beep_fd;
 static int beep_thread_running = 0;
 
 
@@ -71,7 +74,7 @@
 beep_thread_init(void);
 
 
-void
+static void
 beep_beep(void)
 {
   if (!beep_cfg.enabled)
@@ -93,7 +96,7 @@
 }
 
 
-int
+static int
 beep_open_device(void)
 {
   char *uinput_dev[3] =
@@ -107,8 +110,6 @@
   int i;
   int ret;
 
-  beep_info.fd = -1;
-
   if (beep_cfg.enabled == 0)
     return -1;
 
@@ -180,30 +181,71 @@
       return -1;
   }
 
-  beep_info.fd = fd;
+  beep_fd = fd;
 
   return 0;
 }
 
-void
+static void
 beep_close_device(void)
 {
-  if (!beep_cfg.enabled)
+  if (!beep_cfg.enabled || (beep_fd == -1))
     return;
 
-  ioctl(beep_info.fd, UI_DEV_DESTROY, NULL);
+  evloop_remove(beep_fd);
 
-  close(beep_info.fd);
+  ioctl(beep_fd, UI_DEV_DESTROY, NULL);
 
-  beep_info.fd = -1;
+  close(beep_fd);
+
+  beep_fd = -1;
 }
 
 
+void
+beep_process_events(int fd, uint32_t events)
+{
+  int ret;
+
+  struct input_event ev;
+
+  if (events & (EPOLLERR | EPOLLHUP))
+    {
+      logmsg(LOG_WARNING, "Beeper device lost; this should not happen");
+
+      ret = evloop_remove(fd);
+      if (ret < 0)
+	logmsg(LOG_ERR, "Could not remove beeper device from event loop");
+
+      beep_close_device();
+
+      return;
+    }
+
+  ret = read(fd, &ev, sizeof(struct input_event));
+
+  if (ret != sizeof(struct input_event))
+    return;
+
+  if (ev.type == EV_SND)
+    {
+      if ((ev.code == SND_TONE) && (ev.value > 0))
+	{
+	  logdebug("\nBEEP: BEEP!\n");
+
+	  beep_beep(); /* Catch that, Coyote */
+	}
+    }
+}
+
+
 int
 beep_init(void)
 {
   int ret;
 
+  beep_fd = -1;
+
   ret = beep_thread_init();
   if (ret < 0)
     {
@@ -216,17 +258,35 @@
 
   beep_thread_running = 1;
 
+  ret = beep_open_device();
+  if (ret < 0)
+    return -1;
+
+  ret = evloop_add(beep_fd, EPOLLIN, beep_process_events);
+  if (ret < 0)
+    {
+      logmsg(LOG_ERR, "Could not add device to event loop");
+
+      beep_cfg.enabled = 0;
+
+      beep_close_device();
+
+      return -1;
+    }
+
   return 0;
 }
 
 void
 beep_cleanup(void)
 {
-  if (!beep_thread_running)
-    return;
+  if (beep_thread_running)
+    {
+      beep_thread_command(AUDIO_COMMAND_QUIT);
+      beep_thread_cleanup();
+    }
 
-  beep_thread_command(AUDIO_COMMAND_QUIT);
-  beep_thread_cleanup();
+  beep_close_device();
 }
 
 void

Modified: trunk/pommed/beep.h
===================================================================
--- trunk/pommed/beep.h	2008-06-02 17:02:50 UTC (rev 480)
+++ trunk/pommed/beep.h	2008-06-02 18:21:57 UTC (rev 481)
@@ -5,30 +5,14 @@
 #ifndef __BEEP_H__
 #define __BEEP_H__
 
-struct _beep_info
-{
-  int fd;
-};
 
-extern struct _beep_info beep_info;
-
-
 #define BEEP_DEFAULT_FILE    "/usr/share/pommed/goutte.wav"
 #define BEEP_DEVICE_NAME     "Pommed beeper device"
 
 void
-beep_beep(void);
-
-void
 beep_audio(void);
 
 int
-beep_open_device(void);
-
-void
-beep_close_device(void);
-
-int
 beep_init(void);
 
 void

Modified: trunk/pommed/evdev.c
===================================================================
--- trunk/pommed/evdev.c	2008-06-02 17:02:50 UTC (rev 480)
+++ trunk/pommed/evdev.c	2008-06-02 18:21:57 UTC (rev 481)
@@ -45,6 +45,7 @@
 #include "pommed.h"
 #include "conffile.h"
 #include "evdev.h"
+#include "evloop.h"
 #include "kbd_backlight.h"
 #include "lcd_backlight.h"
 #include "cd_eject.h"
@@ -66,85 +67,37 @@
 #endif
 
 
-/* Open event devices */
-static int ev_fds[EVDEV_MAX];
+void
+evdev_process_events(int fd, uint32_t events);
 
-/* epoll fd */
-static int epfd;
+void
+evdev_inotify_process(int fd, uint32_t events);
 
-/* inotify fd */
-static int ifd;
-
-
 static int
 evdev_try_add(int fd);
 
 
-static int
-evdev_add(int fd)
+void
+evdev_process_events(int fd, uint32_t events)
 {
-  int i;
   int ret;
 
-  struct epoll_event epoll_ev;
+  struct input_event ev;
 
-  for (i = 0; i < EVDEV_MAX; i++)
+  /* some of the event devices cease to exist when suspending */
+  if (events & (EPOLLERR | EPOLLHUP))
     {
-      if (ev_fds[i] == -1)
-	{
-	  ev_fds[i] = fd;
+      logmsg(LOG_INFO, "Error condition signaled on event device");
 
-	  break;
-	}
-    }
+      ret = evloop_remove(fd);
+      if (ret < 0)
+	logmsg(LOG_ERR, "Could not remove device from event loop");
 
-  epoll_ev.events = EPOLLIN;
-  epoll_ev.data.fd = fd;
+      close(fd);
 
-  ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &epoll_ev);
-
-  if (ret < 0)
-    {
-      logmsg(LOG_ERR, "Could not add device to epoll: %s", strerror(errno));
-
-      return -1;
+      return;
     }
 
-  return 0;
-}
-
-static void
-evdev_remove(int fd)
-{
-  int i;
-  int ret;
-
-  for (i = 0; i < EVDEV_MAX; i++)
-    {
-      if (ev_fds[i] == fd)
-	{
-	  ev_fds[i] = -1;
-
-	  break;
-	}
-    }
-
-  ret = epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
-
-  if (ret < 0)
-    logmsg(LOG_ERR, "Could not remove device from epoll: %s", strerror(errno));
-
-  close(fd);
-}
-
-
-static void
-evdev_process_events(int fd)
-{
-  int ret;
-
-  struct input_event ev;
-
   ret = read(fd, &ev, sizeof(struct input_event));
 
   if (ret != sizeof(struct input_event))
@@ -257,16 +210,6 @@
 	    break;
 	}
     }
-  else if (ev.type == EV_SND)
-    {
-      /* Beeper device */
-      if ((ev.code == SND_TONE) && (ev.value > 0))
-	{
-	  logdebug("\nBEEP: BEEP!\n");
-
-	  beep_beep(); /* Catch that, Coyote */
-	}
-    }
   else if (ev.type == EV_SW)
     {
       /* Lid switch */
@@ -289,19 +232,32 @@
 }
 
 
-static void
-evdev_inotify_process(void)
+void
+evdev_inotify_process(int fd, uint32_t events)
 {
   int ret;
-  int fd;
+  int efd;
   int qsize;
 
   struct inotify_event *all_ie;
   struct inotify_event *ie;
   char evdev[32];
 
+  if (events & (EPOLLERR | EPOLLHUP))
+    {
+      logmsg(LOG_WARNING, "inotify fd lost; this should not happen");
+
+      ret = evloop_remove(fd);
+      if (ret < 0)
+	logmsg(LOG_ERR, "Could not remove inotify from event loop");
+
+      close(fd);
+
+      return;
+    }
+
   /* Determine the size of the inotify queue */
-  ret = ioctl(ifd, FIONREAD, &qsize);
+  ret = ioctl(fd, FIONREAD, &qsize);
   if (ret < 0)
     {
       logmsg(LOG_ERR, "Could not determine inotify queue size: %s", strerror(errno));
@@ -317,7 +273,7 @@
       return;
     }
 
-  ret = read(ifd, all_ie, qsize);
+  ret = read(fd, all_ie, qsize);
   if (ret < 0)
     {
       logmsg(LOG_WARNING, "inotify read failed: %s", strerror(errno));
@@ -358,8 +314,8 @@
       if ((ret <= 0) || (ret >= sizeof(evdev)))
 	continue;
 
-      fd = open(evdev, O_RDWR);
-      if (fd < 0)
+      efd = open(evdev, O_RDWR);
+      if (efd < 0)
 	{
 	  if (errno != ENOENT)
 	    logmsg(LOG_WARNING, "Could not open %s: %s", evdev, strerror(errno));
@@ -367,75 +323,13 @@
 	  continue;
 	}
 
-      evdev_try_add(fd);
+      evdev_try_add(efd);
     }
 
   free(all_ie);
 }
 
 
-int
-evdev_event_loop(void)
-{
-  int i;
-  int nfds;
-
-  int inotify = 0;
-
-  struct epoll_event events[MAX_EPOLL_EVENTS];
-
-  nfds = epoll_wait(epfd, events, MAX_EPOLL_EVENTS, LOOP_TIMEOUT);
-
-  if (nfds < 0)
-    {
-      if (errno == EINTR)
-	return 1; /* pommed.c will go on with the events management */
-      else
-	{
-	  logmsg(LOG_ERR, "epoll_wait() error: %s", strerror(errno));
-
-	  return -1; /* pommed.c will exit */
-	}
-    }
-
-
-  for (i = 0; i < nfds; i++)
-    {
-      /* some of the event devices cease to exist when suspending */
-      if (events[i].events & (EPOLLERR | EPOLLHUP))
-	{
-	  logmsg(LOG_INFO, "Error condition signaled on event device");
-
-	  if (events[i].data.fd == beep_info.fd)
-	    logmsg(LOG_WARNING, "Beeper device lost; this should not happen");
-
-	  if (events[i].data.fd == ifd)
-	    {
-	      logmsg(LOG_WARNING, "inotify fd lost; this should not happen");
-	      ifd = -1;
-	    }
-
-	  evdev_remove(events[i].data.fd);
-
-	  continue;
-	}
-
-      if (events[i].events & EPOLLIN)
-	{
-	  if (events[i].data.fd == ifd)
-	    inotify = 1; /* defer inotify events processing */
-	  else
-	    evdev_process_events(events[i].data.fd);
-	}
-    }
-
-  if (inotify)
-    evdev_inotify_process();
-
-  return nfds;
-}
-
-
 #ifdef __powerpc__
 /* PowerBook G4 Titanium */
 static int
@@ -906,9 +800,15 @@
       return -1;
     }
 
-  ret = evdev_add(fd);
+  ret = evloop_add(fd, EPOLLIN, evdev_process_events);
+  if (ret < 0)
+    {
+      logmsg(LOG_ERR, "Could not add device to event loop");
 
-  return ret;
+      return -1;
+    }
+
+  return 0;
 }
 
 
@@ -916,36 +816,33 @@
 evdev_inotify_init(void)
 {
   int ret;
-  struct epoll_event epoll_ev;
+  int fd;
 
-  ifd = inotify_init();
-  if (ifd < 0)
+  fd = inotify_init();
+  if (fd < 0)
     {
       logmsg(LOG_ERR, "Failed to initialize inotify: %s", strerror(errno));
 
       return -1;
     }
 
-  ret = inotify_add_watch(ifd, EVDEV_DIR, IN_CREATE | IN_ONLYDIR);
+  ret = inotify_add_watch(fd, EVDEV_DIR, IN_CREATE | IN_ONLYDIR);
   if (ret < 0)
     {
       logmsg(LOG_ERR, "Failed to add inotify watch for %s: %s", EVDEV_DIR, strerror(errno));
 
-      close(ifd);
-      ifd = -1;
+      close(fd);
+      fd = -1;
 
       return -1;
     }
 
-  epoll_ev.events = EPOLLIN;
-  epoll_ev.data.fd = ifd;
-
-  ret = epoll_ctl(epfd, EPOLL_CTL_ADD, ifd, &epoll_ev);
+  ret = evloop_add(fd, EPOLLIN, evdev_inotify_process);
   if (ret < 0)
     {
-      logmsg(LOG_ERR, "Failed to add inotify fd to epoll: %s", strerror(errno));
+      logmsg(LOG_ERR, "Failed to add inotify fd to event loop");
 
-      close(ifd);
+      close(fd);
 
       return -1;
     }
@@ -965,19 +862,6 @@
   int ndevs;
   int fd;
 
-  epfd = epoll_create(MAX_EPOLL_EVENTS);
-  if (epfd < 0)
-    {
-      logmsg(LOG_ERR, "Could not create epoll fd: %s", strerror(errno));
-
-      return -1;
-    }
-
-  for (i = 0; i < EVDEV_MAX; i++)
-    {
-      ev_fds[i] = -1;
-    }
-
   ndevs = 0;
   for (i = 0; i < EVDEV_MAX; i++)
     {
@@ -1001,16 +885,6 @@
 
   logdebug("\nFound %d devices\n", ndevs);
 
-  /* Add the beeper device */
-  ret = beep_open_device();
-  if (ret == 0)
-    {
-      ret = evdev_add(beep_info.fd);
-
-      if (ret == 0)
-	  ndevs++;
-    }
-
   /* Initialize inotify */
   evdev_inotify_init();
 
@@ -1020,17 +894,5 @@
 void
 evdev_cleanup(void)
 {
-  int i;
-
-  close(epfd);
-
-  close(ifd);
-
-  for (i = 0; i < EVDEV_MAX; i++)
-    {
-      if (ev_fds[i] == beep_info.fd)
-	beep_close_device();
-      else
-	close(ev_fds[i]);
-    }
+  /* evloop_cleanup() takes care of closing the devices */
 }

Modified: trunk/pommed/evdev.h
===================================================================
--- trunk/pommed/evdev.h	2008-06-02 17:02:50 UTC (rev 480)
+++ trunk/pommed/evdev.h	2008-06-02 18:21:57 UTC (rev 481)
@@ -100,13 +100,8 @@
 #define EVDEV_BASE              "/dev/input/event"
 #define EVDEV_MAX               32
 
-#define MAX_EPOLL_EVENTS        8
 
-
 int
-evdev_event_loop(void);
-
-int
 evdev_init(void);
 
 void

Added: trunk/pommed/evloop.c
===================================================================
--- trunk/pommed/evloop.c	                        (rev 0)
+++ trunk/pommed/evloop.c	2008-06-02 18:21:57 UTC (rev 481)
@@ -0,0 +1,186 @@
+/*
+ * pommed - Apple laptops hotkeys handler daemon
+ *
+ * $Id$
+ *
+ * Copyright (C) 2006-2008 Julien BLACHE <jb at jblache.org>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include <syslog.h>
+
+#include <errno.h>
+
+#include <sys/epoll.h>
+
+#include "pommed.h"
+#include "evloop.h"
+
+
+/* epoll fd */
+static int epfd;
+
+/* event sources registered on the main loop */
+static struct pommed_event *sources;
+
+
+int
+evloop_add(int fd, uint32_t events, pommed_event_cb cb)
+{
+  int ret;
+
+  struct epoll_event epoll_ev;
+  struct pommed_event *pommed_ev;
+
+  pommed_ev = (struct pommed_event *)malloc(sizeof(*pommed_ev));
+
+  if (pommed_ev == NULL)
+    {
+      logmsg(LOG_ERR, "Could not allocate memory for new event");
+
+      return -1;
+    }
+
+  pommed_ev->fd = fd;
+  pommed_ev->cb = cb;
+  pommed_ev->next = sources;
+
+  epoll_ev.events = events;
+  epoll_ev.data.ptr = pommed_ev;
+
+  ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &epoll_ev);
+
+  if (ret < 0)
+    {
+      logmsg(LOG_ERR, "Could not add device to epoll: %s", strerror(errno));
+
+      free(pommed_ev);
+      return -1;
+    }
+
+  sources = pommed_ev;
+
+  return 0;
+}
+
+int
+evloop_remove(int fd)
+{
+  int ret;
+
+  struct pommed_event *p;
+  struct pommed_event *e;
+
+  ret = epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
+
+  if (ret < 0)
+    {
+      logmsg(LOG_ERR, "Could not remove device from epoll: %s", strerror(errno));
+
+      return -1;
+    }
+
+  for (p = NULL, e = sources; e != NULL; p = e, e = e->next)
+    {
+      if (e->fd != fd)
+	continue;
+
+      if (p != NULL)
+	p->next = e->next;
+      else
+	sources = e->next;
+
+      free(e);
+
+      break;
+    }
+
+  return 0;
+}
+
+
+int
+evloop_iteration(void)
+{
+  int i;
+  int nfds;
+
+  struct epoll_event epoll_ev[MAX_EPOLL_EVENTS];
+  struct pommed_event *pommed_ev;
+
+  nfds = epoll_wait(epfd, epoll_ev, MAX_EPOLL_EVENTS, LOOP_TIMEOUT);
+
+  if (nfds < 0)
+    {
+      if (errno == EINTR)
+	return 1; /* pommed.c will go on with the events management */
+      else
+	{
+	  logmsg(LOG_ERR, "epoll_wait() error: %s", strerror(errno));
+
+	  return -1; /* pommed.c will exit */
+	}
+    }
+
+  for (i = 0; i < nfds; i++)
+    {
+      pommed_ev = epoll_ev[i].data.ptr;
+      pommed_ev->cb(pommed_ev->fd, epoll_ev[i].events);
+    }
+
+  return nfds;
+}
+
+
+int
+evloop_init(void)
+{
+  sources = NULL;
+
+  epfd = epoll_create(MAX_EPOLL_EVENTS);
+  if (epfd < 0)
+    {
+      logmsg(LOG_ERR, "Could not create epoll fd: %s", strerror(errno));
+
+      return -1;
+    }
+
+  return 0;
+}
+
+void
+evloop_cleanup(void)
+{
+  struct pommed_event *p;
+
+  close(epfd);
+
+  while (sources != NULL)
+    {
+      p = sources;
+      sources = sources->next;
+
+      close(p->fd);
+
+      free(p);
+    }
+}


Property changes on: trunk/pommed/evloop.c
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/pommed/evloop.h
===================================================================
--- trunk/pommed/evloop.h	                        (rev 0)
+++ trunk/pommed/evloop.h	2008-06-02 18:21:57 UTC (rev 481)
@@ -0,0 +1,37 @@
+/*
+ * $Id$
+ */
+
+#ifndef __EVLOOP_H__
+#define __EVLOOP_H__
+
+
+#define MAX_EPOLL_EVENTS        8
+
+typedef void(*pommed_event_cb)(int fd, uint32_t events);
+
+struct pommed_event
+{
+  int fd;
+  pommed_event_cb cb;
+  struct pommed_event *next;
+};
+
+
+int
+evloop_add(int fd, uint32_t events, pommed_event_cb cb);
+
+int
+evloop_remove(int fd);
+
+int
+evloop_iteration(void);
+
+int
+evloop_init(void);
+
+void
+evloop_cleanup(void);
+
+
+#endif /* __EVLOOP_H__ */


Property changes on: trunk/pommed/evloop.h
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/pommed/pommed.c
===================================================================
--- trunk/pommed/pommed.c	2008-06-02 17:02:50 UTC (rev 480)
+++ trunk/pommed/pommed.c	2008-06-02 18:21:57 UTC (rev 481)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -48,6 +49,7 @@
 #include "lcd_backlight.h"
 #include "cd_eject.h"
 #include "evdev.h"
+#include "evloop.h"
 #include "conffile.h"
 #include "audio.h"
 #include "dbus.h"
@@ -792,6 +794,13 @@
       exit(1);
     }
 
+  ret = evloop_init();
+  if (ret < 0)
+    {
+      logmsg(LOG_ERR, "Event loop initialization failed");
+      exit (1);
+    }
+
   ret = clock_gettime(CLOCK_MONOTONIC, &tp_als);
   if (ret < 0)
     {
@@ -868,7 +877,7 @@
 
   while (running)
     {
-      ret = evdev_event_loop();
+      ret = evloop_iteration();
 
       if (ret < 0) /* error */
 	{
@@ -933,6 +942,8 @@
 
   mbpdbus_cleanup();
 
+  evloop_cleanup();
+
   config_cleanup();
 
   logmsg(LOG_INFO, "Exiting");




More information about the Pommed-commits mailing list