Functions

gs_info.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "idl_export.h"
#include "grpc.h"
#include "idl_request.h"
#include "translate.h"
#include "utility.h"
#include "comm_data.h"
#include "comm_basics.h"
#include "comm_encode.h"
#include "general.h"
Include dependency graph for gs_info.c:

Go to the source code of this file.

Functions

void gs_info (int argc, IDL_VPTR *argv_idl)
void gridsolve (int argc, IDL_VPTR *argv_idl)

Function Documentation

void gridsolve ( int  argc,
IDL_VPTR *  argv_idl 
)

Displays some information about the GridSolve system.

Definition at line 111 of file gs_info.c.

{
  char *agent, *msg, errmsg[512], dottedIP[20], proxy_dottedIP[20],
     cid_string[2 * CID_LEN + 1];
  int i, sock, num_servers, agentport, tag;
  gs_server_t **server_list;
  grpc_error_t retval;

  agent = getenv("GRIDSOLVE_AGENT");

  if(!agent)
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
       "Error: GRIDSOLVE_AGENT not set!");

  /* Initialize GridRPC system */
  retval = grpc_initialize(NULL);
  if((retval != GRPC_NO_ERROR) && (retval != GRPC_ALREADY_INITIALIZED))
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
       "Error: cannot initialize GridSolve!");

  agentport = getenv_int("GRIDSOLVE_AGENT_PORT", GRIDSOLVE_AGENT_PORT_DEFAULT);
  if((sock = gs_connect_direct(agent, agentport)) == INVALID_SOCKET) {
    sprintf(errmsg, "%s cannot be contacted\n", agent);
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, errmsg);
  }

  if((gs_send_tag(sock, GS_PROT_SERVER_LIST) < 0) ||
     (gs_send_string(sock, VERSION) < 0)) {
    sprintf(errmsg, "Cannot communicate with %s\n", agent);
    IDL_Message(IDL_M_GENERIC, IDL_MSG_INFO, errmsg);
    sprintf(errmsg, "Error sending tag GS_PROT_SERVER_LIST\n");
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, errmsg);
  }

  if(gs_recv_tag(sock, &tag) < 0)
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, "Error communicating with agent.");

  if(tag != GS_PROT_OK) {
    if(tag == GS_PROT_VERSION_MISMATCH)
      sprintf(errmsg, "Error: Agent is an incompatible version\n");
    else
      sprintf(errmsg, "Error: Agent refused with code %d\n", tag);
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, errmsg);
  }

  if(gs_recv_int(sock, &num_servers) < 0)
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, "Error communicating with agent.");

  printf("AGENT: %s [%d servers]\n", agent, num_servers);

  if(num_servers <= 0)
    return;

  server_list = (gs_server_t **) CALLOC(num_servers, sizeof(gs_server_t *));
  if(!server_list)
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP,
      "Failed to allocate memory for the server list.");

  for(i=0;i<num_servers;i++) {
    server_list[i] = (gs_server_t *) CALLOC(1,sizeof(gs_server_t));
    if(gs_recv_string(sock, &msg) < 0)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, "Error communicating with agent.");
    if(gs_decode_server(msg, server_list[i]) < 0)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, "Error decoding server information.");
    FREE(msg);
  }

  for(i=0;i<num_servers;i++) {
    proxy_cid_to_str(cid_string, server_list[i]->componentid);
    proxy_ip_to_str(server_list[i]->ipaddress, dottedIP);
    proxy_ip_to_str(server_list[i]->proxyip, proxy_dottedIP);
    if(server_list[i]->proxyip != 0)
      printf("SERVER: %s (%s:%d, proxy=%s:%d) [cid=%s]\n", server_list[i]->hostname, 
        dottedIP, server_list[i]->port, proxy_dottedIP, 
        server_list[i]->proxyport, cid_string);
    else
      printf("SERVER: %s (%s:%d) [cid=%s]\n", server_list[i]->hostname, 
        dottedIP, server_list[i]->port, cid_string);
  }

  return;
}

Here is the call graph for this function:

void gs_info ( int  argc,
IDL_VPTR *  argv_idl 
)

Implementation of the gs_info procedure. This allows the user to get information about a service from the IDL command line.

This is part of the IDL Client for GridSolve. Gets information about a GridSolve service. This includes the number of arguments, data types, dimensions, etc.

Parameters:
argc -- the number of arguments
argv_idl -- the array of IDL arguments passed in. This should contain one argument: the name of the service to look up.
Returns:
an IDL variable containing the GridRPC exit status of the call. See the GridRPC documentation for details.

Definition at line 39 of file gs_info.c.

{
  grpc_function_handle_t *handle;
  char *fname, *nickname;
  grpc_error_t retval;

  /* 
   * Obtain the problem name to be invoked, 
   * and peel off "()" of the name if necessary.
   */
  fname    = IDL_VarGetString(argv_idl[0]);
  nickname = strdup(fname);

  if(!nickname) {
    IDL_Message(IDL_M_GENERIC, IDL_MSG_INFO, "Error: strdup failed!");
    return;
  }

  if(trunc_fname(nickname) < 0) {
    IDL_Message(IDL_M_GENERIC, IDL_MSG_INFO, "Error: invalid problem name!");
    free(nickname);
    return;
  }

  /* Initialize GridRPC system */
  retval = grpc_initialize(NULL);
  if((retval != GRPC_NO_ERROR) && (retval != GRPC_ALREADY_INITIALIZED)) {
    IDL_Message(IDL_M_GENERIC, IDL_MSG_INFO, "Error: cannot initialize!");
    return;
  }

  /* Create its GridRPC handle */
  handle = (grpc_function_handle_t *)malloc(sizeof(grpc_function_handle_t));

  if(!handle) {
    IDL_Message(IDL_M_GENERIC, IDL_MSG_INFO, "Error: malloc failed!");
    free(nickname);
    return;
  }

  IDL_TimerBlock(IDL_TRUE);
  retval = grpc_function_handle_default(handle, nickname);
  IDL_TimerBlock(IDL_FALSE);

  free(nickname);

  if(retval != GRPC_NO_ERROR) {
    IDL_Message(IDL_M_GENERIC,IDL_MSG_INFO, "Unknown problem.");
    free(handle);
    return;
  }

  if(!handle->problem_desc) {
    IDL_Message(IDL_M_GENERIC, IDL_MSG_INFO, "Error: bad problem desc!");
    grpc_function_handle_destruct(handle);
    free(handle);
    return;
  }

  gs_problem_dump(handle->problem_desc);

  grpc_function_handle_destruct(handle);
  free(handle);

  return;
}

Here is the call graph for this function: