~ubuntu-branches/ubuntu/lucid/boinc/lucid

« back to all changes in this revision

Viewing changes to api/api_app.C

  • Committer: Bazaar Package Importer
  • Author(s): Frank S. Thomas, Frank S. Thomas
  • Date: 2008-05-31 08:02:47 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080531080247-4ce890lp2rc768cr
Tags: 6.2.7-1
[ Frank S. Thomas ]
* New upstream release.
  - BOINC Manager: Redraw disk usage charts immediately after connecting to
    a (different) client. (closes: 463823)
* debian/copyright:
  - Added the instructions from debian/README.Debian-source about how
    repackaged BOINC tarballs can be reproduced because DevRef now
    recommends to put this here instead of in the afore-mentioned file.
  - Updated for the new release.
* Removed the obsolete debian/README.Debian-source.
* For consistency upstream renamed the core client and the command tool
  ("boinc_client" to "boinc" and "boinc_cmd" to "boinccmd"). Done the same
  in all packages and created symlinks with the old names for the binaries
  and man pages. Also added an entry in debian/boinc-client.NEWS explaining
  this change.
* debian/rules: Do not list Makefile.ins in the clean target individually,
  just remove all that can be found.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Berkeley Open Infrastructure for Network Computing
2
 
// http://boinc.berkeley.edu
3
 
// Copyright (C) 2005 University of California
4
 
//
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.
9
 
//
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.
14
 
//
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
19
 
 
20
 
// test program for MFILE class
21
 
 
22
 
#include "config.h"
23
 
 
24
 
#include <cstdlib>
25
 
#ifdef HAVE_SYS_TIME_H
26
 
#include <sys/time.h>
27
 
#endif
28
 
 
29
 
#include "boinc_api.h"
30
 
 
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);
34
 
 
35
 
int main(int argc, char **argv) {
36
 
    MFILE mf, check;
37
 
    unsigned long int i = 0;
38
 
    int temp=0, secs, usecs;
39
 
    APP_IN ai;
40
 
    APP_OUT ao;
41
 
    boinc_init(ai);
42
 
    mf.open("foobar", "w");
43
 
    mf.printf("blah %d %f\n", 17, 34.5);
44
 
    mf.printf("foo\n");
45
 
    if(!recover("counter", &i)) {
46
 
        check.open("counter", "w");
47
 
        check.printf("%d", 0);
48
 
        check.flush();
49
 
        check.close();
50
 
    }
51
 
    if(parse_args(argc, argv, secs, usecs)) {
52
 
        fprintf(stderr, "error: could not parse arguments\n");
53
 
        return 1;
54
 
    }
55
 
    if(timer(secs, usecs)) {
56
 
        fprintf(stderr, "error: could not initialize timer\n");
57
 
        return 1;
58
 
    }
59
 
    for(; i<100000000; i++) {
60
 
        if(time_to_checkpoint()) {
61
 
            check.open("counter", "w");
62
 
            check.printf("%d", i);
63
 
            check.flush();
64
 
            check.close();
65
 
            ao.percent_done = ((double)i)/100000000.0;
66
 
            checkpoint_completed(ao);
67
 
        }
68
 
        temp++;
69
 
    }
70
 
    mf.close();
71
 
    ao.percent_done = 1;
72
 
    app_completed(ao);
73
 
    return 0;
74
 
}
75
 
 
76
 
int recover(char* file, unsigned long int* i) {
77
 
    FILE* f = fopen(file, "r");
78
 
    if(f==NULL) {
79
 
        *i=0;
80
 
        return 0;
81
 
    }
82
 
    fscanf(f, "%lu", i);
83
 
    if(fclose(f)) {
84
 
        fprintf(stderr, "error: could not close file %s\n", file);
85
 
        exit(-1);
86
 
    }
87
 
    return *i;
88
 
}
89
 
 
90
 
int timer(int secs, int usecs) {
91
 
    int retval=0;
92
 
#ifdef HAVE_SYS_TIME_H
93
 
    itimerval value;
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);
99
 
#endif
100
 
    return retval;
101
 
}
102
 
 
103
 
int parse_args(int argc, char **argv, int& secs, int& usecs) {
104
 
    if(argc != 3) {
105
 
        fprintf(stderr, "error: incorrect number of arguments %d\n", argc);
106
 
        return 1;
107
 
    }
108
 
    secs = atoi(argv[1]);
109
 
    usecs = atoi(argv[2]);
110
 
    return 0;
111
 
}
112
 
 
113
 
const char *BOINC_RCSID_bccd17d4ec = "$Id: api_app.C 8896 2005-11-21 18:34:44Z korpela $";