/*- * Copyright (c) 2003 Andrey Simonenko * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)$Id: ipa_time.h,v 1.2.2.2 2006/03/23 00:56:11 simon Exp $ */ #ifndef IPA_TIME_H #define IPA_TIME_H #define UPDATE_TIME_DEF (1 * SECONDS_IN_MINUTE) /* update_time default value. */ #define WAKEUP_TIME_DEF (10 * SECONDS_IN_MINUTE)/* wakeup_time default value. */ #define SENSITIVE_TIME_DEF (SECONDS_IN_MINUTE / 2) /* sensitive_time default value. */ #define ACTIVE_FLAG 1 /* Something is active. */ #define INACTIVE_FLAG 0 /* Something is inactive. */ #define UNKNOWN_ACTIVE_FLAG -1 /* Unknown state. */ #define IS_ACTIVE(x) ((x)->is_active == ACTIVE_FLAG) #define IS_INACTIVE(x) ((x)->is_active == INACTIVE_FLAG) #define TIME_TO_SEC(tm) ((tm)->tm_hour * SECONDS_IN_HOUR + (tm)->tm_min * SECONDS_IN_MINUTE + (tm)->tm_sec) /* * If time of scheduled event is less than current time * no more than FAKE_TIME_DELTA, then fake current time. * To disable this feature, set this macro to zero. */ #ifndef FAKE_TIME_DELTA # define FAKE_TIME_DELTA 5 #endif /* * One time event. */ struct tevent { SLIST_ENTRY(tevent) link; u_int event_sec; /* Next event time. */ u_int event_step; /* Interval between events. */ }; #define TEVENT_NSIZE 10 #define TEVENT_NALLOC 10 /* * List of all time events. */ SLIST_HEAD(tevents_list, tevent); /* * One time interval in "worktime" parameter in seconds * starting from midnight. */ struct tint { STAILQ_ENTRY(tint) link; u_int sec1; /* From sec1. */ u_int sec2; /* Till sec2. */ }; #define TINT_NSIZE 20 #define TINT_NALLOC 20 /* * List of all time intervals for one day. */ STAILQ_HEAD(tint_list, tint); /* * List of all tint_lists. */ struct tint_set { STAILQ_ENTRY(tint_set) link; /* For list building of all tint_lists. */ struct tint_list list; /* One tint_list. */ }; STAILQ_HEAD(tint_sets, tint_set); /* * One worktime. */ struct worktime { SLIST_ENTRY(worktime) link; /* For list of all worktimes. */ const struct tint_list *tint_list[DAYS_IN_WEEK]; const struct tint *curtint; /* Current time interval. */ u_int active_sec; /* Time when to make worktime active. */ u_int inactive_sec; /* Time when to make worktime inactive. */ int is_active; /* 1, if worktime is active. */ }; #define WORKTIME_NSIZE 5 #define WORKTIME_NALLOC 5 /* * List of all worktimes. */ SLIST_HEAD(worktimes_list, worktime); #ifdef WITH_LIMITS /* * [+]