open-source Notes

Notes of an open-source programmer.
11 Dec

How To: create your own work generator script (part 4)

This is the last part of the How To: create your own work generator script for BOINC. The other parts covering the header definitions, the make_job() function and the main_loop() function.

This is the code:

int main(int argc, char** argv) {
    int i, retval;

    for (i=1; i<argc; i++) {
        if (!strcmp(argv[i], "-d")) {
            log_messages.set_debug_level(atoi(argv[++i]));
        } else {
            log_messages.printf(MSG_CRITICAL,
                "bad cmdline arg: %s", argv[i]
            );
        }
    }

    if (config.parse_file("..")) {
        log_messages.printf(MSG_CRITICAL,
            "can't read config file\n"
        );
        exit(1);
    }

    retval = boinc_db.open(
        config.db_name, config.db_host, config.db_user, config.db_passwd
    );
    if (retval) {
        log_messages.printf(MSG_CRITICAL, "can't open db\n");
        exit(1);
    }
    // TODO: change appname for which the work is generated
    if (app.lookup("where name='ostools_app'")) {
        log_messages.printf(MSG_CRITICAL, "can't find app\n");
        exit(1);
    }
    // TODO: change workunit template if needed
    if (read_file_malloc("../templates/ostools_workunit", wu_template)) {
        log_messages.printf(MSG_CRITICAL, "can't read WU template\n");
        exit(1);
    }

    start_time = time(0);
    seqno = 0;

    log_messages.printf(MSG_NORMAL, "Starting\n");

    main_loop();
}

At first the command line parameters are analyzed which is very simple because there could be only one. The “-d n” switch can be used to set the debug level. There are 3 levels: 1 = critical messages only, 2 = normal messages, 3 = detailed debugging info. The next check is for the BOINC config file and the database connection, both are needed to run the work generator.

If those checks are accomplished we can read the application data from the database. Change the name of the application you want to use. Make sure it’s the same as in the database. This is also very important for the workunit template file. Make sure it is the right one.

The last step the main() function does is initialize the start_time and the sequence number used later in the make_work() function. At the end it calls the main_loop() which will do all the work. Isn’t that simple building a BOINC daemon? You can download the whole file now if you want (ostools_work_generator.cpp).

Read the previous parts of this How To: the header of the generator, the make_job() function and the main_loop() function.

Leave a Reply

© 2010 open-source Notes | Entries (RSS) and Comments (RSS)

GPS Reviews and news from GPS Gazettewordpress logo