#include <stdio.h>#include <string.h>#include <matrix.h>#include <mex.h>#include "grpc.h"#include "comm_data.h"#include "matlab_gs.h"
Go to the source code of this file.
Functions | |
| void | matlab_gs_wait (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
Matlab client call
Definition in file matlab_gs_wait.c.
| void matlab_gs_wait | ( | int | nlhs, | |
| mxArray * | plhs[], | |||
| int | nrhs, | |||
| const mxArray * | prhs[] | |||
| ) |
Wait for the completion of a prevously submitted asynchronous call using grpc_wait, returning the status of the grpc_wait call (0 if OK, -1 if error).
| nlhs | - Number of left hand side arguments from Matlab | |
| plhs | - Pointer to left hand side arguments from Matlab | |
| rlhs | - Number of right hand side arguments from Matlab | |
| plhs | - Pointer to right hand side arguments from Matlab |
Definition at line 32 of file matlab_gs_wait.c.
{
int i = -1;
int rc = -1;
grpc_request_t *request = NULL;
grpc_sessionid_t sessionID;
grpc_error_t status;
/* reset global error setting */
matlab_gs_error_num = 0;
/* Check arguments */
if (nrhs < 2) {
mexErrMsgTxt("Usage: [outputargs,...] = gs_wait(sessionID, inputargs, ...)\n");
for (i=0;i<nlhs;i++) plhs[i] = mxCreateDoubleMatrix(0,0,mxREAL);
DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
}
/* Get sessionid from rhs */
sessionID = (int)mxGetPr(prhs[1])[0];
if (sessionID < 0) DO_ERROR_MACRO(GRPC_INVALID_SESSION_ID);
/* Matlab uses column major indexing */
if (grpc_set_client_major("Column") != GRPC_NO_ERROR)
DO_ERROR_MACRO(grpc_errno);
/* Locate request structure */
request = grpc_get_request(sessionID);
if (request == NULL) DO_ERROR_MACRO(grpc_errno);
/* We call gs_wait_common, because we need manipulate a request
handle to extract the output and transfer to matlab before
destroying it. The standard gs_wait assumes that the user
already has pointers to the output data location. Note: This is
not the fault tolerant version of gs_wait */
/* TODO Handle fault tolerant wait */
status = gs_wait_common(request);
if (status != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
/* DBGPRINTF("get output\n"); */
rc = matlab_gs_get_output(request->problem, nlhs, plhs, nrhs, prhs);
if (rc != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
/* Finalize */
DBGPRINTF("Clean up\n");
if (matlab_gs_free_args(request->handle->problem_desc, nlhs, plhs, nrhs, prhs) != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
if (request && request->handle) if (grpc_function_handle_destruct(request->handle) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
if (request && request->handle) request->handle = matlab_gs_free(request->handle);
if (grpc_request_destruct_free_clear(sessionID) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
/* TODO argstack? */
return;
error:
for (i=0;i<nlhs;i++) plhs[i] = mxCreateDoubleMatrix(0,0,mxREAL);
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));
return;
}


1.6.3-20100507