1
// Berkeley Open Infrastructure for Network Computing
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2005 University of California
5
// This is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation;
8
// either version 2.1 of the License, or (at your option) any later version.
10
// This software is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// To view the GNU Lesser General Public License visit
16
// http://www.gnu.org/copyleft/lesser.html
17
// or write to the Free Software Foundation, Inc.,
18
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
// test program for MFILE class
25
#ifdef HAVE_SYS_TIME_H
29
#include "boinc_api.h"
31
int recover(char* file, unsigned long int* i);
32
int timer(int secs, int usecs);
33
int parse_args(int argc, char **argv, int& secs, int& usecs);
35
int main(int argc, char **argv) {
37
unsigned long int i = 0;
38
int temp=0, secs, usecs;
42
mf.open("foobar", "w");
43
mf.printf("blah %d %f\n", 17, 34.5);
45
if(!recover("counter", &i)) {
46
check.open("counter", "w");
47
check.printf("%d", 0);
51
if(parse_args(argc, argv, secs, usecs)) {
52
fprintf(stderr, "error: could not parse arguments\n");
55
if(timer(secs, usecs)) {
56
fprintf(stderr, "error: could not initialize timer\n");
59
for(; i<100000000; i++) {
60
if(time_to_checkpoint()) {
61
check.open("counter", "w");
62
check.printf("%d", i);
65
ao.percent_done = ((double)i)/100000000.0;
66
checkpoint_completed(ao);
76
int recover(char* file, unsigned long int* i) {
77
FILE* f = fopen(file, "r");
84
fprintf(stderr, "error: could not close file %s\n", file);
90
int timer(int secs, int usecs) {
92
#ifdef HAVE_SYS_TIME_H
94
value.it_value.tv_sec=secs;
95
value.it_value.tv_usec=usecs;
96
value.it_interval.tv_sec=0;
97
value.it_interval.tv_usec=0;
98
retval = setitimer(ITIMER_REAL, &value, NULL);
103
int parse_args(int argc, char **argv, int& secs, int& usecs) {
105
fprintf(stderr, "error: incorrect number of arguments %d\n", argc);
108
secs = atoi(argv[1]);
109
usecs = atoi(argv[2]);
113
const char *BOINC_RCSID_bccd17d4ec = "$Id: api_app.C 8896 2005-11-21 18:34:44Z korpela $";