summaryrefslogtreecommitdiff
path: root/src/tests/minicron.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-01-14 00:28:08 +0000
committerMike Buland <eichlan@xagasoft.com>2010-01-14 00:28:08 +0000
commit5471d34089277ad5c622fd9c392b9270229d9e3d (patch)
tree29bb6b159679ef3a9746fdc61c1ac4e7cea6fe5c /src/tests/minicron.cpp
parentb07c2de16ae8dfa2c0fc4a594deddacc46386216 (diff)
downloadlibbu++-5471d34089277ad5c622fd9c392b9270229d9e3d.tar.gz
libbu++-5471d34089277ad5c622fd9c392b9270229d9e3d.tar.bz2
libbu++-5471d34089277ad5c622fd9c392b9270229d9e3d.tar.xz
libbu++-5471d34089277ad5c622fd9c392b9270229d9e3d.zip
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.
Diffstat (limited to 'src/tests/minicron.cpp')
-rw-r--r--src/tests/minicron.cpp53
1 files changed, 53 insertions, 0 deletions
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 @@
1#include "bu/minicron.h"
2#include "bu/sio.h"
3
4#include <unistd.h>
5
6using namespace Bu;
7
8Bu::MiniCron mCron;
9
10void job0( Bu::MiniCron::Job &job )
11{
12 sio << time( NULL ) << ": job0( id = " << job.getId() << ", count = "
13 << job.getRunCount() << ")" << sio.nl;
14}
15
16void job1( Bu::MiniCron::Job &job )
17{
18 sio << time( NULL ) << ": job1( id = " << job.getId() << ", count = "
19 << job.getRunCount() << ")" << sio.nl;
20 mCron.removeJob( 4 );
21}
22
23void job2( Bu::MiniCron::Job &job )
24{
25 sio << time( NULL ) << ": job2( id = " << job.getId() << ", count = "
26 << job.getRunCount() << ")" << sio.nl;
27}
28
29void job3( Bu::MiniCron::Job &job )
30{
31 sio << time( NULL ) << ": job3( id = " << job.getId() << ", count = "
32 << job.getRunCount() << ")" << sio.nl;
33}
34
35int main()
36{
37
38 mCron.addJob( slot( &job0 ), MiniCron::TimerInterval( time(NULL)+3, 5 ) );
39 mCron.addJob( slot( &job1 ), MiniCron::TimerInterval( time(NULL)+10, 8 ) );
40 mCron.addJob( slot( &job2 ), MiniCron::TimerBasic("weekly wed 17") );
41 mCron.addJob( slot( &job3 ), MiniCron::TimerInterval( time(NULL)+1, 2 ) );
42
43 sio << time( NULL ) << ": Program started." << sio.nl;
44
45 for(;;)
46 {
47 usleep( 50000 );
48 mCron.poll();
49 }
50
51 return 0;
52}
53