Functions

gs_probdesc.c File Reference

#include "utility.h"
#include <stdlib.h>
#include <string.h>
#include "comm_data.h"
#include "comm_basics.h"
#include "comm_encode.h"
#include "general.h"
Include dependency graph for gs_probdesc.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Detailed Description

This program will print a detailed description of the specified problem. The usage is: GS_probdesc <agent name>=""> <problem name>="">

Definition in file gs_probdesc.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Entry point for GS_probdesc.

Parameters:
argc -- arg count
argv -- array of command line args
Returns:
EXIT_SUCCESS on success, EXIT_FAILURE on error.

Definition at line 32 of file gs_probdesc.c.

{
  gs_problem_t *problem = NULL;
  int sock, agentport, tag;
  char *msg = NULL;

  if(argc < 3) {
    fprintf(stderr,"Usage: GS_probdesc <agent name> <problem name>\n");
    exit(EXIT_FAILURE);
  }

  initialize_sockets();

  agentport = getenv_int("GRIDSOLVE_AGENT_PORT", GRIDSOLVE_AGENT_PORT_DEFAULT);
  if((sock = gs_connect_direct(argv[1], agentport)) == INVALID_SOCKET) {
    fprintf(stderr,"%s cannot be contacted\n", argv[1]);
    exit(EXIT_FAILURE);
  }

  if((gs_send_tag(sock, GS_PROT_PROBLEM_DESC) < 0) ||
     (gs_send_string(sock, VERSION) < 0)) {
    fprintf(stderr,"Cannot communicate with %s\n", argv[1]);
    fprintf(stderr,"Error sending tag GS_PROT_PROBLEM_DESC\n");
    exit(EXIT_FAILURE);
  }

  if(gs_recv_tag(sock, &tag) < 0) {
    fprintf(stderr,"Error communicating with agent.\n");
    exit(EXIT_FAILURE);
  }

  if(tag != GS_PROT_OK) {
    if(tag == GS_PROT_VERSION_MISMATCH)
      fprintf(stderr, "Error: Agent is an incompatible version\n");
    else
      fprintf(stderr, "Error: Agent refused with code %d\n", tag);
    exit(EXIT_FAILURE);
  }

  if(gs_send_string(sock, argv[2]) < 0) {
    fprintf(stderr,"Cannot communicate with %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }

  if(gs_recv_string(sock, &msg) < 0) {
    fprintf(stderr,"Error communicating with agent.\n");
    exit(EXIT_FAILURE);
  }

  if(!strcmp(msg, "not found")) {
    fprintf(stderr,"Problem '%s' was not found.\n", argv[2]);
    exit(EXIT_FAILURE);
  }

  problem = (gs_problem_t *) CALLOC(1, sizeof(gs_problem_t));

  if(!problem) {
    fprintf(stderr,"Failed to allocate problem struct\n");
    return -1;
  }

  if(gs_decode_problem(msg, problem) < 0) {
    fprintf(stderr,"Error encoding problem description.\n");
    exit(EXIT_FAILURE);
  }

  gs_problem_dump(problem);

  cleanup_sockets();

  return 0;
}

Here is the call graph for this function: