-
Notifications
You must be signed in to change notification settings - Fork 1
/
ELScheduler.h
193 lines (152 loc) · 4.68 KB
/
ELScheduler.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#ifndef _ELSCHEDULER_H_
#define _ELSCHEDULER_H_
/*
Author: Brent Pease (embeddedlibraryfeedback@gmail.com)
The MIT License (MIT)
Copyright (c) 2015-FOREVER Brent Pease
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
ABOUT
*/
#include "EL.h"
#include "ELModule.h"
#include "ELRealTime.h"
#include "ELString.h"
#include "ELCalendarEvent.h"
enum EScheduler_TimeType
{
eTimeType_Sunrise,
eTimeType_Sunset,
eTimeType_Time,
};
enum EScheduler_DateType
{
eDateType_Holiday,
eDateType_Date
};
enum EEventType
{
eEventType_Start,
eEventType_End
};
enum EDayOfWeek
{
eDay_Sunday,
eDay_Monday,
eDay_Tuesday,
eDay_Wednesday,
eDay_Thursday,
eDay_Friday,
eDay_Saturday,
eDay_Count,
};
enum EScheduler
{
eScheduler_Any = -1, // Any year, month, or day of the event
eScheduler_Entire = 0, // The specific month or day of the event
};
typedef void* TSchedulerPeriodRef;
struct CSchedulerThreshold
{
int8_t dateType; // Is the date a Holiday (whose exact date can vary year to year) or a specific date
int8_t holiday; // EHoliday
int8_t year; // For eDateType_Date this can be -1 for any year or it's the exact year. This is ignored for eDate_Holiday
int8_t month; // For eDateType_Date this can be -1 for any month or it's the exact month. For eDate_Holiday -1 means entire month of the holiday
int8_t dayOfMonth; // For eDateType_Date this can be -1 for any day or it's the exact day. For eDate_Holiday this is ignored
int8_t weekOfMonth; // For eDateType_Date this can be -1 for any week of the month or the given week, 0 is first partial week, 1 is first whole week. For eDate_Holiday -1 means the entire week of the holiday
int8_t daysOfWeek; // For eDateType_Date this is a bitmap of the days of the week. For eDate_Holiday this is ignored
int8_t timeType;
int8_t hour; // For eTimeOfDay_Sunrise and eTimeOfDay_Sunset these are relative to either sunrise or sunset for the date specified above
int8_t minute;
int8_t second;
bool
operator ==(
TEpochTime inRHS);
bool
operator >(
TEpochTime inRHS);
bool
operator >=(
TEpochTime inRHS);
bool
operator <(
TEpochTime inRHS);
bool
operator <=(
TEpochTime inRHS);
TEpochTime
GetEpochTime(
TEpochTime inReferenceTime,
bool inStarting); // True of this threshold is starting a period, false if ending
};
struct CSchedulerPeriod
{
CSchedulerThreshold start;
CSchedulerThreshold end;
bool
operator <(
TEpochTime inRHS);
bool
operator >(
TEpochTime inRHS);
bool
operator ==(
TEpochTime inRHS);
};
// This is a dummy class for defining a alarm or event handler object
class ISchedulerHandler
{
public:
};
// A typedef for a event handler method, event methods should return true if it wants to be rescheduled
typedef bool
(ISchedulerHandler::*TSchedulerMethod)(
TSchedulerPeriodRef inPeriodRef,
EEventType inType,
void* inRefCon);
class CModule_Scheduler : public CModule
{
public:
MModule_Declaration(CModule_Scheduler)
TSchedulerPeriodRef*
CreatePeriod(
char const* inPeriodName,
ISchedulerHandler* inObject, // The object on which the method below lives
TSchedulerMethod inMethod, // The method on the above object
void* inReference); // The reference value passed into the above method
void
DestroyPeriod(
TSchedulerPeriodRef* inPeriodRef);
bool
SchedulePeriod(
TSchedulerPeriodRef* inPeriodRef,
CSchedulerPeriod const& inEventData);
/*
Format: [date|holiday]:year/month/[day|week|dayofweek] [sunrise|sunset|time]:hour:minute:second
*/
bool
ParseStringToThreshold(
CSchedulerThreshold& outThreshold,
char const* inString);
void
ThresholdToString(
TString<128>& outString,
CSchedulerThreshold const& inThreshold);
};
extern CModule_Scheduler* gSchedulerModule;
#endif /* _ELSCHEDULER_H_ */