aboutsummaryrefslogtreecommitdiff
path: root/src/minicron.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-10-06 07:01:28 +0000
committerMike Buland <eichlan@xagasoft.com>2010-10-06 07:01:28 +0000
commit313e28df2a8776c82f5493aef6fe44ad40f1935a (patch)
tree219d5ff889b85773a6670fdff28c2043b14a1f09 /src/minicron.cpp
parent0bb8c5962e93fae4a2542d57efe8e87d30d8f0fb (diff)
downloadlibbu++-313e28df2a8776c82f5493aef6fe44ad40f1935a.tar.gz
libbu++-313e28df2a8776c82f5493aef6fe44ad40f1935a.tar.bz2
libbu++-313e28df2a8776c82f5493aef6fe44ad40f1935a.tar.xz
libbu++-313e28df2a8776c82f5493aef6fe44ad40f1935a.zip
Changed the Bu::Heap to allow iteration, and added lots of cool features to
Bu::MiniCron.
Diffstat (limited to 'src/minicron.cpp')
-rw-r--r--src/minicron.cpp75
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
38time_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
38void Bu::MiniCron::poll() 50void 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
64Bu::MiniCron::JobId Bu::MiniCron::addJob( Bu::MiniCron::CronSignal sigJob, 76Bu::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
77Bu::MiniCron::JobId Bu::MiniCron::addJobOnce( Bu::MiniCron::CronSignal sigJob, 89Bu::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
110Bu::MiniCron::Job::Job( JobId jid, bool bRepeat ) : 122Bu::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
135Bu::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
132time_t Bu::MiniCron::Job::getNextRun() 158time_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
159Bu::MiniCron::JobId Bu::MiniCron::Job::getId() 185Bu::MiniCron::JobId Bu::MiniCron::Job::getId() const
160{ 186{
161 return jid; 187 return jid;
162} 188}
163 189
164time_t Bu::MiniCron::Job::getTimeCreated() 190time_t Bu::MiniCron::Job::getTimeCreated() const
165{ 191{
166 return tAdded; 192 return tAdded;
167} 193}
168 194
169int Bu::MiniCron::Job::getRunCount() 195int Bu::MiniCron::Job::getRunCount() const
170{ 196{
171 return iRunCount; 197 return iRunCount;
172} 198}
173 199
200time_t Bu::MiniCron::Job::getNextRunTime() const
201{
202 return tNextRun;
203}
204
205Bu::FString Bu::MiniCron::Job::getName() const
206{
207 return sName;
208}
209
210Bu::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
218Bu::MiniCron::JobInfo::~JobInfo()
219{
220}
221
222bool Bu::MiniCron::JobInfo::operator<( const JobInfo &rhs ) const
223{
224 return jid < rhs.jid;
225}
226
174Bu::MiniCron::Timer::Timer() 227Bu::MiniCron::Timer::Timer()
175{ 228{
176} 229}