From ec1c85f00828ab6ac8d6789350b95a16cdee003f Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 27 Sep 1999 20:57:07 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'GNOME_LIBS_1_0_50'. svn path=/tags/GNOME_LIBS_1_0_50/; revision=1287 --- calendar/gui/alarm-notify/alarm.c | 181 -------------------------------------- calendar/gui/alarm-notify/alarm.h | 12 --- 2 files changed, 193 deletions(-) delete mode 100644 calendar/gui/alarm-notify/alarm.c delete mode 100644 calendar/gui/alarm-notify/alarm.h (limited to 'calendar/gui/alarm-notify') diff --git a/calendar/gui/alarm-notify/alarm.c b/calendar/gui/alarm-notify/alarm.c deleted file mode 100644 index 7e56ce790a..0000000000 --- a/calendar/gui/alarm-notify/alarm.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 "calobj.h" -#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; - CalendarAlarm *alarm; -} 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; - time_t now = time (NULL); - char c; - - if (read (alarm_pipes [0], &c, 1) != 1) - return; - - if (ar == NULL){ - g_warning ("Empty events. This should not happen\n"); - return; - } - - while (head_alarm){ - (*ar->fn)(ar->activation_time, ar->alarm, ar->closure); - alarms = g_list_remove (alarms, head_alarm); - - /* Schedule next alarm */ - if (alarms){ - AlarmRecord *next; - - head_alarm = alarms->data; - next = head_alarm; - - if (next->activation_time > now){ - struct itimerval itimer; - - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = next->activation_time - now; - itimer.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &itimer, NULL); - break; - } else { - g_free (ar); - ar = next; - } - } else - head_alarm = NULL; - } - g_free (ar); -} - -static int -alarm_compare_by_time (gconstpointer a, gconstpointer b) -{ - const AlarmRecord *ara = a; - const AlarmRecord *arb = b; - time_t diff; - - diff = ara->activation_time - arb->activation_time; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -/** - * alarm_add: - * - * Tries to schedule @alarm. - * - * Returns TRUE if the alarm was scheduled. - */ -gboolean -alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure) -{ - time_t now = time (NULL); - AlarmRecord *ar; - time_t alarm_time = alarm->trigger; - - /* If it already expired, do not add it */ - if (alarm_time < now) - return FALSE; - - ar = g_new0 (AlarmRecord, 1); - ar->activation_time = alarm_time; - ar->fn = fn; - ar->closure = closure; - ar->alarm = alarm; - - 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; - } - - return TRUE; -} - -int -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 1; - } - } - return 0; -} - -void -alarm_init (void) -{ - struct sigaction sa; - int flags = 0; - - 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); -} - diff --git a/calendar/gui/alarm-notify/alarm.h b/calendar/gui/alarm-notify/alarm.h deleted file mode 100644 index 81710bda5e..0000000000 --- a/calendar/gui/alarm-notify/alarm.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef ALARM_H -#define ALARM_H - -#include - -typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse); - -void alarm_init (void); -gboolean alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure); -int alarm_kill (void *closure); - -#endif -- cgit v1.2.3