diff options
author | Russell Steinthal <steintr@src.gnome.org> | 1999-12-03 02:47:31 +0800 |
---|---|---|
committer | Russell Steinthal <steintr@src.gnome.org> | 1999-12-03 02:47:31 +0800 |
commit | 6dde8f43e3aba4c65528aae227a6033edf4e0071 (patch) | |
tree | d3c9feb9721f8aa593a76fc018458c444903af6d /calendar/alarm.c | |
parent | 5dc6462368b2c6a0f5b2c6905068b9a3c25006e0 (diff) | |
download | gsoc2013-evolution-6dde8f43e3aba4c65528aae227a6033edf4e0071.tar gsoc2013-evolution-6dde8f43e3aba4c65528aae227a6033edf4e0071.tar.gz gsoc2013-evolution-6dde8f43e3aba4c65528aae227a6033edf4e0071.tar.bz2 gsoc2013-evolution-6dde8f43e3aba4c65528aae227a6033edf4e0071.tar.lz gsoc2013-evolution-6dde8f43e3aba4c65528aae227a6033edf4e0071.tar.xz gsoc2013-evolution-6dde8f43e3aba4c65528aae227a6033edf4e0071.tar.zst gsoc2013-evolution-6dde8f43e3aba4c65528aae227a6033edf4e0071.zip |
Debugging enhancements: report alarms not added (because they have already
passed), allow toggling of debugging output using SIGUSR1
svn path=/trunk/; revision=1453
Diffstat (limited to 'calendar/alarm.c')
-rw-r--r-- | calendar/alarm.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/calendar/alarm.c b/calendar/alarm.c index 04e7c02e49..cf1cd8fb60 100644 --- a/calendar/alarm.c +++ b/calendar/alarm.c @@ -29,7 +29,13 @@ typedef struct { CalendarAlarm *alarm; } AlarmRecord; -void debug_alarm (AlarmRecord* ar, int add); +enum DebugAction { + ALARM_ACTIVATED, + ALARM_ADDED, + ALARM_NOT_ADDED +}; + +void debug_alarm (AlarmRecord* ar, enum DebugAction action); void calendar_notify (time_t time, CalendarAlarm *which, void *data); extern int debug_alarms; @@ -44,6 +50,15 @@ alarm_activate () write (alarm_pipes [1], &c, 1); } +/* + * SIGUSR1 handler. Toggles debugging output + */ +static void +toggle_debugging () +{ + debug_alarms = !debug_alarms; +} + static void alarm_ready (void *closure, int fd, GdkInputCondition cond) { @@ -61,7 +76,7 @@ alarm_ready (void *closure, int fd, GdkInputCondition cond) while (head_alarm){ if (debug_alarms) - debug_alarm (ar, 0); + debug_alarm (ar, ALARM_ACTIVATED); (*ar->fn)(ar->activation_time, ar->alarm, ar->closure); alarms = g_list_remove (alarms, head_alarm); @@ -116,16 +131,19 @@ alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure) 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; + /* If it already expired, do not add it */ + if (alarm_time < now) { + if (debug_alarms) + debug_alarm (ar, ALARM_NOT_ADDED); + return FALSE; + } + alarms = g_list_insert_sorted (alarms, ar, alarm_compare_by_time); /* If first alarm is not the previous first alarm, reschedule SIGALRM */ @@ -142,7 +160,7 @@ alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure) head_alarm = alarms->data; } if (debug_alarms) - debug_alarm (ar, 1); + debug_alarm (ar, ALARM_ADDED); return TRUE; } @@ -170,6 +188,7 @@ void alarm_init (void) { struct sigaction sa; + struct sigaction debug_sa; int flags = 0; pipe (alarm_pipes); @@ -184,18 +203,31 @@ alarm_init (void) sigemptyset (&sa.sa_mask); sa.sa_flags = SA_RESTART; sigaction (SIGALRM, &sa, NULL); + + /* Setup a signal handler to toggle debugging */ + debug_sa.sa_handler = toggle_debugging; + sigemptyset (&debug_sa.sa_mask); + debug_sa.sa_flags = SA_RESTART; + sigaction (SIGUSR1, &debug_sa, NULL); } void -debug_alarm (AlarmRecord* ar, int add) +debug_alarm (AlarmRecord* ar, enum DebugAction action) { time_t now = time (NULL); iCalObject *ico = ar->closure; printf ("%s", ctime(&now)); - if (add) + switch (action) { + case ALARM_ADDED: printf ("Added alarm for %s", ctime(&ar->activation_time)); - else + break; + case ALARM_NOT_ADDED: + printf ("Alarm not added for %s", ctime(&ar->activation_time)); + break; + case ALARM_ACTIVATED: printf ("Activated alarm\n"); + break; + } if (ar->fn!=&calendar_notify) return; printf ("--- Summary: %s\n", ico->summary); |