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