aboutsummaryrefslogtreecommitdiff
path: root/src/tests/minicron.cpp
blob: 0749f9046f8be221a51c58479049d4fa727b6e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (C) 2007-2010 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/minicron.h"
#include "bu/sio.h"

#include <unistd.h>

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(
		"job0", slot( &job0 ), MiniCron::TimerInterval( time(NULL)+3, 5 ) );
	mCron.addJob(
		"job1", slot( &job1 ), MiniCron::TimerInterval( time(NULL)+10, 8 ) );
	mCron.addJob(
		"job2", slot( &job2 ), MiniCron::TimerBasic("weekly wed 17") );
	mCron.addJob(
		"job3", slot( &job3 ), MiniCron::TimerInterval( time(NULL)+1, 2 ) );

	sio << time( NULL ) << ": Program started." << sio.nl;

	for(;;)
	{
		usleep( 50000 );
		mCron.poll();
	}

	return 0;
}