gs_cancel.cpp

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*    gs_cancel.cpp                                                           */
00004 /*    source file that implements the job cancellation                        */
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_cancel, 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     //cancel the job
00060     status = grpc_cancel(req_id);
00061 
00062     if (status != GRPC_NO_ERROR) {
00063         fprintf(stderr, "%s\n", grpc_error_string(status));
00064         return bad_retval;
00065     }
00066 
00067     //finalize and clean up
00068     grpc_finalize();
00069     return octave_value(status);
00070 }
00071 
00072 
00073 
00074 
00075