Changes between Version 5 and Version 6 of BossaImplementation


Ignore:
Timestamp:
Oct 18, 2007, 3:23:50 PM (17 years ago)
Author:
davea
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BossaImplementation

    v5 v6  
    11= Bossa reference manual =
    22
    3 == Creating a Bossa project ==
    4 
    5 First, [ServerIntro set up a BOINC server] and [MakeProject create a project].
    6 You'll need PHP 5.2 or later (for JSON functions).
    7 Say your project is called '''test_project''', your BOINC source directory is '''~/boinc''',
    8 and your BOINC projects directory is '''~/projects'''.
    9 
    10 Create Bossa's database tables as follows:
    11 {{{
    12 cd ~/boinc/db
    13 mysql test_project < bossa_schema.sql
    14 mysql test_project < bossa_constraints.sql
    15 }}}
    16 
    17 Create a Bossa application (see below) as follows:
    18 {{{
    19 cd ~/projects/test_project/html/ops
    20 php bossa_setup_example.php
    21 }}}
    22 
    23 bossa_setup_example.php contains:
    24 {{{
    25 $ba = new BossaApp();
    26 $ba->name = 'bossa_test';
    27 $ba->user_friendly_name = 'Simple pattern recognition';
    28 $ba->start_url = 'bossa_example.php';
    29 
    30 if ($ba->insert($ba)) {
    31     echo "Added application '$ba->name'\n";
    32 } else {
    33     echo "Couldn't add '$ba->name': ", mysql_error(), "\n";
    34 }
    35 }}}
    36 You can edit this to change the application name
    37 and front-end script name, if you like.
    383
    394== Database tables and PHP structures ==
     
    8853The Bossa PHP code uses the following classes:
    8954
    90  '''BossaApp, BossaJob, BossaJobInst'''::
     55 '''!BossaApp, !BossaJob, !BossaJobInst'''::
    9156  These correspond to the above tables, and have fields corresponding to each database field.  They offer various functions to insert, look up, and modify database rows.
    92  '''Bossa''':
     57 '''Bossa'''::
    9358  Various utility functions.
     59
     60== Creating a Bossa project ==
     61
     62First, [ServerIntro set up a BOINC server] and [MakeProject create a project].
     63You'll need PHP 5.2 or later (for JSON functions).
     64Say your project is called '''test_project''', your BOINC source directory is '''~/boinc''',
     65and your BOINC projects directory is '''~/projects'''.
     66
     67Create Bossa's database tables as follows:
     68{{{
     69cd ~/boinc/db
     70mysql test_project < bossa_schema.sql
     71mysql test_project < bossa_constraints.sql
     72}}}
     73
     74Create a Bossa application (see below) as follows:
     75{{{
     76cd ~/projects/test_project/html/ops
     77php bossa_setup_example.php
     78}}}
     79
     80bossa_setup_example.php contains:
     81{{{
     82$ba = new BossaApp();
     83$ba->name = 'bossa_test';
     84$ba->user_friendly_name = 'Simple pattern recognition';
     85$ba->start_url = 'bossa_example.php';
     86
     87if ($ba->insert($ba)) {
     88    echo "Added application '$ba->name'\n";
     89} else {
     90    echo "Couldn't add '$ba->name': ", mysql_error(), "\n";
     91}
     92}}}
     93You can edit this to change the application name
     94and front-end script name, if you like.
     95
     96== Adding jobs ==
    9497
    9598== Front-end scripts ==
    9699
    97 == Adding jobs ==
     100You develop a '''front-end script''' to show a job instance to a user,
     101and to handle a completed instance.
     102It's handy to put both of these functions in a single file.
     103A front-end script is called with the URL parameter '''bji''' set
     104to a job instance ID.
     105Here's an example:
     106
     107{{{
     108     1  <?php
     109     2
     110     3  require_once("../inc/bossa.inc");
     111     4
     112     5  echo "foo";
     113     6
     114     7  // Bossa example.
     115     8  // Show the user an image and ask them whether it's a zero or one.
     116     9
     117    10  function show_job($bj, $bji) {
     118    11      if ($bji->finish_time) {
     119    12          error_page("You already finished this job");
     120    13      }
     121    14      $info = json_decode($bj->info);
     122    15      $img_url = "http://boinc.berkeley.edu/images/number_".$info->number.".jpg";
     123    16      echo "
     124    17          <form method=get action=bossa_example.php>
     125    18          <input type=hidden name=bji value=$bji->id>
     126    19          <img src=$img_url>
     127    20          <br>
     128    21          The picture shows a
     129    22          <br><input type=radio name=response value=0> zero
     130    23          <br><input type=radio name=response value=1> one
     131    24          <br><input type=radio name=response value=2 checked> not sure
     132    25          <br><br><input type=submit name=submit value=OK>
     133    26          </form>
     134    27      ";
     135    28  }
     136    29
     137    30  function handle_job_completion($bj, $bji) {
     138    31      $response = null;
     139    32      $response->number = get_int('response');
     140    33      $bji->info = json_encode($response);
     141    34      $bji->completed($bj);
     142    35
     143    36      // show another job immediately
     144    37      //
     145    38      Bossa::show_next_job($bj);
     146    39  }
     147    40
     148    41  Bossa::script_init($user, $bj, $bji);
     149    42
     150    43  if ($_GET['submit']) {
     151    44      handle_job_completion($bj, $bji);
     152    45  } else {
     153    46      show_job($bj, $bji);
     154    47  }
     155    48
     156    49  ?>
     157}}}
     158
     159Line 41::
     160  Call a Bossa utility function to look up the job instance and make sure that it was issued to the logged-in user.  The job instance, job, and user are returned.
     161Line 43::
     162  Branch according to whether we are showing a job or handling the completion of a job.
     163