[Pommed-commits] r482 - in trunk: . pommed pommed/mactel pommed/pmac
jblache at alioth.debian.org
jblache at alioth.debian.org
Tue Jun 3 17:19:05 UTC 2008
Author: jblache
Date: 2008-06-03 17:19:03 +0000 (Tue, 03 Jun 2008)
New Revision: 482
Added:
trunk/pommed/timerfd-syscalls.h
Modified:
trunk/ChangeLog
trunk/README
trunk/pommed/Makefile
trunk/pommed/conffile.c
trunk/pommed/dbus.c
trunk/pommed/dbus.h
trunk/pommed/evloop.c
trunk/pommed/evloop.h
trunk/pommed/kbd_auto.c
trunk/pommed/kbd_backlight.h
trunk/pommed/mactel/kbd_backlight.c
trunk/pommed/pmac/kbd_backlight.c
trunk/pommed/pommed.c
trunk/pommed/pommed.h
trunk/pommed/power.c
trunk/pommed/power.h
Log:
Integrate DBus, power and automatic keyboard as timers into the event loop.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/ChangeLog 2008-06-03 17:19:03 UTC (rev 482)
@@ -6,6 +6,8 @@
- 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.
+ - pommed: convert power, kbd and dbus to timers integrated into
+ the event loop.
version 1.18:
- pommed: add more IDs for Apple external keyboards
Modified: trunk/README
===================================================================
--- trunk/README 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/README 2008-06-03 17:19:03 UTC (rev 482)
@@ -12,17 +12,10 @@
Kernel version requirements:
----------------------------
- - on the MacBook, MacBook Pro and MacBook Air
- + kernel >= 2.6.19 at least
- + kernel >= 2.6.20 recommended
- Newer machines may require a newer kernel and/or patches.
+ pommed requires at least a 2.6.25 kernel, due to the use of the new timerfd
+ interface that was released as stable with this version.
- - on the PowerBook and iBook
- + kernel >= 2.6.19 recommended
- Warning: kernels 2.6.20 and 2.6.20.x x < 7 are buggy; pommed will fail
- to detect the USB keyboards when run with one of these kernels.
-
Supported machines:
-------------------
Modified: trunk/pommed/Makefile
===================================================================
--- trunk/pommed/Makefile 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/Makefile 2008-06-03 17:19:03 UTC (rev 482)
@@ -18,7 +18,7 @@
CFLAGS = -g -O2 -Wall $(DBUS_CFLAGS) $(ALSA_CFLAGS) $(AUDIOFILE_CFLAGS) $(CONFUSE_CFLAGS) $(INOTIFY_CFLAGS)
-LDFLAGS = -pthread $(DBUS_LIBS) $(ALSA_LIBS) $(AUDIOFILE_LIBS) $(CONFUSE_LIBS)
+LDFLAGS = -pthread -lrt $(DBUS_LIBS) $(ALSA_LIBS) $(AUDIOFILE_LIBS) $(CONFUSE_LIBS)
ifneq (, $(findstring ppc, $(ARCH)))
OFLIB ?=
@@ -79,9 +79,9 @@
audio.o: audio.c audio.h pommed.h conffile.h dbus.h
-dbus.o: dbus.c dbus.h pommed.h lcd_backlight.h kbd_backlight.h ambient.h audio.h
+dbus.o: dbus.c dbus.h evloop.h pommed.h lcd_backlight.h kbd_backlight.h ambient.h audio.h
-power.o: power.c power.h pommed.h lcd_backlight.h
+power.o: power.c power.h evloop.h pommed.h lcd_backlight.h
beep.o: beep.c beep.h pommed.h evloop.h audio.h
@@ -89,7 +89,7 @@
# PowerMac-specific files
-pmac/kbd_backlight.o: pmac/kbd_backlight.c kbd_auto.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
+pmac/kbd_backlight.o: pmac/kbd_backlight.c kbd_auto.c kbd_backlight.h evloop.h pommed.h ambient.h conffile.h dbus.h
pmac/sysfs_backlight.o: pmac/sysfs_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
@@ -115,7 +115,7 @@
mactel/nv8600mgt_backlight.o: mactel/nv8600mgt_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
-mactel/kbd_backlight.o: mactel/kbd_backlight.c kbd_auto.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
+mactel/kbd_backlight.o: mactel/kbd_backlight.c kbd_auto.c kbd_backlight.h evloop.h pommed.h ambient.h conffile.h dbus.h
mactel/ambient.o: mactel/ambient.c ambient.h pommed.h dbus.h
Modified: trunk/pommed/conffile.c
===================================================================
--- trunk/pommed/conffile.c 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/conffile.c 2008-06-03 17:19:03 UTC (rev 482)
@@ -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>
*
* 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
@@ -231,7 +231,7 @@
printf(" auto on threshold: %d\n", kbd_cfg.on_thresh);
printf(" auto off threshold: %d\n", kbd_cfg.off_thresh);
printf(" auto enable: %s\n", (kbd_cfg.auto_on) ? "yes" : "no");
- printf(" idle timer: %d%s\n", (kbd_cfg.idle * LOOP_TIMEOUT) / 1000, (kbd_cfg.idle > 0) ? "s" : "");
+ printf(" idle timer: %d%s\n", (kbd_cfg.idle * KBD_TIMEOUT) / 1000, (kbd_cfg.idle > 0) ? "s" : "");
printf(" + CD eject:\n");
printf(" enabled: %s\n", (eject_cfg.enabled) ? "yes" : "no");
printf(" device: %s\n", eject_cfg.device);
Modified: trunk/pommed/dbus.c
===================================================================
--- trunk/pommed/dbus.c 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/dbus.c 2008-06-03 17:19:03 UTC (rev 482)
@@ -20,12 +20,15 @@
*/
#include <stdio.h>
+#include <unistd.h>
+#include <stdint.h>
#include <syslog.h>
#include <dbus/dbus.h>
#include "pommed.h"
+#include "evloop.h"
#include "dbus.h"
#include "lcd_backlight.h"
#include "kbd_backlight.h"
@@ -37,7 +40,9 @@
static DBusError err;
static DBusConnection *conn;
+static int dbus_timer;
+
void
mbpdbus_send_lcd_backlight(int cur, int prev, int who)
{
@@ -732,13 +737,17 @@
}
-void
-mbpdbus_process_requests(void)
+static void
+mbpdbus_process_requests(int fd, uint32_t events)
{
DBusMessage *msg;
-
int nmsg;
+ uint64_t dummy;
+
+ /* Acknowledge timer */
+ read(fd, &dummy, sizeof(dummy));
+
if (conn == NULL)
{
if (mbpdbus_init() < 0)
@@ -853,6 +862,14 @@
return -1;
}
+ dbus_timer = evloop_add_timer(DBUS_TIMEOUT, mbpdbus_process_requests);
+ if (ret < 0)
+ {
+ mbpdbus_cleanup();
+
+ return -1;
+ }
+
return 0;
}
@@ -862,6 +879,9 @@
if (conn == NULL)
return;
+ if (dbus_timer != -1)
+ evloop_remove_timer(dbus_timer);
+
dbus_error_free(&err);
/* This is a shared connection owned by libdbus
Modified: trunk/pommed/dbus.h
===================================================================
--- trunk/pommed/dbus.h 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/dbus.h 2008-06-03 17:19:03 UTC (rev 482)
@@ -5,7 +5,9 @@
#ifndef __MBPDBUS_H__
#define __MBPDBUS_H__
+#define DBUS_TIMEOUT 200
+
void
mbpdbus_send_lcd_backlight(int cur, int prev, int who);
@@ -28,10 +30,6 @@
mbpdbus_send_video_switch(void);
-void
-mbpdbus_process_requests(void);
-
-
int
mbpdbus_init(void);
Modified: trunk/pommed/evloop.c
===================================================================
--- trunk/pommed/evloop.c 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/evloop.c 2008-06-03 17:19:03 UTC (rev 482)
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <fcntl.h>
#include <string.h>
+#include <time.h>
#include <syslog.h>
@@ -32,6 +33,8 @@
#include <sys/epoll.h>
+#include "timerfd-syscalls.h"
+
#include "pommed.h"
#include "evloop.h"
@@ -42,7 +45,9 @@
/* event sources registered on the main loop */
static struct pommed_event *sources;
+static int running;
+
int
evloop_add(int fd, uint32_t events, pommed_event_cb cb)
{
@@ -55,7 +60,7 @@
if (pommed_ev == NULL)
{
- logmsg(LOG_ERR, "Could not allocate memory for new event");
+ logmsg(LOG_ERR, "Could not allocate memory for new source");
return -1;
}
@@ -71,7 +76,7 @@
if (ret < 0)
{
- logmsg(LOG_ERR, "Could not add device to epoll: %s", strerror(errno));
+ logmsg(LOG_ERR, "Could not add source to epoll: %s", strerror(errno));
free(pommed_ev);
return -1;
@@ -94,7 +99,7 @@
if (ret < 0)
{
- logmsg(LOG_ERR, "Could not remove device from epoll: %s", strerror(errno));
+ logmsg(LOG_ERR, "Could not remove source from epoll: %s", strerror(errno));
return -1;
}
@@ -119,6 +124,76 @@
int
+evloop_add_timer(int timeout, pommed_event_cb cb)
+{
+ int fd;
+ int ret;
+
+ struct itimerspec timing;
+
+ fd = timerfd_create(CLOCK_MONOTONIC, 0);
+ if (fd < 0)
+ {
+ logmsg(LOG_ERR, "Could not create timer: %s", strerror(errno));
+
+ return -1;
+ }
+
+ timing.it_interval.tv_sec = (timeout >= 1000) ? timeout / 1000 : 0;
+ timing.it_interval.tv_nsec = (timeout - (timing.it_interval.tv_sec * 1000)) * 1000000;
+
+ ret = clock_gettime(CLOCK_MONOTONIC, &timing.it_value);
+ if (ret < 0)
+ {
+ logmsg(LOG_ERR, "Could not get current time: %s", strerror(errno));
+
+ close(fd);
+ return -1;
+ }
+
+ timing.it_value.tv_sec += timing.it_interval.tv_sec;
+ timing.it_value.tv_nsec += timing.it_interval.tv_nsec;
+ if (timing.it_value.tv_nsec > 1000000000)
+ {
+ timing.it_value.tv_sec++;
+ timing.it_value.tv_nsec -= 1000000000;
+ }
+
+ ret = timerfd_settime(fd, TFD_TIMER_ABSTIME, &timing, NULL);
+ if (ret < 0)
+ {
+ logmsg(LOG_ERR, "Could not setup timer: %s", strerror(errno));
+
+ close(fd);
+ return -1;
+ }
+
+ ret = evloop_add(fd, EPOLLIN, cb);
+ if (ret < 0)
+ {
+ close(fd);
+ return -1;
+ }
+
+ return fd;
+}
+
+int
+evloop_remove_timer(int fd)
+{
+ int ret;
+
+ ret = evloop_remove(fd);
+ if (ret < 0)
+ return ret;
+
+ close(fd);
+
+ return 0;
+}
+
+
+int
evloop_iteration(void)
{
int i;
@@ -127,12 +202,15 @@
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 (!running)
+ return -1;
+ nfds = epoll_wait(epfd, epoll_ev, MAX_EPOLL_EVENTS, -1);
+
if (nfds < 0)
{
if (errno == EINTR)
- return 1; /* pommed.c will go on with the events management */
+ return 0; /* pommed.c will continue */
else
{
logmsg(LOG_ERR, "epoll_wait() error: %s", strerror(errno));
@@ -150,11 +228,18 @@
return nfds;
}
+void
+evloop_stop(void)
+{
+ running = 0;
+}
+
int
evloop_init(void)
{
sources = NULL;
+ running = 1;
epfd = epoll_create(MAX_EPOLL_EVENTS);
if (epfd < 0)
Modified: trunk/pommed/evloop.h
===================================================================
--- trunk/pommed/evloop.h 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/evloop.h 2008-06-03 17:19:03 UTC (rev 482)
@@ -25,8 +25,17 @@
evloop_remove(int fd);
int
+evloop_add_timer(int timeout, pommed_event_cb cb);
+
+int
+evloop_remove_timer(int fd);
+
+int
evloop_iteration(void);
+void
+evloop_stop(void);
+
int
evloop_init(void);
Modified: trunk/pommed/kbd_auto.c
===================================================================
--- trunk/pommed/kbd_auto.c 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/kbd_auto.c 2008-06-03 17:19:03 UTC (rev 482)
@@ -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>
*
* 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
@@ -19,6 +19,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+
+static int kbd_timer;
+
+
/* simple backlight toggle */
void
kbd_backlight_toggle(void)
@@ -135,3 +139,38 @@
}
}
}
+
+
+static void
+kbd_auto_process(int fd, uint32_t events)
+{
+ uint64_t dummy;
+
+ /* Acknowledge timer */
+ read(fd, &dummy, sizeof(dummy));
+
+ /* Increment keyboard backlight idle timer */
+ kbd_bck_info.idle++;
+ if ((kbd_cfg.idle > 0) && (kbd_bck_info.idle > kbd_cfg.idle))
+ kbd_backlight_inhibit_set(KBD_INHIBIT_IDLE);
+
+ kbd_backlight_ambient_check();
+}
+
+
+static int
+kbd_auto_init(void)
+{
+ kbd_timer = evloop_add_timer(KBD_TIMEOUT, kbd_auto_process);
+ if (kbd_timer < 0)
+ return -1;
+
+ return 0;
+}
+
+static void
+kbd_auto_cleanup(void)
+{
+ if (kbd_timer > 0)
+ evloop_remove_timer(kbd_timer);
+}
Modified: trunk/pommed/kbd_backlight.h
===================================================================
--- trunk/pommed/kbd_backlight.h 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/kbd_backlight.h 2008-06-03 17:19:03 UTC (rev 482)
@@ -25,11 +25,12 @@
#define KBD_MASK_AUTO (KBD_INHIBIT_LID | KBD_INHIBIT_IDLE)
-
#define KBD_USER 0
#define KBD_AUTO 1
+#define KBD_TIMEOUT 200
+
struct _kbd_bck_info
{
int level;
@@ -84,6 +85,9 @@
kbd_backlight_init(void);
void
+kbd_backlight_cleanup(void);
+
+void
kbd_backlight_fix_config(void);
Modified: trunk/pommed/mactel/kbd_backlight.c
===================================================================
--- trunk/pommed/mactel/kbd_backlight.c 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/mactel/kbd_backlight.c 2008-06-03 17:19:03 UTC (rev 482)
@@ -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>
@@ -33,6 +34,7 @@
#include <errno.h>
#include "../pommed.h"
+#include "../evloop.h"
#include "../conffile.h"
#include "../kbd_backlight.h"
#include "../ambient.h"
@@ -255,9 +257,18 @@
kbd_bck_info.max = KBD_BACKLIGHT_MAX;
ambient_init(&kbd_bck_info.r_sens, &kbd_bck_info.l_sens);
+
+ kbd_auto_init();
}
+void
+kbd_backlight_cleanup(void)
+{
+ if (has_kbd_backlight())
+ kbd_auto_cleanup();
+}
+
void
kbd_backlight_fix_config(void)
{
@@ -271,5 +282,5 @@
kbd_cfg.step = KBD_BACKLIGHT_MAX / 2;
if (kbd_cfg.idle > 0)
- kbd_cfg.idle = (kbd_cfg.idle * 1000) / LOOP_TIMEOUT;
+ kbd_cfg.idle = (kbd_cfg.idle * 1000) / KBD_TIMEOUT;
}
Modified: trunk/pommed/pmac/kbd_backlight.c
===================================================================
--- trunk/pommed/pmac/kbd_backlight.c 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/pmac/kbd_backlight.c 2008-06-03 17:19:03 UTC (rev 482)
@@ -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 Yves-Alexis Perez <corsac at corsac.net>
*
* This program is free software; you can redistribute it and/or modify
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -41,6 +42,7 @@
#include <ofapi/of_api.h>
#include "../pommed.h"
+#include "../evloop.h"
#include "../conffile.h"
#include "../kbd_backlight.h"
#include "../ambient.h"
@@ -367,9 +369,18 @@
kbd_bck_info.max = KBD_BACKLIGHT_MAX;
ambient_init(&kbd_bck_info.r_sens, &kbd_bck_info.l_sens);
+
+ kbd_auto_init();
}
+void
+kbd_backlight_cleanup(void)
+{
+ if (has_kbd_backlight())
+ kbd_auto_cleanup();
+}
+
void
kbd_backlight_fix_config(void)
{
@@ -383,7 +394,7 @@
kbd_cfg.step = KBD_BACKLIGHT_MAX / 2;
if (kbd_cfg.idle > 0)
- kbd_cfg.idle = (kbd_cfg.idle * 1000) / LOOP_TIMEOUT;
+ kbd_cfg.idle = (kbd_cfg.idle * 1000) / KBD_TIMEOUT;
}
Modified: trunk/pommed/pommed.c
===================================================================
--- trunk/pommed/pommed.c 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/pommed.c 2008-06-03 17:19:03 UTC (rev 482)
@@ -27,7 +27,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
-#include <time.h>
#include <string.h>
#include <signal.h>
@@ -328,10 +327,6 @@
int console = 0;
-/* Used by signal handlers */
-static int running;
-
-
void
logmsg(int level, char *fmt, ...)
{
@@ -687,7 +682,7 @@
void
sig_int_term_handler(int signal)
{
- running = 0;
+ evloop_stop();
}
int
@@ -700,10 +695,6 @@
machine_type machine;
- struct timespec tp_now;
- struct timespec tp_als;
- struct timespec tp_diff;
-
while ((c = getopt(argc, argv, "fdv")) != -1)
{
switch (c)
@@ -801,13 +792,6 @@
exit (1);
}
- ret = clock_gettime(CLOCK_MONOTONIC, &tp_als);
- if (ret < 0)
- {
- logmsg(LOG_ERR, "clock_gettime() failed: %s", strerror(errno));
- exit (1);
- }
-
ret = mops->lcd_backlight_probe();
if (ret < 0)
{
@@ -870,71 +854,15 @@
/* Spawn the beep thread */
beep_init();
- running = 1;
signal(SIGINT, sig_int_term_handler);
signal(SIGTERM, sig_int_term_handler);
- while (running)
+ do
{
ret = evloop_iteration();
-
- if (ret < 0) /* error */
- {
- break;
- }
- else if (ret != 0)
- {
- clock_gettime(CLOCK_MONOTONIC, &tp_now);
-
- /* is it time to chek the ambient light sensors and AC state ? */
- tp_diff.tv_sec = tp_now.tv_sec - tp_als.tv_sec;
-
- if (tp_diff.tv_sec > 1)
- {
- ret = 0;
- }
- else
- {
- tp_diff.tv_nsec = tp_diff.tv_sec * 1000000000;
-
- if (tp_now.tv_nsec > tp_als.tv_nsec)
- {
- tp_diff.tv_nsec += tp_now.tv_nsec - tp_als.tv_nsec;
- }
- else
- {
- tp_diff.tv_nsec -= tp_als.tv_nsec - tp_now.tv_nsec;
- }
-
- if (tp_diff.tv_nsec >= (1000000 * LOOP_TIMEOUT))
- {
- ret = 0; /* go and check ALS, AC state and idle time */
- }
- }
- }
-
- if (ret == 0)
- {
- /* time to check ambient light sensors, AC state and idle time */
- if (has_kbd_backlight())
- {
- /* Increment keyboard backlight idle timer */
- kbd_bck_info.idle++;
- if ((kbd_cfg.idle > 0) && (kbd_bck_info.idle > kbd_cfg.idle))
- kbd_backlight_inhibit_set(KBD_INHIBIT_IDLE);
-
- kbd_backlight_ambient_check();
- }
-
- power_check_ac_state();
-
- tp_als = tp_now;
- }
-
- /* Process DBus requests */
- mbpdbus_process_requests();
}
+ while (ret >= 0);
evdev_cleanup();
@@ -942,6 +870,10 @@
mbpdbus_cleanup();
+ kbd_backlight_cleanup();
+
+ power_cleanup();
+
evloop_cleanup();
config_cleanup();
Modified: trunk/pommed/pommed.h
===================================================================
--- trunk/pommed/pommed.h 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/pommed.h 2008-06-03 17:19:03 UTC (rev 482)
@@ -89,6 +89,4 @@
#define STEP_DOWN -1
-#define LOOP_TIMEOUT 200
-
#endif /* !__POMMED_H__ */
Modified: trunk/pommed/power.c
===================================================================
--- trunk/pommed/power.c 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/power.c 2008-06-03 17:19:03 UTC (rev 482)
@@ -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>
*
* 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
@@ -20,10 +20,13 @@
*/
#include <stdio.h>
+#include <unistd.h>
+#include <stdint.h>
#include <syslog.h>
#include "pommed.h"
+#include "evloop.h"
#include "lcd_backlight.h"
#include "power.h"
@@ -34,13 +37,19 @@
static int prev_state;
+static int power_timer;
-void
-power_check_ac_state(void)
+static void
+power_check_ac_state(int fd, uint32_t events)
{
int ac_state;
+ uint64_t dummy;
+
+ /* Acknowledge timer */
+ read(fd, &dummy, sizeof(dummy));
+
ac_state = check_ac_state();
if (ac_state == prev_state)
@@ -75,4 +84,13 @@
power_init(void)
{
prev_state = check_ac_state();
+
+ power_timer = evloop_add_timer(POWER_TIMEOUT, power_check_ac_state);
}
+
+void
+power_cleanup(void)
+{
+ if (power_timer > 0)
+ evloop_remove_timer(power_timer);
+}
Modified: trunk/pommed/power.h
===================================================================
--- trunk/pommed/power.h 2008-06-02 18:21:57 UTC (rev 481)
+++ trunk/pommed/power.h 2008-06-03 17:19:03 UTC (rev 482)
@@ -12,14 +12,14 @@
#define AC_STATE_ONLINE 1
#define AC_STATE_OFFLINE 0
+#define POWER_TIMEOUT 200
-void
-power_check_ac_state(void);
-
void
power_init(void);
+void
+power_cleanup(void);
#endif /* !__POWER_H__ */
Added: trunk/pommed/timerfd-syscalls.h
===================================================================
--- trunk/pommed/timerfd-syscalls.h (rev 0)
+++ trunk/pommed/timerfd-syscalls.h 2008-06-03 17:19:03 UTC (rev 482)
@@ -0,0 +1,47 @@
+/*
+ * timerfd syscall numbers and definitions
+ */
+
+#ifndef _LINUX_TIMERFD_SYSCALLS_H_
+#define _LINUX_TIMERFD_SYSCALLS_H_
+
+#ifndef __NR_timerfd_create
+# if defined(__x86_64__)
+# define __NR_timerfd_create 283
+# define __NR_timerfd_settime 286
+# define __NR_timerfd_gettime 287
+# elif defined(__i386__)
+# define __NR_timerfd_create 322
+# define __NR_timerfd_settime 325
+# define __NR_timerfd_gettime 326
+# elif defined(__powerpc__)
+# define __NR_timerfd_create 306
+# define __NR_timerfd_settime 311
+# define __NR_timerfd_gettime 312
+# else
+# error Unsupported architecture
+# endif
+#endif
+
+/* Defined in include/linux/timerfd.h */
+#define TFD_TIMER_ABSTIME (1 << 0)
+
+static inline int
+timerfd_create(int clockid, int flags)
+{
+ return syscall(__NR_timerfd_create, clockid, flags);
+}
+
+static inline int
+timerfd_settime(int fd, int flags, const struct itimerspec *new_value, struct itimerspec *curr_value)
+{
+ return syscall(__NR_timerfd_settime, fd, flags, new_value, curr_value);
+}
+
+static inline int
+timerfd_gettime(int fd, struct itimerspec *curr_value)
+{
+ return syscall(__NR_timerfd_gettime, fd, curr_value);
+}
+
+#endif /* _LINUX_TIMERFD_SYSCALLS_H_ */
More information about the Pommed-commits
mailing list