/* * Alarm handling for the GNOME Calendar. * * (C) 1998 the Free Software Foundation * * Author: Miguel de Icaza (miguel@kernel.org) */ #include #include #include #include #include #include #include "alarm.h" /* The pipes used to notify about an alarm */ int alarm_pipes [2]; /* The list of pending alarms */ static GList *alarms; static void *head_alarm; typedef struct { time_t activation_time; AlarmFunction fn; void *closure; } AlarmRecord; /* * SIGALRM handler. Notifies the callback about the alarm */ static void alarm_activate () { char c = 0; write (alarm_pipes [1], &c, 1); } static void alarm_ready (void *closure, int fd, GdkInputCondition cond) { AlarmRecord *ar = head_alarm; char c; if (read (alarm_pipes [0], &c, 1) != 1) return; if (ar == NULL){ g_warning ("Empty events. This should not happen\n"); return; } (*ar->fn)(ar->activation_time, ar->closure); alarms = g_list_remove (alarms, head_alarm); if (alarms) head_alarm = alarms->data; else head_alarm = NULL; g_free (ar); } static int alarm_compare_by_time (gpointer a, gpointer b) { AlarmRecord *ara = a; AlarmRecord *arb = b; time_t diff; diff = ara->activation_time - arb->activation_time; return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; } void alarm_add (time_t alarm_time, AlarmFunction fn, void *closure) { time_t now = time (NULL); AlarmRecord *ar; /* If it already expired, do not add it */ if (alarm_time < now) return; ar = g_new0 (AlarmRecord, 1); ar->activation_time = alarm_time; ar->fn = fn; ar->closure = closure; alarms = g_list_insert_sorted (alarms, ar, alarm_compare_by_time); /* If first alarm is not the previous first alarm, reschedule SIGALRM */ if (head_alarm != alarms->data){ struct itimerval itimer; int v; /* Set the timer to disable upon activation */ itimer.it_interval.tv_sec = 0; itimer.it_interval.tv_usec = 0; itimer.it_value.tv_sec = alarm_time - now; itimer.it_value.tv_usec = 0; v = setitimer (ITIMER_REAL, &itimer, NULL); head_alarm = alarms->data; } } void alarm_kill (void *closure_key) { GList *p; for (p = alarms; p; p = p->next){ AlarmRecord *ar = p->data; if (ar->closure == closure_key){ alarms = g_list_remove (alarms, p->data); if (alarms) head_alarm = alarms->data; else head_alarm = NULL; return; } } } void alarm_init (void) { struct sigaction sa; int flags; pipe (alarm_pipes); /* set non blocking mode */ fcntl (alarm_pipes [0], F_GETFL, &flags); fcntl (alarm_pipes [0], F_SETFL, flags | O_NONBLOCK); gdk_input_add (alarm_pipes [0], GDK_INPUT_READ, alarm_ready, 0); /* Setup the signal handler */ sa.sa_handler = alarm_activate; sigemptyset (&sa.sa_mask); sa.sa_flags = SA_RESTART; sigaction (SIGALRM, &sa, NULL); } n> FreeBSD GNOME current development ports (https://github.com/freebsd/freebsd-ports-gnome)
aboutsummaryrefslogtreecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
* Fix script "use.perl": correctly check variables 'need_*'.skv2009-11-061-7/+7
* - Fix behaviour of USE_PERL option when it is "off"skv2009-11-032-5/+12
* Update to 5.10.1skv2009-09-1122-584/+319
* - Add option MULTIPLICITYskv2009-07-062-1/+101
* - Add more essential bugfixesskv2009-06-084-2/+65
* Add bugfiux for "Attributes + Unkown Error".skv2009-04-112-1/+49
* Fix packaging with enabled GDBM option.skv2009-04-051-1/+0
* Add several bugfixes, imported from maint-5.10skv2009-04-0412-0/+291
* Fix CONFLICTS.skv2009-03-291-1/+1
* Introduce Perl 5.10.0skv2009-03-298-367/+623
* Add MAKE_JOBS_SAFE variable.skv2009-03-231-0/+1
* Update "perl-after-upgrade": set correct perl package name in @pkgdep.skv2009-03-132-46/+5
* Fix PORTVERSION.skv2009-03-061-1/+1
* Remove variable PERL_VER from the ports tree at all - becauseskv2009-03-062-117/+19
* Update BSDPAN:skv2009-03-042-5/+7
* Fix install of BSDPAN (BSDPAN_WRKSRC) and unbreak.itetcu2009-02-161-1/+1
* * Fix suidperl functionality. [1]skv2009-02-163-4/+15
* Add "regression-test" make target.skv2009-01-271-3/+5
* Unbreak build of threaded perl.skv2009-01-141-1/+1
* Update to 5.8.9skv2009-01-149-308/+280
* - Remove conditional checks for FreeBSD 5.x and olderpav2009-01-062-35/+0
* - Take maintainership [1]skv2008-11-212-25/+20
* - Take advantage of CPAN macro from bsd.sites.mk, change ${MASTER_SITE_PERL_C...araujo2008-04-171-1/+1
* Fix a possible buffer overflow with ASCII regexes that really aretobez2007-11-072-0/+96