[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.12, Wed Nov 25 21:52:02 2009 UTC revision 1.13, Wed Nov 25 22:34:35 2009 UTC
# Line 32  Line 32 
32      my ($serverName, $key) = @_;      my ($serverName, $key) = @_;
33      # Turn off YAML compression, which causes problems with some of our hash keys.      # Turn off YAML compression, which causes problems with some of our hash keys.
34      $YAML::CompressSeries = 0;      $YAML::CompressSeries = 0;
35      # Get the CGI parameters.      # Create the server object.
36        Trace("Requiring $serverName") if T(3);
37        eval {
38            require "$serverName.pm";
39        };
40        # If we have an error, create an error document.
41        if ($@) {
42            SendError($@, "Could not load server module.");
43        } else {
44            # Having successfully loaded the server code, we create the object.
45            my $serverThing = eval("$serverName" . '->new()');
46            # If we have an error, create an error document.
47            if ($@) {
48                SendError($@, "Could not start server.");
49            } else {
50                # No error, so now we can process the request.
51      my $cgi;      my $cgi;
52      if (! defined $key) {      if (! defined $key) {
53          # No tracing key, so presume we're a web service. Check for Fast CGI.          # No tracing key, so presume we're a web service. Check for Fast CGI.
# Line 47  Line 62 
62              require CGI::Fast;              require CGI::Fast;
63              while (($cgi = new CGI::Fast()) &&              while (($cgi = new CGI::Fast()) &&
64                     (MAX_REQUESTS == 0 || ++$requests < MAX_REQUESTS)) {                     (MAX_REQUESTS == 0 || ++$requests < MAX_REQUESTS)) {
65                  RunRequest($cgi, $serverName);                          RunRequest($cgi, $serverThing);
66              }              }
67          } else {          } else {
68              # Here we have a normal web service (non-Fast).              # Here we have a normal web service (non-Fast).
# Line 63  Line 78 
78                  ETracing($key);                  ETracing($key);
79              }              }
80              # Run this request.              # Run this request.
81              RunRequest($cgi, $serverName);                      RunRequest($cgi, $serverThing);
82          }          }
83      } else {      } else {
84          # We're being invoked from the command line. Use the tracing          # We're being invoked from the command line. Use the tracing
# Line 73  Line 88 
88          # Set up tracing using the specified key.          # Set up tracing using the specified key.
89          ETracing($key);          ETracing($key);
90          # Run this request.          # Run this request.
91          RunRequest($cgi, $serverName);                  RunRequest($cgi, $serverThing);
92                }
93            }
94      }      }
95  }  }
96    
# Line 199  Line 216 
216    
217  CGI query object containing the parameters from the web service request.  CGI query object containing the parameters from the web service request.
218    
219  =item serverName  =item serverThing
220    
221  Name of the server to be used for running the request.  Server object against which to run the request.
222    
223  =back  =back
224    
# Line 209  Line 226 
226    
227  sub RunRequest {  sub RunRequest {
228      # Get the parameters.      # Get the parameters.
229      my ($cgi, $serverName, $docURL) = @_;      my ($cgi, $serverThing, $docURL) = @_;
     Trace("Running $serverName server request.") if T(3);  
230      # Determine the request type.      # Determine the request type.
231      if ($cgi->param('pod')) {      if ($cgi->param('pod')) {
232          # Here we have a documentation request. In this case, we produce POD HTML.          # Here we have a documentation request. In this case, we produce POD HTML.
# Line 255  Line 271 
271          } elsif (! $function) {          } elsif (! $function) {
272              SendError("No function specified.", "No function specified.");              SendError("No function specified.", "No function specified.");
273          } else {          } else {
             # We're okay, so load the server function object.  
             Trace("Requiring $serverName") if T(3);  
             eval {  
                 require "$serverName.pm";  
             };  
             # If we have an error, create an error document.  
             if ($@) {  
                 SendError($function, $@, "Could not load server module.");  
             } else {  
                 # Having successfully loaded the server code, we create the object.  
                 my $serverThing = eval("$serverName" . '->new()');  
                 # If we have an error, create an error document.  
                 if ($@) {  
                     SendError($@, "Could not start server.");  
                 } else {  
                     # No error, so execute the server method.  
                     Trace("Executing $function.") if T(2);  
274                      $document = eval("\$serverThing->$function(\$args)");                      $document = eval("\$serverThing->$function(\$args)");
275                      # If we have an error, create an error document.                      # If we have an error, create an error document.
276                      if ($@) {                      if ($@) {
# Line 283  Line 282 
282                          print YAML::Dump($document);                          print YAML::Dump($document);
283                      }                      }
284                  }                  }
             }  
         }  
285          # Stop the timer.          # Stop the timer.
286          my $duration = int(time() - $start + 0.5);          my $duration = int(time() - $start + 0.5);
287          Trace("Function executed in $duration seconds.") if T(2);          Trace("Function executed in $duration seconds.") if T(2);
# Line 483  Line 480 
480  }  }
481    
482    
   
483  1;  1;

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3