Changeset - 2d6b6ba3b549
[Not reviewed]
default
0 3 0
Ethan Zonca (ethanzonca) - 16 years ago 2010-02-20 01:09:22
e@ethanzonca.com
Abstraction, cleanup, warning fixes
3 files changed with 48 insertions and 41 deletions:
0 comments (0 inline, 0 general)
src/server/slave.c
Show inline comments
 
@@ -32,12 +32,8 @@
 
#include <unistd.h>
 

	
 

	
 

	
 
int main(int argc, char *argv[])
 
{
 
  char curopt;
 

	
 
  int tmp;
 

	
 
  char *datadir;
 
  char *server;
 
@@ -65,6 +61,7 @@ int main(int argc, char *argv[])
 
  server = NULL;
 
  username = NULL;
 

	
 
  char curopt;
 

	
 
  while(((char)-1) != (curopt = getopt(argc, argv, "u:h")))
 
     {
 
@@ -96,31 +93,11 @@ int main(int argc, char *argv[])
 

	
 

	
 
  /* Notifies the user if there no username in .conf */
 
  if(username == NULL || strcmp(username, "!username") == 0 ) {
 
    fprintf(stderr, "\nPlease ensure that your username is present in distrenslave.conf\n");
 
    return 0;
 
  }
 
  else
 
    if( username != NULL || strcmp(username, "!username") != 0 )
 
      {
 
	// Log in the user
 
	if(login_user(username) == 1){
 
	  fprintf(stderr, "You should now be logged into distren.\n");
 
	}
 
	else
 
	  {
 
	    fprintf(stderr, "Login failed, please check your username. If you have not registered, please do so on the DistRen website.\n");
 
	    return 0;
 
	  }
 
      }
 
    else
 
      {
 
	fprintf(stderr, "Please check your distrenslave.conf, it appears to be incorrectly formatted.\n");
 
      }
 
  if(checkUsername(username))
 
    return 1;
 

	
 
  fprintf(stderr, "Connecting to server...\n");
 
  tmp = remoteio_open(&comm_slave, commonopts->remoteio, server);
 
  if(tmp)
 
  if(remoteio_open(&comm_slave, commonopts->remoteio, server))
 
    {
 
      fprintf(stderr, "Error connecting to server; exiting\n");
 
      return 1;
 
@@ -141,8 +118,6 @@ int main(int argc, char *argv[])
 
  char *pathtoXml;     /* Full path to the job's xml file */
 
  char *outputExt;     /* Output Extension (e.g., JPG) */
 

	
 
  char *jobdatapath;   /* Path to job data */
 

	
 
  int haveWork = 0;
 
  int quit = 0;
 

	
 
@@ -157,22 +132,14 @@ int main(int argc, char *argv[])
 
    /* If we got a frame */
 
    if(haveWork)
 
      {
 

	
 
        fprintf(stderr,"Got work from server...\n");
 
        /* @TODO: Add remotio hooks */
 
        // jobnum = remoteio_read(jobnum); /* Set jobnum from remoteio (we could use info from struct, but we need this info to download the xmlfile */
 
        //framenum = remoteio_read(jobnum); /* Set framenum from remoteio */
 
        // framenum = remoteio_read(jobnum); /* Set framenum from remoteio */
 

	
 
        fprintf(stderr, "Preparing to render frame %d in job %d\n", framenum, jobnum);
 

	
 
        // Variable Preparation
 
        _distren_asprintf(&jobdatapath, "job%d", jobnum);
 
        _distren_asprintf(&urltoTar, "http://data.distren.org/job%d/job%d.tar.gz", jobnum); // Prepares URL to download from
 
        _distren_asprintf(&pathtoTar, "%s/stor/jobdata/job%d.tar.gz", datadir, jobnum); // Prepares destination to save to
 
        _distren_asprintf(&pathtoJobfile, "%s/%s/job.blend", datadir, jobdatapath ); // Prepares the path to the jobfile
 
        _distren_asprintf(&urltoOutput, "http://data.distren.org/tmp/", jobdatapath ); // Prepares the URL where output is posted
 
        _distren_asprintf(&pathtoXml, "%s/job%d/job%d.xml", datadir, jobnum ); // Prepares the path to the job's XML file
 
        free(jobdatapath);
 
        prepareJobPaths(jobnum, datadir, &urltoTar, &pathtoTar, &pathtoJobfile, &urltoOutput, &pathtoXml);
 

	
 
        if(downloadTar(urltoTar, pathtoTar))
 
          return 1;
 
@@ -225,7 +192,7 @@ int main(int argc, char *argv[])
 
    else
 
      fprintf(stderr,"Nothing to do. Idling...\n");
 

	
 
    // If the server says that every frame for the last jobnum is finished, OR if the data is getting old
 
    // @TODO: If the server says that every frame for the last jobnum is finished, OR if the data is getting old
 
    if(1 == 0)
 
      {
 
        // Note: individual frames are already deleted after uploading,
 
@@ -238,6 +205,6 @@ int main(int argc, char *argv[])
 

	
 
  fprintf(stderr,"Closing connection to server...\n");
 
  remoteio_close(comm_slave);
 

	
 
  fprintf(stderr,"Goodbye!\n");
 
  return 0;
 
}
src/server/slavefuncs.c
Show inline comments
 
@@ -403,3 +403,41 @@ int unpackJob(char *pathtoTar, int jobnu
 
  free(outdir);
 
  return 0;
 
}
 

	
 
void prepareJobPaths(int jobnum,char *datadir, char **urltoTar,char **pathtoTar,char **pathtoJobfile,char **urltoOutput,char **pathtoXml){
 
  // Variable Preparation
 
  char *jobdatapath;
 
   _distren_asprintf(&jobdatapath, "job%d", jobnum);
 
   _distren_asprintf(urltoTar, "http://data.distren.org/job%d/job%d.tar.gz", jobnum); // Prepares URL to download from
 
   _distren_asprintf(pathtoTar, "%s/stor/jobdata/job%d.tar.gz", datadir, jobnum); // Prepares destination to save to
 
   _distren_asprintf(pathtoJobfile, "%s/%s/job.blend", datadir, jobdatapath ); // Prepares the path to the jobfile
 
   _distren_asprintf(urltoOutput, "http://data.distren.org/tmp/", jobdatapath ); // Prepares the URL where output is posted
 
   _distren_asprintf(pathtoXml, "%s/job%d/job%d.xml", datadir, jobnum ); // Prepares the path to the job's XML file
 
   free(jobdatapath);
 
}
 

	
 
int checkUsername(char *username){
 
  if(username == NULL || strcmp(username, "!username") == 0 ) {
 
     fprintf(stderr, "\nPlease ensure that your username is present in distrenslave.conf\n");
 
     return 0;
 
   }
 
   else
 
     if( username != NULL || strcmp(username, "!username") != 0 )
 
       {
 
         // Log in the user
 
         if(login_user(username) == 1){
 
           fprintf(stderr, "You should now be logged into distren.\n");
 
           return 0;
 
         }
 
         else
 
           {
 
             fprintf(stderr, "Login failed, please check your username. If you have not registered, please do so on the DistRen website.\n");
 
             return 1;
 
           }
 
       }
 
     else
 
       {
 
         fprintf(stderr, "Please check your distrenslave.conf, it appears to be incorrectly formatted.\n");
 
         return 1;
 
       }
 
}
src/server/slavefuncs.h
Show inline comments
 
@@ -49,5 +49,7 @@ int job_build_path(char *filename, unsig
 
int downloadTar(char *url, char *destinationPath);
 
int uploadOutput(char *pathtoOutput, char *urltoOutput);
 
int unpackJob(char *pathtoTar, int jobnum);
 
void prepareJobPaths(int jobnum,char *datadir, char **urltoTar,char **pathtoTar,char **pathtoJobfile,char **urltoOutput,char **pathtoXml);
 
int checkUsername(char *username);
 

	
 
#endif
0 comments (0 inline, 0 general)