- client and GUI RPC: add some plumbing for notices

svn path=/trunk/boinc/; revision=19973
This commit is contained in:
David Anderson 2009-12-18 21:52:08 +00:00
parent 12955d898c
commit 62156200f4
10 changed files with 259 additions and 1 deletions

View File

@ -10303,3 +10303,16 @@ David 18 Dec 2009
client/
app_start.cpp
David 18 Dec 2009
- client and GUI RPC: add some plumbing for notices
client/
Makefile.am
cs_notice.cpp,h (new)
gui_rpc_server_ops.cpp
lib/
Makefile.am
gui_rpc_client.h
gui_rpc_client_ops.cpp
notice.cpp,h (new)

View File

@ -49,6 +49,7 @@ boinc_client_SOURCES = \
cs_benchmark.cpp \
cs_cmdline.cpp \
cs_files.cpp \
cs_notice.cpp \
cs_platforms.cpp \
cs_prefs.cpp \
cs_proxy.cpp \

34
client/cs_notice.cpp Normal file
View File

@ -0,0 +1,34 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// 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.
//
// BOINC is distributed in the hope that it will be useful,
// 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include "cs_notice.h"
using std::deque;
deque<NOTICE> notices;
void write_notices(int seqno, MIOFILE& fout, bool public_only) {
unsigned int i;
fout.printf("<notices>\n");
for (i=0; i<notices.size(); i++) {
NOTICE& n = notices[i];
if (n.seqno <= seqno) break;
if (public_only && n.is_private) continue;
n.write(fout);
}
fout.printf("</notices>\n");
}

38
client/cs_notice.h Normal file
View File

@ -0,0 +1,38 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// 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.
//
// BOINC is distributed in the hope that it will be useful,
// 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include <deque>
#include "miofile.h"
#include "notice.h"
extern std::deque<NOTICE> notices;
extern void write_notices(int seqno, MIOFILE&, bool public_only);
#if 0
// RSS_FEED represents an RSS feed that the client
// polls periodically and caches on disk
struct RSS_FEED {
char url[256];
std::vector<RSS_ITEM> items;
int fetch_start();
int fetch_complete();
};
#endif

View File

@ -63,6 +63,7 @@
#include "client_msgs.h"
#include "client_state.h"
#include "cs_proxy.h"
#include "cs_notice.h"
using std::string;
using std::vector;
@ -1092,6 +1093,18 @@ static void handle_set_cc_config(char* buf, MIOFILE& fout) {
);
}
static void handle_get_notices(char* buf, MIOFILE& fout) {
int seqno = 0;
parse_int(buf, "<seqno>", seqno);
write_notices(seqno, fout, false);
}
static void handle_get_notices_public(char* buf, MIOFILE& fout) {
int seqno = 0;
parse_int(buf, "<seqno>", seqno);
write_notices(seqno, fout, true);
}
// Some of the RPCs have empty-element request messages.
// We accept both <foo/> and <foo></foo>
//
@ -1190,6 +1203,8 @@ int GUI_RPC_CONN::handle_rpc() {
handle_get_cc_status(this, mf);
} else if (match_req(request_msg, "get_all_projects_list")) {
read_all_projects_list_file(mf);
} else if (match_req(request_msg, "get_notices_public")) {
handle_get_notices_public(request_msg, mf);
// Operations that require authentication start here
@ -1269,10 +1284,13 @@ int GUI_RPC_CONN::handle_rpc() {
gstate.request_work_fetch("Core client configuration");
} else if (match_req(request_msg, "set_debts")) {
handle_set_debts(request_msg, mf);
} else if (match_req(request_msg, "get_notices")) {
handle_get_notices(request_msg, mf);
} else {
// RPCs after this point require authentication,
// and enable network communication for 5 minutes, overriding other factors.
// and enable network communication for 5 minutes,
// overriding other factors.
// Things like attaching projects, etc.
//

View File

@ -51,6 +51,7 @@ generic_sources = \
miofile.cpp \
msg_log.cpp \
network.cpp \
notice.cpp \
parse.cpp \
prefs.cpp \
procinfo_unix.cpp \
@ -110,6 +111,7 @@ pkginclude_HEADERS = \
miofile.h \
msg_log.h \
network.h \
notice.h \
parse.h \
prefs.h \
proxy_info.h \

View File

@ -33,6 +33,7 @@
#include "prefs.h"
#include "hostinfo.h"
#include "common_defs.h"
#include "notice.h"
struct GUI_URL {
std::string name;
@ -677,6 +678,8 @@ public:
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>);
int get_notices(int, std::vector<NOTICE>&);
int get_notices_public(int, std::vector<NOTICE>&);
};
struct RPC {

View File

@ -2280,5 +2280,54 @@ int RPC_CLIENT::set_debts(vector<PROJECT> projects) {
return retval;
}
static int parse_notices(MIOFILE& fin, vector<NOTICE>& notices) {
XML_PARSER xp(&fin);
char tag[256];
bool is_tag;
int retval;
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) continue;
if (!strcmp(tag, "notice")) {
NOTICE notice;
retval = notice.parse(xp);
if (!retval) {
notices.push_back(notice);
}
}
}
}
int RPC_CLIENT::get_notices(int seqno, vector<NOTICE>& notices) {
SET_LOCALE sl;
char buf[1024];
RPC rpc(this);
int retval;
sprintf(buf,
"<get_notices>\n"
" <seqno>%d</seqno>\n"
"</get_notices>\n"
);
retval = rpc.do_rpc(buf);
if (retval) return retval;
return parse_notices(rpc.fin, notices);
}
int RPC_CLIENT::get_notices_public(int seqno, vector<NOTICE>& notices) {
SET_LOCALE sl;
char buf[1024];
RPC rpc(this);
int retval;
sprintf(buf,
"<get_notices_public>\n"
" <seqno>%d</seqno>\n"
"</get_notices_public>\n"
);
retval = rpc.do_rpc(buf);
if (retval) return retval;
return parse_notices(rpc.fin, notices);
}
const char *BOINC_RCSID_90e8b8d168="$Id$";

61
lib/notice.cpp Normal file
View File

@ -0,0 +1,61 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// 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.
//
// BOINC is distributed in the hope that it will be useful,
// 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include "error_numbers.h"
#include "notice.h"
int NOTICE::parse(XML_PARSER& xp) {
char tag[1024];
bool is_tag;
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) continue;
if (!strcmp(tag, "/notice")) return 0;
if (xp.parse_int(tag, "seqno", seqno)) continue;
if (xp.parse_str(tag, "title", title, sizeof(title))) continue;
if (xp.parse_string(tag, "description", description)) continue;
if (xp.parse_double(tag, "create_time", create_time)) continue;
if (xp.parse_double(tag, "arrival_time", arrival_time)) continue;
if (xp.parse_bool(tag, "is_private", is_private)) continue;
if (xp.parse_str(tag, "category", category, sizeof(category))) continue;
if (xp.parse_str(tag, "url", url, sizeof(url))) continue;
}
return ERR_XML_PARSE;
}
void NOTICE::write(MIOFILE& f) {
f.printf(
"<notice>\n"
" <seqno>%d</seqno>\n"
" <title>%s</title>\n"
" <description>%s</description>\n"
" <create_time>%f</create_time>\n"
" <arrival_time>%f</arrival_time>\n"
" <is_private>%d</is_private>\n"
" <category>%s</category>\n"
" <url>%s</url>\n"
"</notice>\n",
seqno,
title,
description,
create_time,
arrival_time,
is_private?1:0,
category,
url
);
}

39
lib/notice.h Normal file
View File

@ -0,0 +1,39 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// 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.
//
// BOINC is distributed in the hope that it will be useful,
// 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include <string>
#include "parse.h"
// represents a notice delivered from client to GUI
struct NOTICE {
int seqno;
char title[256];
std::string description;
double create_time;
double arrival_time; // when item arrived at client
bool is_private;
char category[64];
char url[256];
// the following fields used in client only
char guid[256];
int parse(XML_PARSER&);
void write(MIOFILE&);
};