-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterval.h
115 lines (94 loc) · 2.61 KB
/
Interval.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once
#include"BaseLib/CommonDefines.h"
#include"BaseLib/Duration.h"
#include"BaseLib/Export.h"
namespace BaseLib { namespace Policy {
enum class DLL_STATE IntervalKind
{
FromStart,
FromStop
};
/**
* @brief The Interval class
*
* TODO: Rename to TimeInterval
* TODO: Interval should include (Interval::FromEndOfTask, Interval::FromBeginningOfTask),
*/
class DLL_STATE Interval
{
public:
Interval(Duration initialDelay, Duration period, IntervalKind kind = IntervalKind::FromStop)
: initial_(initialDelay)
, period_(period)
, kind_(kind)
{ }
~Interval()
{ }
const Duration& Initial() const
{
return initial_;
}
const Duration& Period() const
{
return period_;
}
IntervalKind Kind() const
{
return kind_;
}
/**
* Default is start immediately and run every 1000 milliseconds
*/
static Interval Default()
{
return Interval(Duration::Zero(), Duration::FromMilliseconds(1000));
}
static Interval RunImmediatelyAndThenEvery(int periodMs)
{
return Interval(Duration::Zero(), Duration::FromMilliseconds(periodMs));
}
static Interval RunImmediately()
{
return Interval(Duration::Zero(), Duration::Zero());
}
static Interval DelayedRunAndThenEvery(int initialMs, int periodMs)
{
return Interval(Duration::FromMilliseconds(initialMs), Duration::FromMilliseconds(periodMs));
}
static Interval DelayedRunAndThenEvery(Duration initial, Duration period)
{
return Interval(initial, period);
}
static Interval RunEveryMs(int periodMs)
{
return Interval(Duration::FromMilliseconds(periodMs), Duration::FromMilliseconds(periodMs));
}
static Interval RunEveryMinute(int minutes)
{
return Interval(Duration::FromMinutes(minutes), Duration::FromMinutes(minutes));
}
static Interval FromMinutes(int minutes)
{
return RunEveryMinute(minutes);
}
static Interval Infinite()
{
return Interval(Duration::Zero(), Duration::Infinite(), IntervalKind::FromStart);
}
friend std::ostream& operator<<(std::ostream& ostr, const Interval& qos)
{
ostr << "Interval(" << qos.initial_ << "," << qos.period_ << ")";
return ostr;
}
//void generateSleepTime(Packet *pPckt)
//{
// double temp = (SERVICE_RATE/((double)(pPckt->packetSize)));
// wait_time = (1/temp) * 1000;
// wakeup_time = wait_time + get_current_time();
//}
private:
Duration initial_;
Duration period_;
IntervalKind kind_;
};
}}