#include <oct.h>#include <stdio.h>#include <stdlib.h>#include "grpc.h"#include "gs_oct.h"
Go to the source code of this file.
Functions | |
| DEFUN_DLD (gs_wait, args, nargout,"Octave client for GridSolve") | |
| DEFUN_DLD | ( | gs_wait | , | |
| args | , | |||
| nargout | , | |||
| "Octave client for GridSolve" | ||||
| ) |
Definition at line 22 of file gs_wait.cpp.
{
octave_value_list retvals; //return value
octave_value_list bad_retval; //bad return value
grpc_function_handle_t *handle; //GridRPC function handle
grpc_error_t status; //GridRPC status/error code
grpc_sessionid_t req_id; //GridRPC non-blocking call session id
//meaningless return value for error condition
//or those calls that do not make grpc function call
for (int i = 0; i < nargout; i++) {
bad_retval(i) = Matrix(0, 0);
}
//number of input arguments
int nargin = args.length();
if (nargin <= 0) {
fprintf(stderr, "No input service name found. Aborted.\n");
return bad_retval;
}
if (nargin > 1) {
fprintf(stderr, "Exactly one argument (session id) is expected. Aborted.\n");
return bad_retval;
}
//otherwise, the input is correct
//initialize the GridSolve environment
status = grpc_initialize(NULL);
if (status != GRPC_NO_ERROR && status != GRPC_ALREADY_INITIALIZED) {
fprintf(stderr, "%s\n", grpc_error_string(status));
return bad_retval;
}
req_id = args(0).int_value();
//get the GRPC handle
status = grpc_get_handle(&handle, req_id);
if (status != GRPC_NO_ERROR) {
fprintf(stderr, "Failed to get the GRPC handle. Aborted.\n");
return bad_retval;
}
status = grpc_wait(req_id);
if (status != GRPC_NO_ERROR) {
fprintf(stderr, "%s\n", grpc_error_string(status));
return bad_retval;
}
//the job completed
retvals = octave_value_list();
//convert object back
if (convert_output_objects(handle->problem_desc, retvals) < 0) {
fprintf(stderr, "Failed to convert output arguments. Aborted.\n");
grpc_function_handle_destruct(handle);
if (handle != NULL) free(handle);
grpc_finalize();
return bad_retval;
}
//finalize and clean up
grpc_function_handle_destruct(handle);
if (handle != NULL) free(handle);
grpc_finalize();
return retvals;
}

1.6.3-20100507