Replace inet_aton() with inet_pton() to parse IPs correctly (#8825)
[libi2ncommon] / src / cron.hpp
... / ...
CommitLineData
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*/
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
33namespace I2n {
34namespace 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*/
41class 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