[Bio] / FigKernelPackages / ServerThing.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/ServerThing.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.56, Thu Oct 14 17:28:49 2010 UTC revision 1.62, Wed Feb 9 17:56:09 2011 UTC
# Line 40  Line 40 
40      # Create the server object.      # Create the server object.
41      Trace("Requiring $serverName for task $$.") if T(3);      Trace("Requiring $serverName for task $$.") if T(3);
42      eval {      eval {
43          require "$serverName.pm";          my $output = $serverName;
44            $output =~ s/::/\//;
45            require "$output.pm";
46      };      };
47      # If we have an error, create an error document.      # If we have an error, create an error document.
48      if ($@) {      if ($@) {
# Line 363  Line 365 
365      return $retVal;      return $retVal;
366  }  }
367    
368    =head3 ChangeDB
369    
370        ServerThing::ChangeDB($thing, $newDbName);
371    
372    Change the sapling database used by this server. The old database will be closed and a
373    new one attached.
374    
375    =over 4
376    
377    =item newDbName
378    
379    Name of the new Sapling database on which this server should operate. If omitted, the
380    default database will be used.
381    
382    =back
383    
384    =cut
385    
386    sub ChangeDB {
387        # Get the parameters.
388        my ($thing, $newDbName) = @_;
389        # Default the db-name if it's not specified.
390        if (! defined $newDbName) {
391            $newDbName = $FIG_Config::saplingDB;
392        }
393        # Check to see if we really need to change.
394        my $oldDB = $thing->{db};
395        if (! defined $oldDB || $oldDB->dbName() ne $newDbName) {
396            # We need a new sapling.
397            require Sapling;
398            my $newDB = Sapling->new(dbName => $newDbName);
399            $thing->{db} = $newDB;
400        }
401    }
402    
403    
404  =head2 Gene Correspondence File Methods  =head2 Gene Correspondence File Methods
405    
# Line 831  Line 868 
868      }      }
869      # Close the input file.      # Close the input file.
870      close $ih;      close $ih;
871      # If we have no errors and we found a reverse arrow, keep the result.      # If we have no errors, keep the result.
872      if (! $error) {      if (! $error) {
         if ($reverseFound) {  
873              $retVal = \@corrList;              $retVal = \@corrList;
         } else {  
             Trace("No reverse arrow found in correspondence file $fileName.") if T(Corr => 1);  
         }  
874      }      }
875      # Return the result (if any).      # Return the result (if any).
876      return $retVal;      return $retVal;
# Line 998  Line 1031 
1031    
1032  =head3 RunRequest  =head3 RunRequest
1033    
1034      ServerThing::RunRequest($cgi, $serverName);      ServerThing::RunRequest($cgi, $serverThing, $docURL);
1035    
1036  Run a request from the specified server using the incoming CGI parameter  Run a request from the specified server using the incoming CGI parameter
1037  object for the parameters.  object for the parameters.
# Line 1050  Line 1083 
1083    
1084  Server object against which to run the request.  Server object against which to run the request.
1085    
1086    =item docURL
1087    
1088    URL to use for POD documentation requests.
1089    
1090  =back  =back
1091    
1092  =cut  =cut
# Line 1057  Line 1094 
1094  sub RunRequest {  sub RunRequest {
1095      # Get the parameters.      # Get the parameters.
1096      my ($cgi, $serverThing, $docURL) = @_;      my ($cgi, $serverThing, $docURL) = @_;
1097        # Make the CGI object available to the server.
1098        $serverThing->{cgi} = $cgi;
1099      # Determine the request type.      # Determine the request type.
1100      my $module = $cgi->param('pod');      my $module = $cgi->param('pod');
1101      if ($module) {      if ($module) {
# Line 1095  Line 1134 
1134              if $function =~ /\W/;              if $function =~ /\W/;
1135          # Determing the encoding scheme. The default is YAML.          # Determing the encoding scheme. The default is YAML.
1136          my $encoding = $cgi->param('encoding') || 'yaml';          my $encoding = $cgi->param('encoding') || 'yaml';
1137            # Optional callback for json encoded documents
1138            my $callback = $cgi->param('callback');
1139          # The parameter structure will go in here.          # The parameter structure will go in here.
1140          my $args = {};          my $args = {};
1141          # Start the timer.          # Start the timer.
1142          my $start = time();          my $start = time();
1143          # The output document goes in here.          # The output document goes in here.
1144          my $document;          my $document;
         # The sapling database goes in here.  
         my $sapling;  
1145          # Protect from errors.          # Protect from errors.
1146          eval {          eval {
1147              # Here we parse the arguments. This is affected by the encoding parameter.              # Here we parse the arguments. This is affected by the encoding parameter.
# Line 1128  Line 1167 
1167          } elsif (! $function) {          } elsif (! $function) {
1168              SendError("No function specified.", "No function specified.");              SendError("No function specified.", "No function specified.");
1169          } else {          } else {
1170                # Insure we're connected to the correct database.
1171                my $dbName = $cgi->param('dbName');
1172                if ($dbName && exists $serverThing->{db}) {
1173                    ChangeDB($serverThing, $dbName);
1174                }
1175                # Run the request.
1176              $document = eval { $serverThing->$function($args) };              $document = eval { $serverThing->$function($args) };
1177              # If we have an error, create an error document.              # If we have an error, create an error document.
1178              if ($@) {              if ($@) {
# Line 1135  Line 1180 
1180                  Trace("Error encountered by service: $@") if T(0);                  Trace("Error encountered by service: $@") if T(0);
1181              } else {              } else {
1182                  # No error, so we output the result. Start with an HTML header.                  # No error, so we output the result. Start with an HTML header.
1183                    if ($encoding eq 'yaml') {
1184                  print $cgi->header(-type => 'text/plain');                  print $cgi->header(-type => 'text/plain');
1185                    } else {
1186                        print $cgi->header(-type => 'text/javascript');
1187                    }
1188                  # The nature of the output depends on the encoding type.                  # The nature of the output depends on the encoding type.
1189                  my $string;                  my $string;
1190                  if ($encoding eq 'yaml') {                  if ($encoding eq 'yaml') {
1191                      $string = YAML::Dump($document);                      $string = YAML::Dump($document);
1192                    } elsif(defined($callback)) {
1193                        $string = $callback . "(".JSON::Any->objToJson($document).")";
1194                  } else {                  } else {
1195                      $string = JSON::Any->objToJson($document);                      $string = JSON::Any->objToJson($document);
1196                  }                  }

Legend:
Removed from v.1.56  
changed lines
  Added in v.1.62

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3