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 47 insertions and 40 deletions:
0 comments (0 inline, 0 general)
src/server/slave.c
Show inline comments
 
@@ -29,18 +29,14 @@
 
#include <stdlib.h>
 
#include <string.h>
 
#include <sys/stat.h>
 
#include <unistd.h>
 

	
 

	
 

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

	
 
  int tmp;
 

	
 
  char *datadir;
 
  char *server;
 
  char *username;
 
  char *hostname;
 
  cfg_opt_t myopts[] = {
 
@@ -62,12 +58,13 @@ int main(int argc, char *argv[])
 
     initializations
 
  */
 
  datadir = NULL;
 
  server = NULL;
 
  username = NULL;
 

	
 
  char curopt;
 

	
 
  while(((char)-1) != (curopt = getopt(argc, argv, "u:h")))
 
     {
 
       if(curopt == ':')
 
         {
 
           fprintf(stderr, "-%c: is missing an argument\n", optopt);
 
@@ -93,37 +90,17 @@ int main(int argc, char *argv[])
 

	
 
  /* Get conf data */
 
  options_init(argc, argv, &my_cfg, myopts, "slave", &commonopts);
 

	
 

	
 
  /* 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;
 
    }
 

	
 

	
 
@@ -138,14 +115,12 @@ int main(int argc, char *argv[])
 
  char *pathtoOutput;  /* Full path to the output (rendered) file */
 

	
 
  char *pathtoJobfile; /* Full path to the job's main file */
 
  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;
 

	
 
  // Main loop
 
  while(!quit)
 
    {
 
@@ -154,28 +129,20 @@ int main(int argc, char *argv[])
 
    fprintf(stderr,"Requesting work...\n");
 
    sendSignal(comm_slave, DISTREN_REQUEST_GETWORK);
 

	
 
    /* 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 */
 

	
 
        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;
 

	
 
        unpackJob(pathtoTar, jobnum);
 

	
 
@@ -222,22 +189,22 @@ int main(int argc, char *argv[])
 
        sendExtSignal(comm_slave, DISTREN_REQUEST_DONEFRAME, jobFrame);
 
	free(jobFrame);
 
      }
 
    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,
 
        // except for ones that couldn't be uploaded
 
        delete_jobdata(jobnum, datadir);
 
      }
 

	
 
    sleep(5); // Poll 5 seconds. @TODO: Remove all polling
 
  }
 

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

	
 
  fprintf(stderr,"Goodbye!\n");
 
  return 0;
 
}
src/server/slavefuncs.c
Show inline comments
 
@@ -400,6 +400,44 @@ int unpackJob(char *pathtoTar, int jobnu
 
  system(tarcmd);
 
  free(tarcmd);
 
  free(pathtoTar);
 
  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
 
@@ -46,8 +46,10 @@ void xmlinit();
 
void xmlcleanup();
 
int distren_mkdir_recurse(char *dirname);
 
int job_build_path(char *filename, unsigned int jobnum);
 
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)