~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to sched/sample_work_generator.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
// You should have received a copy of the GNU Lesser General Public License
16
16
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
 
// sample_work_generator.C: an example BOINC work generator.
 
18
// sample_work_generator.cpp: an example BOINC work generator.
19
19
// This work generator has the following properties
20
20
// (you may need to change some or all of these):
21
21
//
37
37
#include "backend_lib.h"
38
38
#include "parse.h"
39
39
#include "util.h"
 
40
#include "svn_version.h"
40
41
 
41
42
#include "sched_config.h"
42
43
#include "sched_util.h"
43
44
#include "sched_msgs.h"
 
45
#include "str_util.h"
44
46
 
45
47
#define CUSHION 100
46
48
    // maintain at least this many unsent results
98
100
        wu,
99
101
        wu_template,
100
102
        "templates/uc_result",
101
 
        "../templates/uc_result",
 
103
        config.project_path("templates/uc_result"),
102
104
        infiles,
103
105
        1,
104
106
        config
136
138
    }
137
139
}
138
140
 
 
141
void usage(char *name) {
 
142
    fprintf(stderr, "This is an example BOINC work generator.\n"
 
143
        "This work generator has the following properties\n"
 
144
        "(you may need to change some or all of these):\n"
 
145
        "- Runs as a daemon, and creates an unbounded supply of work.\n"
 
146
        "  It attempts to maintain a \"cushion\" of 100 unsent job instances.\n"
 
147
        "  (your app may not work this way; e.g. you might create work in batches)\n"
 
148
        "- Creates work for the application \"uppercase\".\n"
 
149
        "- Creates a new input file for each job;\n"
 
150
        "  the file (and the workunit names) contain a timestamp\n"
 
151
        "  and sequence number, so that they're unique.\n\n"
 
152
        "Usage: %s [OPTION]...\n\n"
 
153
        "Options:\n"
 
154
        "  [ -d X ]                    Sets debug level to X.\n"
 
155
        "  [ -h | --help ]             Shows this help text.\n"
 
156
        "  [ -v | --version ]          Shows version information.\n",
 
157
        name
 
158
    );
 
159
}
 
160
 
139
161
int main(int argc, char** argv) {
140
162
    int i, retval;
141
163
 
142
164
    for (i=1; i<argc; i++) {
143
 
        if (!strcmp(argv[i], "-d")) {
144
 
            log_messages.set_debug_level(atoi(argv[++i]));
 
165
        if (is_arg(argv[i], "d")) {
 
166
            if (!argv[++i]) {
 
167
                log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
 
168
                usage(argv[0]);
 
169
                exit(1);
 
170
            }
 
171
            int dl = atoi(argv[i]);
 
172
            log_messages.set_debug_level(dl);
 
173
            if (dl == 4) g_print_queries = true;
 
174
        } else if (is_arg(argv[i], "h") || is_arg(argv[i], "help")) {
 
175
            usage(argv[0]);
 
176
            exit(0);
 
177
        } else if (is_arg(argv[i], "v") || is_arg(argv[i], "version")) {
 
178
            printf("%s\n", SVN_VERSION);
 
179
            exit(0);
145
180
        } else {
146
 
            log_messages.printf(MSG_CRITICAL,
147
 
                "bad cmdline arg: %s", argv[i]
148
 
            );
 
181
            log_messages.printf(MSG_CRITICAL, "unknown command line argument: %s\n\n", argv[i]);
 
182
            usage(argv[0]);
 
183
            exit(1);
149
184
        }
150
185
    }
151
186
 
152
 
    if (config.parse_file("..")) {
 
187
    retval = config.parse_file();
 
188
    if (retval) {
153
189
        log_messages.printf(MSG_CRITICAL,
154
 
            "can't read config file\n"
 
190
            "Can't parse config.xml: %s\n", boincerror(retval)
155
191
        );
156
192
        exit(1);
157
193
    }
167
203
        log_messages.printf(MSG_CRITICAL, "can't find app\n");
168
204
        exit(1);
169
205
    }
170
 
    if (read_file_malloc("../templates/uc_wu", wu_template)) {
 
206
    if (read_file_malloc(config.project_path("templates/uc_wu"), wu_template)) {
171
207
        log_messages.printf(MSG_CRITICAL, "can't read WU template\n");
172
208
        exit(1);
173
209
    }