2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-02-05 23:30:28 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-03-17 01:26:44 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2004-03-17 01:26:44 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2004-03-17 01:26:44 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2008-02-05 23:30:28 +00:00
|
|
|
//
|
2006-10-11 16:32:59 +00:00
|
|
|
// trickle_handler - framework for trickle-up message handler
|
2004-03-17 01:26:44 +00:00
|
|
|
//
|
2006-07-17 16:38:53 +00:00
|
|
|
// -variety variety
|
2004-03-17 01:26:44 +00:00
|
|
|
// [-d debug_level]
|
|
|
|
// [-one_pass] // make one pass through table, then exit
|
|
|
|
//
|
|
|
|
// This program must be linked with an app-specific function:
|
|
|
|
//
|
2006-07-17 16:38:53 +00:00
|
|
|
// int handle_trickle(MSG_FROM_HOST&)
|
2004-03-17 01:26:44 +00:00
|
|
|
// handle a trickle message
|
|
|
|
//
|
|
|
|
// return nonzero on error
|
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-03-17 01:26:44 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "boinc_db.h"
|
|
|
|
#include "util.h"
|
2008-10-27 21:23:07 +00:00
|
|
|
#include "error_numbers.h"
|
2008-02-05 23:30:28 +00:00
|
|
|
#include "str_util.h"
|
2008-10-27 21:23:07 +00:00
|
|
|
|
2004-03-17 01:26:44 +00:00
|
|
|
#include "sched_config.h"
|
|
|
|
#include "sched_util.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "sched_msgs.h"
|
2004-03-17 01:26:44 +00:00
|
|
|
|
2004-07-06 04:10:51 +00:00
|
|
|
char variety[256];
|
2004-03-17 01:26:44 +00:00
|
|
|
|
2004-06-22 22:56:50 +00:00
|
|
|
extern int handle_trickle(MSG_FROM_HOST&);
|
2004-03-17 01:26:44 +00:00
|
|
|
|
2006-07-17 16:38:53 +00:00
|
|
|
// The following is an example;
|
|
|
|
// replace it with your own function
|
|
|
|
//
|
2004-06-22 22:56:50 +00:00
|
|
|
int handle_trickle(MSG_FROM_HOST& mfh) {
|
2004-05-12 21:21:09 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
printf(
|
2004-06-22 22:56:50 +00:00
|
|
|
"got trickle-up \n%s\n\n",
|
|
|
|
mfh.xml
|
2004-05-12 21:21:09 +00:00
|
|
|
);
|
2004-06-22 22:56:50 +00:00
|
|
|
DB_MSG_TO_HOST mth;
|
|
|
|
mth.clear();
|
|
|
|
mth.create_time = time(0);
|
|
|
|
mth.hostid = mfh.hostid;
|
2004-07-06 04:10:51 +00:00
|
|
|
strcpy(mth.variety, mfh.variety);
|
2004-06-22 22:56:50 +00:00
|
|
|
mth.handled = false;
|
2004-07-06 04:10:51 +00:00
|
|
|
sprintf(mth.xml,
|
|
|
|
"<trickle_down>\n"
|
|
|
|
"%s"
|
|
|
|
"</trickle_down>\n",
|
|
|
|
mfh.xml
|
|
|
|
);
|
2004-06-22 22:56:50 +00:00
|
|
|
retval = mth.insert();
|
2004-05-12 21:21:09 +00:00
|
|
|
if (retval) {
|
|
|
|
printf("insert failed %d\n", retval);
|
|
|
|
}
|
2004-03-17 01:26:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make one pass through trickle_ups with handled == 0
|
|
|
|
// return true if there were any
|
|
|
|
//
|
2008-06-26 21:20:07 +00:00
|
|
|
bool do_trickle_scan() {
|
2004-06-22 22:56:50 +00:00
|
|
|
DB_MSG_FROM_HOST mfh;
|
2004-03-17 01:26:44 +00:00
|
|
|
char buf[256];
|
|
|
|
bool found=false;
|
2004-05-12 21:21:09 +00:00
|
|
|
int retval;
|
2004-03-17 01:26:44 +00:00
|
|
|
|
2004-07-06 04:10:51 +00:00
|
|
|
sprintf(buf, "where variety='%s' and handled=0", variety);
|
2008-10-27 21:23:07 +00:00
|
|
|
while (1) {
|
|
|
|
retval = mfh.enumerate(buf);
|
|
|
|
if (retval) {
|
|
|
|
if (retval != ERR_DB_NOT_FOUND) {
|
|
|
|
fprintf(stderr, "lost DB conn\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-06-22 22:56:50 +00:00
|
|
|
retval = handle_trickle(mfh);
|
2004-05-12 21:21:09 +00:00
|
|
|
if (!retval) {
|
2004-06-22 22:56:50 +00:00
|
|
|
mfh.handled = true;
|
|
|
|
mfh.update();
|
2004-05-12 21:21:09 +00:00
|
|
|
}
|
2004-03-17 01:26:44 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main_loop(bool one_pass) {
|
|
|
|
int retval;
|
|
|
|
bool did_something;
|
|
|
|
|
2008-09-22 17:52:41 +00:00
|
|
|
retval = boinc_db.open(
|
|
|
|
config.db_name, config.db_host, config.db_user, config.db_passwd
|
|
|
|
);
|
2004-03-17 01:26:44 +00:00
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL, "boinc_db.open failed: %d\n", retval);
|
2004-03-17 01:26:44 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2004-05-03 19:30:01 +00:00
|
|
|
check_stop_daemons();
|
2008-06-26 21:20:07 +00:00
|
|
|
did_something = do_trickle_scan();
|
2004-03-17 01:26:44 +00:00
|
|
|
if (one_pass) break;
|
|
|
|
if (!did_something) {
|
|
|
|
sleep(5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
int i, retval;
|
2007-04-18 20:49:58 +00:00
|
|
|
bool one_pass = false;
|
2004-03-17 01:26:44 +00:00
|
|
|
|
2004-05-03 19:30:01 +00:00
|
|
|
check_stop_daemons();
|
2004-03-17 01:26:44 +00:00
|
|
|
|
|
|
|
for (i=1; i<argc; i++) {
|
2007-04-18 20:49:58 +00:00
|
|
|
if (!strcmp(argv[i], "-one_pass")) {
|
2004-03-17 01:26:44 +00:00
|
|
|
one_pass = true;
|
2004-07-06 04:10:51 +00:00
|
|
|
} else if (!strcmp(argv[i], "-variety")) {
|
|
|
|
strcpy(variety, argv[++i]);
|
2004-03-17 01:26:44 +00:00
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
|
|
|
log_messages.set_debug_level(atoi(argv[++i]));
|
|
|
|
} else {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2008-02-05 23:30:28 +00:00
|
|
|
"unrecognized arg: %s\n", argv[i]
|
|
|
|
);
|
2004-03-17 01:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = config.parse_file("..");
|
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2007-05-11 16:30:13 +00:00
|
|
|
"Can't parse ../config.xml: %s\n", boincerror(retval)
|
2004-03-17 01:26:44 +00:00
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2008-02-05 23:30:28 +00:00
|
|
|
"Starting trickle handler\n"
|
|
|
|
);
|
2004-03-17 01:26:44 +00:00
|
|
|
|
|
|
|
install_stop_signal_handler();
|
|
|
|
|
|
|
|
main_loop(one_pass);
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_560388f67e = "$Id$";
|