-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathcron_alarm.h
75 lines (65 loc) · 1.92 KB
/
cron_alarm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* .============.
* // M A K E / \
* // C++ DEV / \
* // E A S Y / \/ \
* ++ ----------. \/\ .
* \\ \ \ /\ /
* \\ \ \ /
* \\ \ \ /
* -============'
*
* Copyright (c) 2018 Hevake and contributors, all rights reserved.
*
* This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
* Use of this source code is governed by MIT license that can be found
* in the LICENSE file in the root of the source tree. All contributing
* project authors may be found in the CONTRIBUTORS.md file in the root
* of the source tree.
*/
#ifndef TBOX_ALARM_CRON_ALARM_H
#define TBOX_ALARM_CRON_ALARM_H
#include <string>
#include "alarm.h"
namespace tbox {
namespace alarm {
/*
* @brief The linux cron alarm.
*
* CronAlarm allow the user to make plans by linux cron expression.
* Linux-cron tab expression
* * * * * *
- - - - - -
| | | | | |
| | | | | +----- day of week (0 - 7) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | +---------- month (1 - 12) OR jan,feb,mar,apr ...
| | | +--------------- day of month (1 - 31)
| | +-------------------- hour (0 - 23)
| +------------------------- minute (0 - 59)
+------------------------------ second (0 - 59)
*
* code example:
*
* Loop *loop = Loop::New();
*
* CronAlarm tmr(loop);
* tmr.initialize("18 28 14 * * *"); // every day at 14:28:18
* tmr.setCallback([] { std::cout << "timeout" << std::endl; });
* tmr.enable();
*
* loop->runLoop();
*/
class CronAlarm : public Alarm
{
public:
explicit CronAlarm(event::Loop *wp_loop);
virtual ~CronAlarm();
bool initialize(const std::string &cron_expr_str);
protected:
virtual bool calculateNextLocalTimeSec(uint32_t curr_local_sec, uint32_t &next_local_sec) override;
private:
void *sp_cron_expr_;
};
}
}
#endif //TBOX_ALARM_CRON_ALARM_H