| 1 | /* |
| 2 | The software in this package is distributed under the GNU General |
| 3 | Public License version 2 (with a special exception described below). |
| 4 | |
| 5 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 6 | in the file COPYING.GPL. |
| 7 | |
| 8 | As a special exception, if other files instantiate templates or use macros |
| 9 | or inline functions from this file, or you compile this file and link it |
| 10 | with other works to produce a work based on this file, this file |
| 11 | does not by itself cause the resulting work to be covered |
| 12 | by the GNU General Public License. |
| 13 | |
| 14 | However the source code for this file must still be made available |
| 15 | in accordance with section (3) of the GNU General Public License. |
| 16 | |
| 17 | This exception does not invalidate any other reasons why a work based |
| 18 | on this file might be covered by the GNU General Public License. |
| 19 | */ |
| 20 | /** @file |
| 21 | * @brief repeating time-points and intervals |
| 22 | * |
| 23 | * @copyright Copyright © 2009 by Intra2net AG |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #ifndef __CRON_HPP |
| 28 | #define __CRON_HPP |
| 29 | |
| 30 | #include <time.h> |
| 31 | #include <week.hpp> |
| 32 | |
| 33 | namespace I2n { |
| 34 | namespace Time { |
| 35 | |
| 36 | /** |
| 37 | @brief Time points and intervals repeating each week |
| 38 | This class represents recurring time points and intervals |
| 39 | which can be repeated on configurable days of the week. |
| 40 | */ |
| 41 | class WeekCron |
| 42 | { |
| 43 | public: |
| 44 | static const time_t StNimmerleinsDay; |
| 45 | |
| 46 | private: |
| 47 | /// Start point of time in seconds since the start of the day |
| 48 | int Begin; |
| 49 | /// End point of time in seconds since the start of the day. Only used when #Every != -1 |
| 50 | int End; |
| 51 | /// Repeat event every xxx seconds in the half-open interval of #Begin and #End. -1 is disabled |
| 52 | int Every; |
| 53 | /// Stores the active days this WeekCron is valid for |
| 54 | I2n::Time::Week Week; |
| 55 | |
| 56 | time_t get_next_point(const time_t calc_from, const int daysec, const bool todaycheck) const; |
| 57 | time_t get_previousnow_point(const time_t calc_from, const int daysec, const bool todaycheck) const; |
| 58 | void fill_tm_with_wallclock(struct tm *ft, const int daysec) const; |
| 59 | |
| 60 | public: |
| 61 | WeekCron(); |
| 62 | WeekCron(const std::string& daystring, const int begin); |
| 63 | WeekCron(const std::string& daystring, const int begin, const int end, const int every); |
| 64 | WeekCron(const I2n::Time::Week& week, const int begin); |
| 65 | WeekCron(const I2n::Time::Week& week, const int begin, const int end, const int every); |
| 66 | |
| 67 | // accessor functions |
| 68 | I2n::Time::Week get_week(void) const |
| 69 | { return Week; } |
| 70 | void set_week(const I2n::Time::Week& week) |
| 71 | { Week=week; } |
| 72 | int get_begin(void) const |
| 73 | { return Begin; } |
| 74 | void set_begin(const int begin) |
| 75 | { Begin=begin; } |
| 76 | int get_end(void) const |
| 77 | { return End; } |
| 78 | void set_end(const int end) |
| 79 | { End=end; } |
| 80 | int get_every(void) const |
| 81 | { return Every; } |
| 82 | void set_every(const int every) |
| 83 | { Every=every; } |
| 84 | |
| 85 | bool is_sane() const; |
| 86 | |
| 87 | time_t get_next_run(time_t calc_from=0) const; |
| 88 | }; |
| 89 | |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | #endif |