Changeset - 257ea2fc6baf
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 15 years ago 2010-07-22 21:34:58
ohnobinki@ohnopublishing.net
Fixed up the client's main() function which yet doesn't get anything done ;-).
3 files changed with 142 insertions and 74 deletions:
0 comments (0 inline, 0 general)
src/client/distren.c
Show inline comments
 
@@ -39,13 +39,17 @@
 
#include <confuse.h>
 
#include <string.h> // for strcat
 

	
 
int main_opt_set(const char *name, char **dst, const char *src);
 

	
 
int main(int argc, char *argv[])
 
{
 
  int doLogin = 0;
 
  short dologin;
 
  short printinfo;
 
  short lazy;
 

	
 
  char *input;
 
  char *output;
 
  char *jobid;
 
  char *joburi;
 

	
 
  char *username;
 
  char *password;
 
@@ -55,106 +59,170 @@ int main(int argc, char *argv[])
 
  distren_t distren;
 
  distren_job_t distren_job;
 

	
 
  dologin = 0;
 
  printinfo = 0;
 
  lazy = 1;
 

	
 
  input = NULL;
 
  output = NULL;
 
  joburi = NULL;
 

	
 
  while(-1 != (curopt = getopt(argc, argv, "i:o:u:p:h")))
 
  while(-1 != (curopt = getopt(argc, argv, "di:j:o:u:p:h")))
 
    {
 
      if(curopt == ':')
 
      switch(curopt)
 
	{
 
	case ':':
 
	  fprintf(stderr, "-%c: is missing an argument\n", optopt);
 
	  return 1;
 
	}
 
      else if(curopt == '?')
 
	{
 

	
 
	case '?':
 
	  fprintf(stderr, "-%c: invalid option specified\n", optopt);
 
	  return 1;
 
	}
 
      else if(curopt == 'h')
 
	{
 
	  fprintf(stderr, "Usage: %s -i <inputfile> -o <outputfile> [ -u <username> -p <password> ]\n", argv[0]);
 
	  fprintf(stderr, "\t-i\tSpecifies the input file\n\
 
\t-o\tSpecifies the output file\n\
 
\t-h\tShows this help message\n");
 

	
 
	case 'h':
 
	  fprintf(stderr, "Usage: %s [-u <username>] [-p <password>] ...\n", argv[0]);
 
	  fprintf(stderr, "\t-i\tSpecifies an input file to submit to the server.\n\
 
\t-o\tSpecifies the name that should be given to a job retrieved from the server.\n\
 
\t-j\tSpecifies the job handle of a job to view information about or retrieve.\n\
 
\t-d\tDisplays information about the job specified with -j or uploaded by -i.\n\
 
\t-h\tShows this help message.\n");
 
	  
 
	  //  don't return here because options_init will have an overall
 
	  //  options help page
 
	  
 
	  /*
 
	   * don't return here because options_init will have an
 
	   * overall options help page
 
	   */
 
	  break;
 

	
 
	case 'u':
 
	  main_opt_set("-u", &username, optarg);
 
	  dologin = 1;
 
	  break;
 

	
 
	case 'p':
 
	  main_opt_set("-p", &password, optarg);
 
	  dologin = 1;
 
	  break;
 

	
 
	case 'i':
 
	  if(joburi)
 
	    {
 
	      fprintf(stderr, "You may not specify both -i and -j; -j must refer to an existing job URL and -i will create a new job and thus retrieve its URL.\n");
 
	      return 1;
 
	    }
 
	  main_opt_set("-i", &input, optarg);
 
	  break;
 

	
 
	case 'o':
 
	  main_opt_set("-o", &output, optarg);
 
	  break;
 

	
 
	case 'j':
 
	  if(input)
 
	    {
 
	      fprintf(stderr, "You may not specify both -j and -i; -i is submitting a new jobs whose URL cannot be known before it is submitted\n");
 
	      return 1;
 
	    }
 
	  main_opt_set("-j", &joburi, optarg);
 
	  break;
 

	
 
	case 'd':
 
	  printinfo = 1;
 
	  break;
 
	}
 
      else if(curopt == 'u') {
 
        doLogin = 1;
 
        username = strdup(optarg);
 
      }
 
      else if(curopt == 'p') {
 
        doLogin = 1;
 
        password = strdup(optarg);
 
      }
 
      else if(curopt == 'i')
 
	
 
	 //  TODO: is strdup good or bad? what about
 
	 //  the idea that all libs should allow plugging different
 
	 //  malloc/free implementations in?
 
	 
 
	input = strdup(optarg);
 
      else if(curopt == 'o')
 
	output = strdup(optarg);
 
    }
 

	
 
  
 
     // give this error after the general arguments parsing so that
 
     // the general help from options_init can have effect
 
  if(!username || !password){
 
    fprintf(stderr, "Username and password must be specified");
 
    return 1;
 
  }
 
  if(doLogin == 1){
 
    fprintf(stderr, "Trying username and password on server...");
 
    return 0;
 
  }
 
  if(!input
 
     || !output)
 
  if(!username || !password)
 
    {
 
      fprintf(stderr, "Input and output files must be specified\n");
 
      fprintf(stderr, "Username and password must be specified:\n");
 
      if(!username)
 
	fprintf(stderr, "\tyou did not specify a username\n");
 
      if(!password)
 
	fprintf(stderr, "\tyou did not specify a password\n");
 
      return 1;
 
    }
 

	
 
  fprintf(stderr, "reading from %s\nwriting to %s\n", input, output);
 
  if(dologin)
 
    {
 
      fprintf(stderr, "Trying username and password on server...");
 
      fprintf(stderr, "STUB\n");
 
      lazy = 0;
 
    }
 

	
 
  if(distren_init_mf(&distren, &malloc, &free))
 
    {
 
      fprintf(stderr, "error initializing distren handle\n");
 
      fprintf(stderr, "error initializing the distren handle\n");
 
      return 1;
 
    }
 

	
 
  if(distren_submit_file(distren, &distren_job, input))
 
  if(input)
 
    {
 
      fprintf(stderr, "error submitting file\n");
 
      return 1;
 
      if(distren_submit_file(distren, &distren_job, input))
 
	{
 
	  fprintf(stderr, "error submitting file\n");
 
	  return 1;
 
	}
 

	
 
      if(distren_job_geturi(distren_job, &joburi))
 
	{
 
	  fprintf(stderr, "error retrieving joburi\n");
 
	  return 1;
 
	}
 

	
 
      lazy = 0;
 
      fprintf(stdout, "joburi: %s\n", joburi);
 
    }
 

	
 
  if(output)
 
    {
 
      if(distren_job_retrieve_file(distren_job, output))
 
	{
 
	  fprintf(stderr, "error retrieving output file\n");
 
	  return 1;
 
	}
 

	
 
      lazy = 0;
 
    }
 

	
 
  if(distren_job_getid(distren_job, &jobid))
 
  /*
 
   * if these following lines fail, it'll be reported as a core dump
 
   * ;-)
 
   */
 
  if(distren_job)
 
    distren_job_free(distren_job);
 

	
 
  distren_free(distren);
 

	
 
  if(lazy)
 
    fprintf(stderr, "Performed no action\n");
 

	
 
  return 0;
 
};
 

	
 
  /**
 
   * A helper for main() that will print a warning about overriding
 
   * specifying an argument multiple times and properly handle options
 
   * overriding eachother.
 
   *
 
   * Before calling main_opt_set() for the first time, the caller must
 
   * preset *dst to NULL.
 
   *
 
   * @param name something to identify the particular option to the user.
 
   * @param dst the poiner to where a newly allocated string's pointer should be stored.
 
   * @param src the value specified by the user.
 
   */
 
int main_opt_set(const char *name, char **dst, const char *src)
 
{
 
  if(*dst)
 
    {
 
      fprintf(stderr, "error retrieving job id\n");
 
      return 1;
 
    }
 
  fprintf(stdout, "jobid: %s\n", jobid);
 

	
 
  if(distren_job_retrieve_file(distren_job, output))
 
    {
 
      fprintf(stderr, "error retrieving output file\n");
 
      return 1;
 
      fprintf(stderr, "warning: You have specified %s before, setting it to %s\n", name, src);
 
      free(*dst);
 
    }
 

	
 
  // if these following lines fail, it'll be reported as a core dump ;-)
 
  distren_job_free(distren_job);
 
  distren_free(distren);
 
  *dst = strdup(src);
 
  return 0;
 
}
 

	
 

	
 

	
 
 return 0;
 
};
 

	
 

	
 

	
 

	
 

	
src/client/distren.h
Show inline comments
 
@@ -58,7 +58,7 @@ int distren_submit_file(distren_t handle
 
   @param jobid This will be set to a string allocated by the specified malloc implementation
 
   @param job The distren_job_t from which to retrieve a jobid
 
*/
 
int distren_job_getid(distren_job_t job, char **jobid);
 
int distren_job_geturi(distren_job_t job, char **joburi);
 

	
 
/**
 
   Retrieves a tarball of a rendering's result.
 
@@ -69,7 +69,7 @@ int distren_job_retrieve_file(distren_jo
 
/*
 
 TODO: extraction of a job-ID, retrieving job handle by job-ID, getting information
 
 for a job handle, retrieving results of a job, callbacks for progress (i.e., job_is_finished callback)
 
 -- threads?
 
 -- threads? -- noooo!
 
*/
 

	
 
/**
src/client/libdistren_job.c
Show inline comments
 
@@ -28,7 +28,7 @@
 
/**
 
   @todo Stub
 
 */
 
int distren_job_getid(distren_job_t job, char **jobid)
 
int distren_job_geturi(distren_job_t job, char **joburi)
 
{
 
  return 1;
 
}
0 comments (0 inline, 0 general)