- Add GUI RPC to set projects debts (short and long term).

Lets you set all of them at once, as suggested by Nicolas Alvarez.
    fixes #131

client/
    gui_rpc_server_ops.C
html/user/
    sample_index.php
lib/
    boinc_cmd.C
    gui_rpc_client.h
    gui_rpc_client_ops.C

svn path=/trunk/boinc/; revision=12749
This commit is contained in:
David Anderson 2007-05-26 21:15:58 +00:00
parent b3e3ce4c43
commit 56408dbbbe
6 changed files with 127 additions and 41 deletions

View File

@ -5345,3 +5345,17 @@ David 24 May 2007
api/
texfont.C (changed c to C)
Makefile.am
David 26 May 2007
- Add GUI RPC to set projects debts (short and long term).
Lets you set all of them at once, as suggested by Nicolas Alvarez.
fixes #131
client/
gui_rpc_server_ops.C
html/user/
sample_index.php
lib/
boinc_cmd.C
gui_rpc_client.h
gui_rpc_client_ops.C

View File

@ -45,6 +45,7 @@
#endif
#include "str_util.h"
#include "client_state.h"
#include "util.h"
#include "error_numbers.h"
#include "parse.h"
@ -182,7 +183,7 @@ static void handle_result_show_graphics(char* buf, MIOFILE& fout) {
GRAPHICS_MSG gm;
ACTIVE_TASK* atp;
if (match_tag(buf, "<full_screen/>")) {
if (match_tag(buf, "<full_screen/>")) {
gm.mode = MODE_FULLSCREEN;
} else if (match_tag(buf, "<hide/>")) {
gm.mode = MODE_HIDE_GRAPHICS;
@ -518,13 +519,13 @@ static void handle_set_screensaver_mode(char* buf, MIOFILE& fout) {
parse_str(buf, "<window_station>", gm.window_station, sizeof(gm.window_station));
parse_str(buf, "<display>", gm.display, sizeof(gm.display));
if (match_tag(buf, "<enabled")) {
if (log_flags.scrsave_debug) {
msg_printf(NULL, MSG_INFO, "Got start msg from screensaver");
if (log_flags.scrsave_debug) {
msg_printf(NULL, MSG_INFO, "Got start msg from screensaver");
}
gstate.ss_logic.start_ss(gm, blank_time );
} else {
if (log_flags.scrsave_debug) {
msg_printf(NULL, MSG_INFO, "Got stop msg from screensaver");
if (log_flags.scrsave_debug) {
msg_printf(NULL, MSG_INFO, "Got stop msg from screensaver");
}
gstate.ss_logic.stop_ss();
}
@ -580,8 +581,8 @@ static void handle_get_cc_status(GUI_RPC_CONN* gr, MIOFILE& fout) {
gstate.network_mode.get_current(),
gstate.run_mode.get_perm(),
gstate.network_mode.get_perm(),
gstate.run_mode.delay(),
gstate.network_mode.delay()
gstate.run_mode.delay(),
gstate.network_mode.delay()
);
if (gr->au_mgr_state == AU_MGR_QUIT_REQ) {
fout.printf(
@ -873,6 +874,58 @@ static void read_all_projects_list_file(MIOFILE& fout) {
}
}
static int set_debt(XML_PARSER& xp) {
bool is_tag;
char tag[256], url[256];
double short_term_debt, long_term_debt;
bool got_std=false, got_ltd=false;
strcpy(url, "");
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!strcmp(tag, "/project")) {
if (!strlen(url)) return ERR_XML_PARSE;
PROJECT* p = gstate.lookup_project(url);
if (!p) return ERR_NOT_FOUND;
if (got_std) p->short_term_debt = short_term_debt;
if (got_ltd) p->long_term_debt = long_term_debt;
return 0;
}
if (xp.parse_str(tag, "master_url", url, sizeof(url))) continue;
if (xp.parse_double(tag, "short_term_debt", short_term_debt)) {
got_std = true;
continue;
}
if (xp.parse_double(tag, "long_term_debt", long_term_debt)) {
got_ltd = true;
continue;
}
}
}
static void handle_set_debts(char* buf, MIOFILE& fout) {
MIOFILE in;
XML_PARSER xp(&in);
bool is_tag;
char tag[256];
int retval;
in.init_buf_read(buf);
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) continue;
if (!strcmp(tag, "/set_debts")) {
fout.printf("<success/>\n");
gstate.set_client_state_dirty("set_debt RPC");
break;
}
if (!strcmp(tag, "project")) {
retval = set_debt(xp);
if (retval) {
fout.printf("<error>%d</error>\n", retval);
return;
}
}
}
}
static void handle_set_cc_config(char* buf, MIOFILE& fout) {
char *p, *q=0;
int retval = ERR_XML_PARSE;
@ -1036,6 +1089,8 @@ int GUI_RPC_CONN::handle_rpc() {
gstate.request_work_fetch("Core client configuration");
} else if (match_tag(request_msg, "<get_all_projects_list/>")) {
read_all_projects_list_file(mf);
} else if (match_tag(request_msg, "<set_debts")) {
handle_set_debts(request_msg, mf);
} else {
// RPCs after this point enable network communication
@ -1072,8 +1127,8 @@ int GUI_RPC_CONN::handle_rpc() {
} else if (match_tag(request_msg, "<acct_mgr_rpc_poll")) {
handle_acct_mgr_rpc_poll(request_msg, mf);
// DON'T JUST ADD NEW RPCS HERE - THINK ABOUT THEIR
// AUTHENTICATION AND NETWORK REQUIREMENTS FIRST
// DON'T JUST ADD NEW RPCS HERE - THINK ABOUT THEIR
// AUTHENTICATION AND NETWORK REQUIREMENTS FIRST
} else {
mf.printf("<error>unrecognized op</error>\n");

View File

@ -22,12 +22,11 @@ function show_nav() {
You can participate by downloading and running a free program
on your computer.
<p>
XXX is based at research lab of Professor XXX
at <a href=xxx>the University of XXX</a>.
XXX is based at
[describe your institution, with link to web page]
<ul>
<li> <a href=xxx>Our research</a>
<li> <a href=xxx>Project personnel</a>
<li> <a href=\"apps.php\">".tr(APPS_TITLE)."</a>
<li> [Link to page describing your research in detail]
<li> [Link to page listing project personnel, and an email address]
</ul>
<h2>Join ".PROJECT."</h2>
<ul>
@ -47,6 +46,7 @@ function show_nav() {
<li><a href=\"home.php\">Your account</a> - view stats, modify preferences
<li><a href=\"team.php\">Teams</a> - create or join a team
<li><a href=\"cert1.php\">Certificate</a>
<li> <a href=\"apps.php\">".tr(APPS_TITLE)."</a>
</ul>
<h2>Community</h2>
<ul>

View File

@ -95,6 +95,7 @@ Commands:\n\
--read_cc_config\n\
--network_available\n\
--get_cc_status\n\
--set_debts URL1 std1 ltd1 [URL2 std2 ltd2 ...]\n\
--quit\n"
);
exit(1);
@ -498,40 +499,27 @@ int main(int argc, char** argv) {
retval = rpc.read_global_prefs_override();
} else if (!strcmp(cmd, "--read_cc_config")) {
retval = rpc.read_cc_config();
} else if (!strcmp(cmd, "--test1")) {
string s;
retval = rpc.get_global_prefs_override(s);
printf("retval: %d\nprefs:\n%s\n", retval, s.c_str());
} else if (!strcmp(cmd, "--test2")) {
string s = "foobar";
retval = rpc.set_global_prefs_override(s);
printf("retval: %d\n", retval);
} else if (!strcmp(cmd, "--test3")) {
GLOBAL_PREFS gp;
GLOBAL_PREFS_MASK mask;
memset(&gp, 0, sizeof(gp));
mask.clear();
retval = rpc.get_global_prefs_override_struct(gp, mask);
printf("retval %d max %d\n", retval, gp.max_cpus);
} else if (!strcmp(cmd, "--test4")) {
GLOBAL_PREFS gp;
GLOBAL_PREFS_MASK m;
gp.max_cpus = 2;
m.max_cpus = true;
retval = rpc.set_global_prefs_override_struct(gp, m);
printf("retval %d\n", retval);
} else if (!strcmp(cmd, "--quit")) {
retval = rpc.quit();
} else if (!strcmp(cmd, "read_cc_config")) {
retval = rpc.read_cc_config();
} else if (!strcmp(cmd, "network_available")) {
} else if (!strcmp(cmd, "--network_available")) {
retval = rpc.network_available();
} else if (!strcmp(cmd, "get_cc_status")) {
} else if (!strcmp(cmd, "--get_cc_status")) {
CC_STATUS cs;
retval = rpc.get_cc_status(cs);
if (!retval) {
retval = cs.network_status;
}
} else if (!strcmp(cmd, "--set_debts")) {
vector<PROJECT>projects;
while (i < argc) {
PROJECT p;
p.master_url = string(next_arg(argc, argv, i));
p.short_term_debt = atoi(next_arg(argc, argv, i));
p.long_term_debt = atoi(next_arg(argc, argv, i));
projects.push_back(p);
}
retval = rpc.set_debts(projects);
} else if (!strcmp(cmd, "--quit")) {
retval = rpc.quit();
} else {
fprintf(stderr, "unrecognized command %s\n", cmd);
}

View File

@ -612,6 +612,7 @@ public:
int set_global_prefs_override(std::string&);
int get_global_prefs_override_struct(GLOBAL_PREFS&, GLOBAL_PREFS_MASK&);
int set_global_prefs_override_struct(GLOBAL_PREFS&, GLOBAL_PREFS_MASK&);
int set_debts(std::vector<PROJECT>);
};
struct RPC {

View File

@ -2216,4 +2216,32 @@ int RPC_CLIENT::read_cc_config() {
return retval;
}
int RPC_CLIENT::set_debts(vector<PROJECT> projects) {
int retval;
SET_LOCALE sl;
char buf[64000], buf2[1024];
RPC rpc(this);
string s;
s = "<set_debts>\n";
for (unsigned int i=0; i<projects.size(); i++) {
PROJECT& p = projects[i];
sprintf(buf2,
" <project>\n"
" <master_url>%s</master_url>\n"
" <short_term_debt>%f</short_term_debt>\n"
" <long_term_debt>%f</long_term_debt>\n"
" </project>\n",
p.master_url.c_str(),
p.short_term_debt,
p.long_term_debt
);
s += string(buf2);
}
s += "</set_debts>\n";
retval = rpc.do_rpc(s.c_str());
return retval;
}
const char *BOINC_RCSID_90e8b8d168="$Id$";