Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

alarm.h

Go to the documentation of this file.
00001 
00002 /*
00003 ** Copyright (C) 2004 Russell Leighton
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __AWALARM__
00021 #define __AWALARM__
00022 
00026 #define AW_DEFAULT_ALARM_CYCLE_TIME ( AW_TIMESTAMP_PER_SEC / 10 )
00027 
00028 
00032 typedef enum {
00033   AW_ALARM_RUN_TYPE,                
00034   AW_ALARM_INTERRUPT_TYPE           
00035 } aw_alarm_type_t;
00036 
00040 typedef enum {
00041   AW_ALARM_OK,                 
00042   AW_ALARM_REMOVE,             
00043   AW_ALARM_NCODES              
00044 } aw_alarm_code_t;
00045 
00046 
00050 typedef enum {
00051   AW_SCHED_NONE,               
00052   AW_SCHED_PULSE,              
00053   AW_SCHED_CALENDAR,           
00054 } aw_alarm_sched_code_t;
00055 
00056 
00060 typedef enum {
00061   AW_SCHED_RUNONCE = 0x1,     
00062 } aw_alarm_sched_flag_t;
00063 
00067 typedef struct {
00068 
00069   /* offset */
00070   aw_timestamp_t
00071    phase;
00072 
00073   /* how often (normal cycle) */
00074   aw_timestamp_t
00075    period;
00076 
00077 } aw_alarm_sched_pulse_t;
00078 
00082 typedef struct {
00083 
00084  /* these are treated as bit vectors */
00085  u_int64_t
00086   min;                /*< minute, bits 0-59 */
00087  u_int32_t
00088   hour,               /*< hour, bits 0-23 */
00089   mday,               /*< day of month, bits 1-31 */
00090   mon,                /*< month, bits 0-11 , 0 is January */
00091   wday;               /*< day of week, 0-6, 0 is Sunday */
00092 
00093 } aw_alarm_sched_cal_t;
00094 
00098 typedef struct {
00099 
00100   aw_alarm_sched_code_t
00101    method_type;
00102 
00103   aw_alarm_sched_flag_t
00104    flags;
00105 
00106   /* how we control cycling... */
00107   union {
00108     
00109     aw_alarm_sched_pulse_t           /* simple cycle */
00110       pulse;
00111 
00112     aw_alarm_sched_cal_t             /* via calendar */
00113       calendar;
00114 
00115   } method;
00116 
00117 
00118   /* this calendar schedule (if enabled, which means .min != 0) 
00119      specifies the times NOT to run...used for things like
00120      maintenance windows, for example: run every 5min
00121      except from midnight to 3am on Sundays */
00122   aw_alarm_sched_cal_t             
00123    notch;
00124 
00125 } aw_alarm_sched_t;
00126 
00127 
00131 typedef struct {
00132 
00133   /* start time of next alarm */
00134   aw_timestamp_t
00135    next_alarm_time;
00136 
00137   /* the run schedule */
00138   aw_alarm_sched_t
00139     sched;
00140 
00141 } aw_alarm_state_t;
00142 
00146 typedef struct {
00147 
00148   aw_event_sig_t
00149    interrupt;                  /* alarm went off */
00150 
00151 } aw_alarm_events_t;
00152 
00153 
00157 typedef struct aw_alarm_s {
00158 
00159   /* run time list */
00160   struct aw_alarm_s
00161    *next,*prev;
00162 
00163   /* what kind */
00164   aw_alarm_type_t
00165    type;
00166 
00167   /* cache allocator used to create this */
00168   aw_cache_allocator_t 
00169    *factory;
00170 
00171   /* holds state related info */
00172   aw_alarm_state_t
00173    state;
00174 
00175   /* events generated */
00176   aw_alarm_events_t
00177    events;
00178 
00179 } aw_alarm_t ;
00180 
00181 
00210 int32_t aw_set_sched_calendar(aw_alarm_sched_cal_t *cal, const byte_t *crontab, FILE *message_stream);
00211 
00212 #endif
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)