Changeset - 18e6f04a1092
[Not reviewed]
default
0 1 0
LordOfWar - 16 years ago 2009-10-01 00:51:50

-created printAllJobnums() functions to... print all the job numbers in the queue in the order they will be processed
-added printAllJobnums to user interface
1 file changed with 19 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -440,96 +440,112 @@ int distrend_config_free(struct distrend
 
/* ************************** Test Functions ************************* */
 
void printFrameInfo(struct frameset *frame)
 
{
 
  char *status = "";
 

	
 
  switch(frame->status)
 
  {
 
    case FRAMESETSTATUS_UNASSIGNED:
 
      _distren_asprintf(&status, "%s", "unassigned");
 
      break;
 
    case FRAMESETSTATUS_ASSIGNED:
 
      _distren_asprintf(&status, "%s", "assigned");
 
      break;
 
    case FRAMESETSTATUS_DONE:
 
      _distren_asprintf(&status, "%s", "completed");
 
      break;
 
    case FRAMESETSTATUS_CANCELED:
 
      _distren_asprintf(&status, "%s", "canceled");
 
  }
 

	
 
  printf("frame #: %d --> %s", frame->num, status);
 
}
 

	
 
void printJob(struct distrenjob *job)
 
{
 
  int counter;
 
  printf("frame_num: status");
 
  for(counter = 0; counter < job->total_frames; counter++)
 
    {
 
      printFrameInfo(&job->frameset[counter]);
 
    }
 
}
 

	
 
void printJobInfo(struct distrenjob *job)
 
{
 
  printf("type: %d", job->type);
 
  printf("name: %s", job->email);
 
  printf("submitter: %s", job->submitter);
 
  printf("e-mail: %s", job->email);
 
  printf("priority, %d", job->priority);
 
  printf("completed: %d", job->completed_frames);
 
  printf("assigned: %d", job->assigned_frames);
 
  printf("total: %d", job->total_frames);
 
  printf("watchdog: %d", job->watchdog_forgiveness);
 
  printf("hibernate: %d", job->hibernate);
 
  printf("prev_frame: %d", job->prev_frame_index);
 
}
 

	
 
void printAllJobnums(struct distrenjob *head)
 
{
 
  struct distrenjob *current_job;
 
  int total_jobs;
 
  printf("job numbers in the order they will be processed:");
 

	
 
  total_jobs = 0;
 
  for(current_job = head; !current_job; current_job = current_job->next)
 
    {
 
      printf("%d", current_job->jobnum);
 
      total_jobs++;
 
    }
 

	
 
  printf("%d jobs in queue", total_jobs);
 
}
 

	
 
/* ************************** Main ************************* */
 

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

	
 
  /* Argument-parser */
 
  int counter = 0;
 
  int test = 0; // Have some fun if-ness that does fun stuff when this is 1
 
  int die = 0;
 

	
 
  for(counter=0; counter<argc; counter++){
 
         if(strcmp(argv[counter], "-h") == 0) {
 
           fprintf(stderr, "Usage: distrend [option] \nStarts the distrend server\n\t-h\tshow this help\n\t-t\tlaunches queue testing interface \n");
 
           return 2;
 
          }
 

	
 
          else if(strcmp(argv[counter], "-t") == 0) {
 
            fprintf(stderr, "Entering into test mode...\n\n");
 
            test=1;
 
          }
 
          else{
 
            fprintf(stderr, "Please enter some compatible args (see -h), or invoke with no args.\n\n");
 
            die=1;
 
          }
 
  }
 
  if(die==1){
 
    return 3;
 
  }
 

	
 
  struct distrenjob head;
 
  head.priority = 0; // make head have the highest priority
 

	
 
  int cont;
 
  struct distrend_listenset *listenset;
 
  struct distrend_config *config;
 

	
 
  enum clientstatus
 
  {
 
    CLIENTSTATUS_UNINITIALIZED = 0,
 
    CLIENTSTATUS_BUSY = 1,
 
    CLIENTSTATUS_IDLE = 2
 
  } clientstatus;
 

	
 
  cont = 1;
 
  memset(&head, '\0', sizeof(struct distrenjob));
 

	
 
  start_data(); // Starts fresh or loads data from xml dump. Should we grab the return?
 

	
 
@@ -545,98 +561,101 @@ int main(int argc, char *argv[])
 
  char *email = "";
 
  int priority;
 
  int start_frame;
 
  int end_frame;
 

	
 
  while(1)
 
  {
 
    printf("1-->print all frames in a job");
 
    printf("2-->examine certain job");
 
    printf("3-->get a frame to render");
 
    printf("4-->add a job");
 
    printf("5-->delete a job");
 
    printf("6-->print jobnums in queue");
 
    printf("7-->exit menu");
 

	
 
    scanf("%d", &command);
 

	
 
    if(command == 6)
 
      break;
 

	
 
    switch(command)
 
    {
 
    case 1:
 
      printf("job number:");
 
      scanf("%d", &jobnum);
 
      printJob(distrenjob_get(&head, jobnum));
 
      break;
 
    case 2:
 
      printf("job number:");
 
      scanf("%d", &jobnum);
 
      printJobInfo(distrenjob_get(&head, jobnum));
 
      break;
 
    case 3:
 
      find_jobframe(&head, &tmp_job, &tmp_frame);
 
      printf("job#:%d", tmp_job->jobnum);
 
      printf("frame#:%d", tmp_frame->num);
 
      break;
 
    case 4:
 
      printf("type 1:blender, 2:povray"); scanf("%d", &type);
 
      printf("name:");                    scanf("%s", name);
 
      printf("submitter");                scanf("%s", submitter);
 
      printf("e-mail");                   scanf("%s", email);
 
      printf("priority");                 scanf("%d", &priority);
 
      printf("start frame");              scanf("%d", &end_frame);
 
      printf("end frame");                scanf("%d", &start_frame);
 
      prepare_distrenjob(&head, type, name, submitter, email, priority, start_frame, end_frame);
 
      break;
 
    case 5:
 
      printf("job number:");
 
      scanf("%d", &jobnum);
 
      distrenjob_remove(&head, distrenjob_get(&head, jobnum));
 
      break;
 
    case 6:
 
      printAllJobnums(&head);
 
      break;
 
    }
 
  }
 

	
 
  distrend_listen(&listenset, config);
 
  /* This is called the "main loop" */
 
  while(cont)
 
    {
 
      struct distren_action *action;
 
      int clientsays = 0; /*< temporary example variable, will be replaced when we can handle messages */
 

	
 
      distrend_accept(&action);
 
      cont = distrend_do(action);
 

	
 
      /* Make the following code more event-driven */
 
      frame_watchdog(&head);
 

	
 

	
 
      struct frameset *frame;
 
      struct distrenjob *job;
 

	
 
      /* If the client is idle, must be modified for climbing through linked list of clients (client->clientnum) */
 
      if(clientstatus == CLIENTSTATUS_IDLE)
 
	{
 
	  int returnnum = find_jobframe(&head, &job, &frame); // Finds a frame to render
 
	  if(returnnum)
 
	    {
 
	      fprintf(stderr,"No frames are available to render at this time. Idling...\n");
 
	      sleep(10);
 
	    }
 
	  else
 
	    remotio_send_to_client(frame->num, job->jobnum); // Pseudo-sends data to client
 
	}
 
      /* If the client states that they finished the frame */
 
      	if(clientsays == DISTREN_REQUEST_DONEFRAME){
 
      	  clientstatus = CLIENTSTATUS_IDLE; // Sets the client back to idle
 
      	  finish_frame(&head, job, frame->num); // @TODO: Make sure this actually works.
 
      	}
 

	
 
      distrend_action_free(action);
 
    }
 

	
 
  distrend_unlisten(listenset);
 
  distrend_config_free(config);
 

	
 
  return 0;
 
}
0 comments (0 inline, 0 general)