diff options
Diffstat (limited to 'src/minicron.cpp')
-rw-r--r-- | src/minicron.cpp | 75 |
1 files changed, 64 insertions, 11 deletions
diff --git a/src/minicron.cpp b/src/minicron.cpp index 8aace26..491d143 100644 --- a/src/minicron.cpp +++ b/src/minicron.cpp | |||
@@ -35,6 +35,18 @@ time_t Bu::MiniCron::getNextRun() | |||
35 | return -1; | 35 | return -1; |
36 | } | 36 | } |
37 | 37 | ||
38 | time_t Bu::MiniCron::getNextRun( Bu::MiniCron::JobId jid ) | ||
39 | { | ||
40 | for( JobHeap::iterator i = hJobs.begin(); i; i++ ) | ||
41 | { | ||
42 | if( (*i)->getId() == jid ) | ||
43 | { | ||
44 | return (*i)->getNextRunTime(); | ||
45 | } | ||
46 | } | ||
47 | return -1; | ||
48 | } | ||
49 | |||
38 | void Bu::MiniCron::poll() | 50 | void Bu::MiniCron::poll() |
39 | { | 51 | { |
40 | time_t tNow = time( NULL ); | 52 | time_t tNow = time( NULL ); |
@@ -61,11 +73,11 @@ void Bu::MiniCron::poll() | |||
61 | } | 73 | } |
62 | } | 74 | } |
63 | 75 | ||
64 | Bu::MiniCron::JobId Bu::MiniCron::addJob( Bu::MiniCron::CronSignal sigJob, | 76 | Bu::MiniCron::JobId Bu::MiniCron::addJob( const Bu::FString &sName, |
65 | const Bu::MiniCron::Timer &t ) | 77 | Bu::MiniCron::CronSignal sigJob, const Bu::MiniCron::Timer &t ) |
66 | { | 78 | { |
67 | JobId jid = jidNext++; | 79 | JobId jid = jidNext++; |
68 | Job *pJob = new Job( jid ); | 80 | Job *pJob = new Job( sName, jid ); |
69 | pJob->sigJob = sigJob; | 81 | pJob->sigJob = sigJob; |
70 | pJob->pTimer = t.clone(); | 82 | pJob->pTimer = t.clone(); |
71 | pJob->tNextRun = pJob->pTimer->nextTime(); | 83 | pJob->tNextRun = pJob->pTimer->nextTime(); |
@@ -74,11 +86,11 @@ Bu::MiniCron::JobId Bu::MiniCron::addJob( Bu::MiniCron::CronSignal sigJob, | |||
74 | return jid; | 86 | return jid; |
75 | } | 87 | } |
76 | 88 | ||
77 | Bu::MiniCron::JobId Bu::MiniCron::addJobOnce( Bu::MiniCron::CronSignal sigJob, | 89 | Bu::MiniCron::JobId Bu::MiniCron::addJobOnce( const Bu::FString &sName, |
78 | const Bu::MiniCron::Timer &t ) | 90 | Bu::MiniCron::CronSignal sigJob, const Bu::MiniCron::Timer &t ) |
79 | { | 91 | { |
80 | JobId jid = jidNext++; | 92 | JobId jid = jidNext++; |
81 | Job *pJob = new Job( jid, false ); | 93 | Job *pJob = new Job( sName, jid, false ); |
82 | pJob->sigJob = sigJob; | 94 | pJob->sigJob = sigJob; |
83 | pJob->pTimer = t.clone(); | 95 | pJob->pTimer = t.clone(); |
84 | pJob->tNextRun = pJob->pTimer->nextTime(); | 96 | pJob->tNextRun = pJob->pTimer->nextTime(); |
@@ -107,7 +119,21 @@ void Bu::MiniCron::removeJob( JobId jid ) | |||
107 | } | 119 | } |
108 | } | 120 | } |
109 | 121 | ||
110 | Bu::MiniCron::Job::Job( JobId jid, bool bRepeat ) : | 122 | Bu::MiniCron::JobInfoList Bu::MiniCron::getJobInfo() |
123 | { | ||
124 | JobInfoList lRet; | ||
125 | for( JobHeap::iterator i = hJobs.begin(); i; i++ ) | ||
126 | { | ||
127 | lRet.append( | ||
128 | JobInfo( (*i)->getName(), (*i)->getId(), (*i)->getNextRun() ) | ||
129 | ); | ||
130 | } | ||
131 | lRet.sort(); | ||
132 | return lRet; | ||
133 | } | ||
134 | |||
135 | Bu::MiniCron::Job::Job( const Bu::FString &sName, JobId jid, bool bRepeat ) : | ||
136 | sName( sName ), | ||
111 | pTimer( NULL ), | 137 | pTimer( NULL ), |
112 | bContinue( bRepeat ), | 138 | bContinue( bRepeat ), |
113 | jid( jid ), | 139 | jid( jid ), |
@@ -129,7 +155,7 @@ void Bu::MiniCron::Job::run() | |||
129 | sigJob( *this ); | 155 | sigJob( *this ); |
130 | } | 156 | } |
131 | 157 | ||
132 | time_t Bu::MiniCron::Job::getNextRun() | 158 | time_t Bu::MiniCron::Job::getNextRun() const |
133 | { | 159 | { |
134 | return tNextRun; | 160 | return tNextRun; |
135 | } | 161 | } |
@@ -156,21 +182,48 @@ void Bu::MiniCron::Job::resume() | |||
156 | bContinue = true; | 182 | bContinue = true; |
157 | } | 183 | } |
158 | 184 | ||
159 | Bu::MiniCron::JobId Bu::MiniCron::Job::getId() | 185 | Bu::MiniCron::JobId Bu::MiniCron::Job::getId() const |
160 | { | 186 | { |
161 | return jid; | 187 | return jid; |
162 | } | 188 | } |
163 | 189 | ||
164 | time_t Bu::MiniCron::Job::getTimeCreated() | 190 | time_t Bu::MiniCron::Job::getTimeCreated() const |
165 | { | 191 | { |
166 | return tAdded; | 192 | return tAdded; |
167 | } | 193 | } |
168 | 194 | ||
169 | int Bu::MiniCron::Job::getRunCount() | 195 | int Bu::MiniCron::Job::getRunCount() const |
170 | { | 196 | { |
171 | return iRunCount; | 197 | return iRunCount; |
172 | } | 198 | } |
173 | 199 | ||
200 | time_t Bu::MiniCron::Job::getNextRunTime() const | ||
201 | { | ||
202 | return tNextRun; | ||
203 | } | ||
204 | |||
205 | Bu::FString Bu::MiniCron::Job::getName() const | ||
206 | { | ||
207 | return sName; | ||
208 | } | ||
209 | |||
210 | Bu::MiniCron::JobInfo::JobInfo( const Bu::FString &sName, JobId jid, | ||
211 | time_t tNext ) : | ||
212 | sName( sName ), | ||
213 | jid( jid ), | ||
214 | tNext( tNext ) | ||
215 | { | ||
216 | } | ||
217 | |||
218 | Bu::MiniCron::JobInfo::~JobInfo() | ||
219 | { | ||
220 | } | ||
221 | |||
222 | bool Bu::MiniCron::JobInfo::operator<( const JobInfo &rhs ) const | ||
223 | { | ||
224 | return jid < rhs.jid; | ||
225 | } | ||
226 | |||
174 | Bu::MiniCron::Timer::Timer() | 227 | Bu::MiniCron::Timer::Timer() |
175 | { | 228 | { |
176 | } | 229 | } |