Changeset - 536058b6e341
[Not reviewed]
default
0 2 0
Ethan Zonca (ethanzonca) - 15 years ago 2010-05-29 13:36:52
e@ethanzonca.com
Fixed the recalc process to remove interaction, need to add php hook on server for getting render_power
2 files changed with 18 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/server/simpleslave.c
Show inline comments
 
@@ -53,50 +53,53 @@ int main(int argc, char *argv[])
 
  struct options_common *commonopts;
 

	
 
  /**
 
     initializations
 
  */
 
  datadir = NULL;
 
  server = NULL;
 
  username = NULL;
 
  password = NULL;
 
  hostname = NULL;
 

	
 
  char curopt;
 
  int runBenchmark = 0;
 

	
 
  while(((char)-1) != (curopt = getopt(argc, argv, "u:th")))
 
  while(((char)-1) != (curopt = getopt(argc, argv, "u:rh")))
 
     {
 
       if(curopt == ':')
 
         {
 
           fprintf(stderr, "-%c: is missing an argument\n", optopt);
 
           return 1;
 
         }
 
       else if(curopt == '?')
 
         {
 
           fprintf(stderr, "-%c: invalid option specified\n", optopt);
 
           return 1;
 
         }
 
       else if(curopt == 'h')
 
         {
 
           fprintf(stderr, "Usage: distrenslave [option] \nStarts a distren slave\n\t-u\tset username (run after fresh install)\n\t-t\tEnter test mode\n\t-h\tshow this help\n");
 
           fprintf(stderr, "Usage: distrenslave [option] \nStarts a distren slave\n\t-u\tset username (run after fresh install)\n\t-r\tRecalculate render power (benchmark)\n\t-h\tshow this help\n");
 
           return 2;
 
         }
 
       else if(curopt == 't')
 
       else if(curopt == 'r')
 
         {
 
           slaveTest();
 
           return 0;
 
           runBenchmark = 1;
 
           break;
 
         }
 
       else if(curopt == 'u')
 
         username = strdup(optarg);
 
         fprintf(stderr, "Putting username \"%s\" in distrenslave.conf\n", username);
 
         if(DEBUG)
 
           fprintf(stderr, "Putting username \"%s\" in distrenslave.conf\n", username);
 

	
 
         conf_replace("distrenslave.conf", "!username", username);
 
         fprintf(stderr, "Please invoke distrenslave with no arguments to run with the username you just set\n");
 
         return 0;
 
     }
 

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

	
 
  if(!datadir)
 
    {
 
      fprintf(stderr, "datadir not set\n");
 
      return 1;
 
@@ -114,31 +117,30 @@ int main(int argc, char *argv[])
 
  if(!password)
 
    {
 
      fprintf(stderr, "password not set\n");
 
      return 1;
 
    }
 
  if(!hostname)
 
    {
 
      fprintf(stderr, "hostname not set\n");
 
      return 1;
 
    }
 

	
 
  
 

	
 
  /* Notifies the user if there no username in .conf */
 
  if(checkUsername(username))
 
    return 1;
 
  if(!strncmp(password, "!password",10))
 
    {
 
      fprintf(stderr, "You haven't specified a password. Please edit your distrenslave.conf file appropriately\n");
 
      fprintf(stderr, "You haven't specified a password. Please edit distrenslave.conf!\n");
 
      return 1;
 
    }
 

	
 
  // Variables needed for main loop
 
  int jobnum = 0;
 
  int framenum = 0;
 
  int slavekey = atoi(username); // @TODO: Make this more friendly
 

	
 
  char *urltoTar;      /* Full URL to the server-side location of job#.tgz */
 
  char *pathtoTar;     /* Full path to the location of the job#.tgz */
 
  char *pathtoTardir;
 

	
 
@@ -148,46 +150,46 @@ int main(int argc, char *argv[])
 
  char *urltoOutput;   /* Full URL where output is posted */
 
  char *pathtoOutput;  /* Full path to the output (rendered) file */
 
  char *pathtoOutdir;  /* Full path to output directory */
 
  char *pathtoRenderOutput; /* Contains blender framenum placeholder */
 

	
 
  char *pathtoJob; /* Path to job data folder */
 
  char *pathtoJobfile; /* Full path to the job's main file */
 
  char *outputExt = "jpg";     /* Output Extension (e.g., JPG) */
 

	
 
  int haveWork = 0;
 
  int quit = 0;
 

	
 
  fprintf(stderr,"DistRenSimpleSlave Pre-Alpha\n\t- this version of DistRen is still experimental\n\t  so things might go horribly wrong!\n");
 
  fprintf(stderr,"\nDistRen SimpleSlave Pre-Alpha %s\n- Experimental build: Use at your own risk!\n\n", PACKAGE_VERSION);
 

	
 
  int benchmarkTime = 0;
 
  int renderPower = 0;
 

	
 
  char option[1] = "";
 
  fprintf(stderr,"Do you want to recalculate render power? (y/n): ");
 
  scanf("%s", option);
 
  if(!strcmp(option, "y"))
 
  // @TODO: create _web function to force recalc if !isset($render_power) on server
 
  if(runBenchmark)
 
    {
 
      if(slaveBenchmark(datadir, &benchmarkTime, &renderPower))
 
	{
 
	  fprintf(stderr,"Benchmark failed! Exiting.\n");
 
	  return 1;
 
	}
 
      else
 
	{
 
	  fprintf(stderr,"Benchmark successful, time taken was %d seconds, giving you a render power of %d.\n",
 
		  benchmarkTime, renderPower);
 
	  _web_setrenderpower(slavekey, password, renderPower);
 
	  return 0;
 
	}
 
    }
 

	
 
  if(!DEBUG)
 
    fprintf(stderr, "Running..");
 
  // Main loop
 
  while(!quit)
 
    {
 

	
 
    // request work
 
    if(DEBUG)
 
      fprintf(stderr,"Requesting work from %s...\n", hostname);
 
    haveWork = _web_getwork(slavekey, password, &jobnum, &framenum);
 

	
 
    /* If we got a frame */
src/server/slavefuncs.c
Show inline comments
 
@@ -529,25 +529,25 @@ void prepareJobPaths(int jobnum, int fra
 
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 1;
 
   }
 
   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");
 
           // Logged in OK
 
           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;
 
@@ -718,25 +718,26 @@ void _web_resetframe(int slavekey, char 
 
  fprintf(stderr,"Resetting frame %d in job %d on server... ",framenum,jobnum);
 
  char *url;
 
  _distren_asprintf(&url,"http://dev.distren.org/slave/act.php?mode=resetframe&slavekey=%d&slavepass=%s&jobnum=%d&framenum=%d", slavekey, slavepass, jobnum, framenum);
 
  struct _web_memorystruct data = _web_getrequest(url);
 
  free(url);
 

	
 
  fprintf(stderr,"%s\n", data.memory);
 
  if(data.memory)
 
    free(data.memory);
 
}
 

	
 
void _web_startframe(int slavekey, char *slavepass, int jobnum, int framenum){
 
  fprintf(stderr,"Marking frame %d started on server... ",framenum);
 
  if(DEBUG)
 
    fprintf(stderr,"Marking frame %d started on server... ",framenum);
 
  char *url;
 
  _distren_asprintf(&url,"http://dev.distren.org/slave/act.php?mode=startframe&slavekey=%d&slavepass=%s&jobnum=%d&framenum=%d", slavekey, slavepass, jobnum, framenum);
 
  struct _web_memorystruct data = _web_getrequest(url);
 
  free(url);
 

	
 
  fprintf(stderr,"%s\n", data.memory);
 
  if(data.memory)
 
    free(data.memory);
 
}
 

	
 
int _web_getwork(int slavekey, char *slavepass, int *jobnum, int *framenum){
 
  char *url;
0 comments (0 inline, 0 general)