From 5471d34089277ad5c622fd9c392b9270229d9e3d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 14 Jan 2010 00:28:08 +0000 Subject: Created the minicron system. This is a cute little cron like implementation that allows a program to signal slots on a schedule, possibly a dynamic schedule. --- src/tests/minicron.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/tests/minicron.cpp (limited to 'src/tests') diff --git a/src/tests/minicron.cpp b/src/tests/minicron.cpp new file mode 100644 index 0000000..715a74d --- /dev/null +++ b/src/tests/minicron.cpp @@ -0,0 +1,53 @@ +#include "bu/minicron.h" +#include "bu/sio.h" + +#include + +using namespace Bu; + +Bu::MiniCron mCron; + +void job0( Bu::MiniCron::Job &job ) +{ + sio << time( NULL ) << ": job0( id = " << job.getId() << ", count = " + << job.getRunCount() << ")" << sio.nl; +} + +void job1( Bu::MiniCron::Job &job ) +{ + sio << time( NULL ) << ": job1( id = " << job.getId() << ", count = " + << job.getRunCount() << ")" << sio.nl; + mCron.removeJob( 4 ); +} + +void job2( Bu::MiniCron::Job &job ) +{ + sio << time( NULL ) << ": job2( id = " << job.getId() << ", count = " + << job.getRunCount() << ")" << sio.nl; +} + +void job3( Bu::MiniCron::Job &job ) +{ + sio << time( NULL ) << ": job3( id = " << job.getId() << ", count = " + << job.getRunCount() << ")" << sio.nl; +} + +int main() +{ + + mCron.addJob( slot( &job0 ), MiniCron::TimerInterval( time(NULL)+3, 5 ) ); + mCron.addJob( slot( &job1 ), MiniCron::TimerInterval( time(NULL)+10, 8 ) ); + mCron.addJob( slot( &job2 ), MiniCron::TimerBasic("weekly wed 17") ); + mCron.addJob( slot( &job3 ), MiniCron::TimerInterval( time(NULL)+1, 2 ) ); + + sio << time( NULL ) << ": Program started." << sio.nl; + + for(;;) + { + usleep( 50000 ); + mCron.poll(); + } + + return 0; +} + -- cgit v1.2.3