1 /* 2 * Tvheadend - cron routines 3 * 4 * Copyright (C) 2014 Adam Sutton 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __TVH_CRON_H__ 21 #define __TVH_CRON_H__ 22 23 #include <stdint.h> 24 #include <sys/types.h> 25 26 #define CRON_MIN_MASK (0x0FFFFFFFFFFFFFFFLL) // 60 bits 27 #define CRON_HOUR_MASK (0x00FFFFFF) // 24 bits 28 #define CRON_MDAY_MASK (0x7FFFFFFF) // 31 bits 29 #define CRON_MON_MASK (0x0FFF) // 12 bits 30 #define CRON_WDAY_MASK (0x7F) // 7 bits 31 32 typedef struct cron 33 { 34 uint64_t c_min; ///< Minute mask 35 uint32_t c_hour; ///< Hour mask 36 uint32_t c_mday; ///< Day of the Month mask 37 uint16_t c_mon; ///< Month mask 38 uint8_t c_wday; ///< Day of the Week mask 39 } cron_t; 40 41 typedef struct cron_multi 42 { 43 uint32_t cm_count; ///< Count of multiple crons 44 cron_t cm_crons[0]; ///< Allocated cron structures 45 } cron_multi_t; 46 47 /** 48 * Initialise from a string 49 * 50 * @param c The cron instance to update 51 * @param str String representation of the cron 52 * 53 * @return 0 if OK, 1 if failed to parse 54 */ 55 int cron_set ( cron_t *c, const char *str ); 56 57 /** 58 * Determine the next time a cron will run (from cur) 59 * 60 * @param c The cron to check 61 * @param now The current time 62 * @param nxt The next time to execute 63 * 64 * @return 0 if next time was found 65 */ 66 int cron_next ( cron_t *c, const time_t cur, time_t *nxt ); 67 68 /** 69 * Initialise from a string 70 * 71 * @param str String representation of the mutiple cron entries ('\n' delimiter) 72 * 73 * @return cron_multi_t pointer if OK, NULL if failed to parse 74 */ 75 cron_multi_t *cron_multi_set ( const char *str ); 76 77 /** 78 * Determine the next time a cron will run (from cur) 79 * 80 * @param c The cron to check 81 * @param now The current time 82 * @param nxt The next time to execute 83 * 84 * @return 0 if next time was found 85 */ 86 int cron_multi_next ( cron_multi_t *cm, const time_t cur, time_t *nxt ); 87 88 #endif /* __TVH_CRON_H__ */ 89 90 /****************************************************************************** 91 * Editor Configuration 92 * 93 * vim:sts=2:ts=2:sw=2:et 94 *****************************************************************************/ 95