From 13f51d42e58fb735dd9b4d8c43f493b1ec563a0f Mon Sep 17 00:00:00 2001
From: David Anderson
Date: Sun, 20 May 2012 23:02:12 +0000
Subject: [PATCH] - API: add boinc_network_usage(); lets an application
report its network usage to BOINC, and hence take it into account with
monthly limits etc. - API: get rid of deprecated boinc_ops_per_cpu_sec(),
boinc_ops_cumulative(), and boinc_set_credit_claim(); - admin web: update
manage_apps.php; add the ability to set homogeneous app version
svn path=/trunk/boinc/; revision=25700
---
api/boinc_api.cpp | 57 +++----
api/boinc_api.h | 1 +
checkin_notes | 15 ++
html/ops/manage_apps.php | 333 ++++++++++++++++++---------------------
4 files changed, 187 insertions(+), 219 deletions(-)
diff --git a/api/boinc_api.cpp b/api/boinc_api.cpp
index 6b58f1dfd2..6d8be85033 100644
--- a/api/boinc_api.cpp
+++ b/api/boinc_api.cpp
@@ -141,12 +141,10 @@ static volatile int interrupt_count = 0;
static volatile int running_interrupt_count = 0;
// number of timer interrupts while not suspended.
// Used to compute elapsed time
-static double fpops_per_cpu_sec = 0;
-static double fpops_cumulative = 0;
-static double intops_per_cpu_sec = 0;
-static double intops_cumulative = 0;
static int want_network = 0;
static int have_network = 1;
+static double bytes_sent = 0;
+static double bytes_received = 0;
bool g_sleep = false;
// simulate unresponsive app by setting to true (debugging)
static FUNC_PTR timer_callback = 0;
@@ -336,21 +334,13 @@ static bool update_app_progress(double cpu_t, double cp_cpu_t) {
sprintf(buf, "%e\n", fdone);
strlcat(msg_buf, buf, MSG_CHANNEL_SIZE);
}
- if (fpops_per_cpu_sec) {
- sprintf(buf, "%e\n", fpops_per_cpu_sec);
- strlcat(msg_buf, buf, MSG_CHANNEL_SIZE);
+ if (bytes_sent) {
+ sprintf(buf, "%f\n", bytes_sent);
+ strcat(msg_buf, buf);
}
- if (fpops_cumulative) {
- sprintf(buf, "%e\n", fpops_cumulative);
- strlcat(msg_buf, buf, MSG_CHANNEL_SIZE);
- }
- if (intops_per_cpu_sec) {
- sprintf(buf, "%e\n", intops_per_cpu_sec);
- strlcat(msg_buf, buf, MSG_CHANNEL_SIZE);
- }
- if (intops_cumulative) {
- sprintf(buf, "%e\n", intops_cumulative);
- strlcat(msg_buf, buf, MSG_CHANNEL_SIZE);
+ if (bytes_received) {
+ sprintf(buf, "%f\n", bytes_received);
+ strcat(msg_buf, buf);
}
return app_client_shm->shm->app_status.send_msg(msg_buf);
}
@@ -684,6 +674,11 @@ void boinc_exit(int status) {
#endif
}
+void boinc_network_usage(double sent, double received) {
+ bytes_sent = sent;
+ bytes_received = received;
+}
+
int boinc_is_standalone() {
if (standalone) return 1;
return 0;
@@ -754,8 +749,8 @@ int boinc_report_app_status_aux(
double checkpoint_cpu_time,
double _fraction_done,
int other_pid,
- double bytes_sent,
- double bytes_received
+ double _bytes_sent,
+ double _bytes_received
) {
char msg_buf[MSG_CHANNEL_SIZE], buf[256];
if (standalone) return 0;
@@ -772,12 +767,12 @@ int boinc_report_app_status_aux(
sprintf(buf, "%d\n", other_pid);
strcat(msg_buf, buf);
}
- if (bytes_sent) {
- sprintf(buf, "%f\n", bytes_sent);
+ if (_bytes_sent) {
+ sprintf(buf, "%f\n", _bytes_sent);
strcat(msg_buf, buf);
}
- if (bytes_received) {
- sprintf(buf, "%f\n", bytes_received);
+ if (_bytes_received) {
+ sprintf(buf, "%f\n", _bytes_received);
strcat(msg_buf, buf);
}
if (app_client_shm->shm->app_status.send_msg(msg_buf)) {
@@ -1433,20 +1428,6 @@ int boinc_upload_status(std::string& name) {
return ERR_NOT_FOUND;
}
-void boinc_ops_per_cpu_sec(double fp, double i) {
- fpops_per_cpu_sec = fp;
- intops_per_cpu_sec = i;
-}
-
-void boinc_ops_cumulative(double fp, double i) {
- fpops_cumulative = fp;
- intops_cumulative = i;
-}
-
-void boinc_set_credit_claim(double credit) {
- boinc_ops_cumulative(credit*8.64000e+11, 0);
-}
-
void boinc_need_network() {
want_network = 1;
have_network = 0;
diff --git a/api/boinc_api.h b/api/boinc_api.h
index 50e8a8c940..a3f87a61e7 100644
--- a/api/boinc_api.h
+++ b/api/boinc_api.h
@@ -100,6 +100,7 @@ extern void boinc_end_critical_section();
extern void boinc_need_network();
extern int boinc_network_poll();
extern void boinc_network_done();
+extern void boinc_network_usage(double sent, double received);
extern int boinc_is_standalone(void);
extern void boinc_ops_per_cpu_sec(double fp, double integer);
extern void boinc_ops_cumulative(double fp, double integer);
diff --git a/checkin_notes b/checkin_notes
index ca2a238f11..122ffebd0e 100644
--- a/checkin_notes
+++ b/checkin_notes
@@ -3958,3 +3958,18 @@ Rom 18 May 2012
AccountManagerInfoPage.cpp
clientgui/
ProjectListCtrl.cpp, .h
+
+David 20 May 2012
+ - API: add boinc_network_usage();
+ lets an application report its network usage to BOINC,
+ and hence take it into account with monthly limits etc.
+ - API: get rid of deprecated boinc_ops_per_cpu_sec(),
+ boinc_ops_cumulative(), and
+ boinc_set_credit_claim();
+ - admin web: update manage_apps.php;
+ add the ability to set homogeneous app version
+
+ html/ops/
+ manage_apps.php
+ api/
+ boinc_api.cpp,h
diff --git a/html/ops/manage_apps.php b/html/ops/manage_apps.php
index 955e5cdc28..58d07621df 100644
--- a/html/ops/manage_apps.php
+++ b/html/ops/manage_apps.php
@@ -18,15 +18,13 @@
-/***********************************************************************\
- * Display and Manage BOINC Application Versions
- *
- * This page presents a form with information about application versions.
- * Some of the fields can be changed.
- *
- * Eric Myers - 4 June 2006
- * @(#) $Id$
-\***********************************************************************/
+// Display and Manage BOINC Application Versions
+//
+// This page presents a form with information about application versions.
+// Some of the fields can be changed.
+//
+// Eric Myers - 4 June 2006
+// @(#) $Id$
// TODO - code cleanup and use new DB interface
@@ -36,217 +34,190 @@ db_init();
$commands = "";
-// Platform and application labels (are better than numbers)
+// process form input for changes
+//
+function do_updates() {
+ $apps = BoincApp::enum("");
-$result = mysql_query("SELECT * FROM platform");
-$Nplatform = mysql_num_rows($result);
-for($i=0;$i<$Nplatform;$i++){
- $item=mysql_fetch_object($result);
- $id=$item->id;
- $plat_off[$id]=$item->deprecated;
- $platform[$id]=$item->user_friendly_name;
- }
-mysql_free_result($result);
+ foreach ($apps as $app) {
+ $id = $app->id;
-/***************************************************\
- * Action: process form input for changes
- \***************************************************/
-
-if( !empty($_POST) ) {
-
- /* Changing properties of existing applications */
-
- $result = mysql_query("SELECT * FROM app");
- $Nrow=mysql_num_rows($result);
-
- for($j=1;$j<=$Nrow;$j++){ // test/update each row in DB
- $item=mysql_fetch_object($result);
- $id=$item->id;
-
- /* Change deprecated status? */
- $field="deprecated_".$id;
- $new_v= (post_str($field, true)=='on') ? 1 : 0;
- $old_v=$item->deprecated;
- if($new_v != $old_v ) {
- $cmd = "UPDATE app SET deprecated=$new_v WHERE id=$id";
- $commands .= "$cmd
\n";
- mysql_query($cmd);
+ // Change deprecated status?
+ //
+ $field = "deprecated_".$id;
+ $new_v = (post_str($field, true)=='on') ? 1 : 0;
+ $old_v = $app->deprecated;
+ if ($new_v != $old_v ) {
+ $app->update("deprecated=$new_v");
}
- /* Minimum version limit */
- $field="min_version_".$id;
- $new_v= $_POST[$field] + 0;
- $old_v=$item->min_version;
- if( $new_v != $old_v ) {
- $cmd = "UPDATE app SET min_version=$new_v WHERE id=$id";
- $commands .= "$cmd
\n";
- mysql_query($cmd);
+ $field = "weight_".$id;
+ $new_v = $_POST[$field] + 0;
+ $old_v = $app->weight;
+ if ($new_v != $old_v ) {
+ $app->update("weight=$new_v");
}
-
- $field="weight_".$id;
- $new_v= $_POST[$field] + 0;
- $old_v=$item->weight;
- if( $new_v != $old_v ) {
- $cmd = "UPDATE app SET weight=$new_v WHERE id=$id";
- $commands .= "$cmd
\n";
- mysql_query($cmd);
+ $field = "homogeneous_redundancy_".$id;
+ $new_v = $_POST[$field];
+ $old_v = $app->homogeneous_redundancy;
+ if ($new_v != $old_v ) {
+ $app->update("homogeneous_redundancy=$new_v");
}
- /* Homogendous redundancy restriction (same platform for all WU's) */
- $field="homogeneous_redundancy_".$id;
- $new_v= $_POST[$field];
- $old_v=$item->homogeneous_redundancy;
- if( $new_v != $old_v ) {
- $cmd = "UPDATE app SET homogeneous_redundancy=$new_v WHERE id=$id";
- $commands .= "$cmd
\n";
- mysql_query($cmd);
+ $field = "homogeneous_app_version".$id;
+ $new_v = (post_str($field, true)=='on') ? 1 : 0;
+ $old_v = $app->homogeneous_app_version;
+ if ($new_v != $old_v ) {
+ $app->update("homogeneous_app_version=$new_v");
}
}
- /* Adding a new application */
+ // Adding a new application
- if(post_str('add_app', true)) {
- $name= mysql_real_escape_string($_POST['add_name']);
- $user_friendly_name=mysql_real_escape_string($_POST['add_user_friendly_name']);
- if( empty($name) || empty($user_friendly_name) ) {
+ if (post_str('add_app', true)) {
+ $name = mysql_real_escape_string($_POST['add_name']);
+ $user_friendly_name = mysql_real_escape_string($_POST['add_user_friendly_name']);
+ if (empty($name) || empty($user_friendly_name) ) {
$commands .= "
- To add a new application please supply both a brief name and a
- longer 'user-friendly' name.
\n";
- }
- else {
- $now=time();
+ To add a new application please supply both a brief name and a
+ longer 'user-friendly' name.
+ ";
+ } else {
+ $now = time();
$cmd = "INSERT INTO app (name,user_friendly_name,create_time) ".
"VALUES ('$name', '$user_friendly_name',$now)";
$commands .= "$cmd
\n";
mysql_query($cmd);
}
}
- }//$_POST
-
-
-/***************************************************\
- * Display the DB contents in a form
- \***************************************************/
-
-admin_page_head("Manage Applications");
-
-if (strlen($commands)) {
- echo "The following updates were done: $commands
-
- You must stop and restart the project
- for these changes to take effect.
-";
}
-$self=$_SERVER['PHP_SELF'];
-echo "
\n";
+ admin_page_tail();
+}
-echo "
\n";
-
-admin_page_tail();
+if( !empty($_POST) ) {
+ do_updates();
+ show_form(true);
+} else {
+ show_form(false);
+}
//Generated automatically - do not edit
$cvs_version_tracker[]="\$Id$";