Go to the documentation of this file.00001
00007
00008
00009
00010 #include <stdio.h>
00011 #include <string.h>
00012
00013 #include <matrix.h>
00014 #include <mex.h>
00015
00016 #ifdef HAVE_CONFIG_H
00017 #include "config.h"
00018 #endif
00019
00020 #include "grpc.h"
00021 #include "comm_data.h"
00022 #include "matlab_gs.h"
00023
00033 void
00034 matlab_gs_call_async( int nlhs, mxArray *plhs[],
00035 int nrhs, const mxArray *prhs[] )
00036 {
00037 grpc_function_handle_t* handle = NULL;
00038 char func_name[1024];
00039 grpc_arg_stack* argstack = NULL;
00040 gs_argument_t *argp = NULL;
00041 grpc_sessionid_t sessionID;
00042 grpc_error_t status;
00043 int i;
00044 int argcount = 0;
00045 int rc;
00046
00047
00048 matlab_gs_error_num = 0;
00049
00050
00051 if ((nlhs != 1) || (nrhs < 2)) {
00052 mexPrintf("Usage: [request_id] = gs_call_async('service_name', ...) \n");
00053 DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
00054 }
00055
00056
00057 rc = grpc_initialize(NULL);
00058 if ((rc != GRPC_NO_ERROR) && (rc != GRPC_ALREADY_INITIALIZED)) DO_ERROR_MACRO(grpc_errno);
00059
00060
00061 if (grpc_set_client_major("Column") != GRPC_NO_ERROR)
00062 DO_ERROR_MACRO(grpc_errno);
00063
00064
00065 if (!mxIsChar(prhs[1])) DO_ERROR_MACRO(GRPC_FUNCTION_NOT_FOUND);
00066 if (mxGetString(prhs[1],func_name,1024) != 0) DO_ERROR_MACRO(GRPC_FUNCTION_NOT_FOUND);
00067
00068
00069 handle = (grpc_function_handle_t*)matlab_gs_calloc(1, sizeof(grpc_function_handle_t));
00070 if (handle == NULL) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
00071 if ((status = grpc_function_handle_default(handle, func_name)) != GRPC_NO_ERROR) DO_ERROR_MACRO(status);
00072 if (handle->problem_desc == NULL) DO_ERROR_MACRO(GRPC_INVALID_FUNCTION_HANDLE);
00073
00074
00075
00076
00077
00078
00079 if (matlab_gs_setup_args(handle->problem_desc, nlhs, plhs, nrhs, prhs) != 0)
00080 DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
00081
00082
00083 for (argcount=0,argp=handle->problem_desc->arglist; argp!=NULL; argp=argp->next)
00084 if (argp->inout != GS_WORKSPACE) argcount++;
00085 if ((argstack = grpc_arg_stack_new(argcount)) == NULL) DO_ERROR_MACRO(grpc_errno);
00086 for (argp=handle->problem_desc->arglist; argp!=NULL; argp=argp->next) {
00087 if (argp->inout != GS_WORKSPACE)
00088 if (grpc_arg_stack_push_arg(argstack, argp->data) < 0)
00089 DO_ERROR_MACRO(grpc_errno);
00090 }
00091
00092
00093 status = grpc_call_arg_stack_async_ft(handle, &sessionID, argstack);
00094 if (status != GRPC_NO_ERROR) DO_ERROR_MACRO(status);
00095 if (matlab_gs_free_input_args(handle->problem_desc, nlhs, plhs, nrhs, prhs) != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
00096
00097
00098 plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
00099 mxGetPr(plhs[0])[0] = (double)sessionID;
00100
00101 return;
00102
00103
00104
00105
00106 error:
00107
00108
00109 if (nlhs > 0) {
00110 plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
00111 mxGetPr(plhs[0])[0] = (double) -1;
00112 }
00113
00114 for (i=1;i<nlhs;i++)
00115 plhs[i] = mxCreateDoubleMatrix(0,0,mxREAL);
00116
00117 mexPrintf("Warning: GridSolve call failed: %d:%d: %s; %s\n", grpc_errno, grpc_minor_errno, grpc_error_string(grpc_errno), grpc_minor_error_string(grpc_minor_errno));
00118
00119 if (matlab_gs_free_args(handle->problem_desc, nlhs, plhs, nrhs, prhs) != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
00120 if (argstack && grpc_arg_stack_destruct(argstack) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
00121 if (handle && grpc_function_handle_destruct(handle) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
00122 handle = matlab_gs_free(handle);
00123
00124 return;
00125
00126 }
00127
00128
00129
00130