diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/minicron.cpp | 53 |
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 | |||
6 | using namespace Bu; | ||
7 | |||
8 | Bu::MiniCron mCron; | ||
9 | |||
10 | void job0( Bu::MiniCron::Job &job ) | ||
11 | { | ||
12 | sio << time( NULL ) << ": job0( id = " << job.getId() << ", count = " | ||
13 | << job.getRunCount() << ")" << sio.nl; | ||
14 | } | ||
15 | |||
16 | void 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 | |||
23 | void job2( Bu::MiniCron::Job &job ) | ||
24 | { | ||
25 | sio << time( NULL ) << ": job2( id = " << job.getId() << ", count = " | ||
26 | << job.getRunCount() << ")" << sio.nl; | ||
27 | } | ||
28 | |||
29 | void job3( Bu::MiniCron::Job &job ) | ||
30 | { | ||
31 | sio << time( NULL ) << ": job3( id = " << job.getId() << ", count = " | ||
32 | << job.getRunCount() << ")" << sio.nl; | ||
33 | } | ||
34 | |||
35 | int 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 | |||