gs_probe.cpp

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*    gs_call_probe.cpp                                                       */
00004 /*    source file that implements the job probing                             */
00005 /*    for the octave client for GridSolve systems                             */
00006 /*                                                                            */
00007 /*    Copyright (C)                                                           */
00008 /*    Innovative Computing Laboratory (ICL)                                   */
00009 /*    Univesity of Tennessee, Knoxville                                       */
00010 /*                                                                            */
00011 /*    Feburary 22, 2007                                                       */
00012 /******************************************************************************/
00013 
00014 
00015 #include <oct.h>
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 #include "grpc.h"
00019 #include "gs_oct.h"
00020 
00021 
00022 DEFUN_DLD (gs_probe, args, nargout, "Octave client for GridSolve") {
00023     octave_value_list bad_retval;   //bad return value
00024     grpc_error_t status;            //GridRPC status/error code
00025     grpc_sessionid_t req_id;        //GridRPC non-blocking call session id
00026 
00027 
00028     //meaningless return value for error condition
00029     //or those calls that do not make grpc function call
00030     for (int i = 0; i < nargout; i++) {
00031         bad_retval(i) = Matrix(0, 0);
00032     }
00033 
00034     //number of input arguments
00035     int nargin = args.length();
00036 
00037     //input argument error checking
00038     if (nargin <= 0) {
00039         fprintf(stderr, "No input service name found. Aborted.\n");
00040         return bad_retval;
00041     }
00042 
00043     if (nargin > 1) {
00044         fprintf(stderr, "Exactly one argument (session id) is expected. Aborted.\n");
00045         return bad_retval;
00046     }
00047     
00048     //otherwise, the input is correct
00049     
00050     //initialize the GridSolve environment
00051     status = grpc_initialize(NULL);
00052     if (status != GRPC_NO_ERROR && status != GRPC_ALREADY_INITIALIZED) {
00053         fprintf(stderr, "%s\n", grpc_error_string(status));
00054         return bad_retval;
00055     }
00056 
00057     //the GRPC session id
00058     req_id = args(0).int_value();
00059     //probe the job status
00060     status = grpc_probe(req_id);
00061 
00062     if (status == GRPC_NOT_COMPLETED) { //not completed
00063         printf("Job has not completed.\n");
00064     }
00065     else if (status == GRPC_NO_ERROR) { //completed
00066         printf("Job has completed.\n");
00067     } else {
00068         fprintf(stderr, "Error in probing.\n");
00069         return bad_retval;
00070     }
00071 
00072     return octave_value(status);
00073 }
00074 
00075 
00076 
00077 
00078