Changeset - 0be4e8427de5
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2009-07-26 08:53:52
ohnobinki@ohnopublishing.net
started fixing server's main()
1 file changed with 29 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -296,257 +296,266 @@ void frame_num_struct_builder(struct ble
 

	
 
/**
 
  Frame Finder: matches your computer up with a lovely frame to render
 
  TODO: Major issue here, the client needs to know the frame number, AND the job number!
 
  Notice that this function starts by looking at the oldest job first
 

	
 
	TODO: Link this up with the main() function to check if there are frames available or not and provide jobnum/framenum to the client
 

	
 
  @return 0 success, other: error
 
*/
 
int frame_finder(struct blendjob *head, struct blendjob **job, struct frameset **frame)
 
{
 
  int your_frame;  // your_frame is an integer value that will be given to the client as the frame number to render
 
  int your_job;	   // you_job is an integer value that must ALSO be given to the client
 

	
 
  unsigned short int found;
 
  unsigned short int priority;
 

	
 
  struct blendjob *blendjob_ptr;
 

	
 
  found = 0;
 
  while(!found)
 
    {
 
      /* enumerate through priority levels */
 
      for(priority = 10;
 
	  priority > 0
 
	    && !found;
 
	  priority --)
 
	/* Find the job with the highest priority */
 
	for(blendjob_ptr = head;
 
	    blendjob_ptr != NULL
 
	      && !found;
 
	    blendjob_ptr = blendjob_ptr->next)
 
	  if(blendjob_ptr->priority == priority)
 
	    found = 1;
 

	
 
      if(!found)
 
	{
 
	  fprintf(stderr, "out of jobs to render\n");
 
	  return 1;
 
	}
 

	
 
      found = 0;
 
      for(your_frame = 0;
 
	  your_frame < blendjob_ptr->total_frames;
 
	  your_frame ++)
 
	if(blendjob_ptr->frameset[your_frame].status == 0)
 
	  found = 1;
 

	
 
      if(!found)
 
	{
 
	  /* there are no frames left in this job */
 
	  blendjob_ptr->priority --;
 

	
 
	  /* If that job had no open frames for some reason, run the status report generator so that */
 
	  status_report_generator(&head);
 

	
 
	  /* should the job be removed now? */
 
	  fprintf(stderr, "Job %d is finished, this is probably the place to call the job-removal function\n", blendjob_ptr->jobnum);
 
	}
 
    } /* while(!found) */
 

	
 
  fprintf(stderr, "Missing apostrophe !!!!!!!!!!!!!!\n"); abort();
 
  /* sets the value of the frame to 1, which means its taken !!!!!! MISSSING APOSTROPHE!!!!!!! */
 
  blendjob_ptr->frameset[your_frame].status++;
 

	
 
  blendjob_ptr->frameset[your_frame].start_time = clock();
 

	
 
  *job = blendjob_ptr;
 
  *frame =  &blendjob_ptr->frameset[your_frame];
 

	
 
  return 0;
 
}
 

	
 
void blend_frame_watchdog(struct blendjob *blendjob_head)
 
{
 
  unsigned short int watchdog_forgiveness; /*< seconds to wait on a frame before re-assigning it */
 
  struct blendjob *blendjob_ptr;
 
  unsigned int counter;
 

	
 
  watchdog_forgiveness = 3; /*< hours of forgiveness before frame is re-assigned */
 
  blendjob_ptr = blendjob_head;
 

	
 
  for(blendjob_ptr = blendjob_head; blendjob_ptr; blendjob_ptr = blendjob_ptr->next)
 
    /* iterate through jobs */
 

	
 
    for(counter = 0; counter < blendjob_ptr->total_frames; counter ++)
 
      /* iterate through all frames for this job*/
 
      {
 
	if((blendjob_ptr->frameset[counter].start_time + (watchdog_forgiveness * 3600)) < clock())
 
	  /*
 
	    If frame is not completed within the number of hours specified by watchdog_forgiveness
 
	    Then change the frame status to unassigned
 
	  */
 
	  blendjob_ptr->frameset[counter].status = 0;
 
      }
 

	
 
}
 

	
 
/**
 
   Finds a blendjob struct based on the jobnum
 
   @arg jobnum job number to search for
 
   @return NULL on job doesn't exist
 
 */
 
struct blendjob *blendjob_get(struct blendjob *head, jobnum_t jobnum)
 
{
 
  struct blendjob *blendjob_ptr;
 

	
 
  /*
 
    The conditions of the for loop will leave blendjob_ptr at NULL if the end of the list is reached. It will leave it pointing to the correct job if it is found.
 
   */
 
  for(blendjob_ptr = head;
 
      blendjob_ptr
 
	&& blendjob_ptr->jobnum != jobnum;
 
      blendjob_ptr = blendjob_ptr->next);
 

	
 
  return blendjob_ptr;
 
}
 

	
 

	
 
/**
 
   Removes a blendjob from the blendjob linkelist.
 

	
 
   @arg head a double pointer. the head pointer will have to be changed if blendjob == *head. Thus, make sure that the pointer points to the pointer to the head that all functions use. (I'm going to come back to this and misunderstand myself ;-))
 
 */
 
void blendjob_remove(struct blendjob **head, struct blendjob *bj)
 
{
 
  struct blendjob *previous_blendjob;
 

	
 
  if(bj == *head)
 
    *head = bj->next;
 
  else
 
    {
 

	
 
      for(previous_blendjob = *head;
 
	  previous_blendjob
 
	    && previous_blendjob->next != bj; /*< stop on the blendjob that comes before bj */
 
	  previous_blendjob = previous_blendjob->next)
 
	/* all of the action is in the definition of the for loop itself */;
 

	
 
      /*
 
	This removes references to bj from the linked list. I.E., we now skip bj when iterating through the list
 
       */
 
      previous_blendjob->next = bj->next;
 
    }
 

	
 
  /*
 
     @lordofwar: the magic deallocation of memory ;-)
 
   */
 
  free(bj);
 
}
 

	
 

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

	
 

	
 
// Begin non-working framework?
 
	int distrend_do_config(int argc, char *argv[], struct distrend_config *config)
 
	{
 
	  cfg_opt_t myopts_listen[] =
 
	    {
 
	      CFG_SIMPLE_STR("type", NULL),
 
	      CFG_SIMPLE_STR("path", NULL),
 
	      CFG_SIMPLE_INT("port", NULL),
 
	      CFG_END()
 
	  };
 
	  cfg_opt_t myopts[] =
 
	    {
 
	      CFG_SEC("listen",  /* this must be imported into struct listens (which must still be declared) */
 
		      myopts_listen
 
		      ,
 
		      CFGF_MULTI),
 
	      CFG_END()
 
	    };
 

	
 
	  config = malloc(sizeof(struct distrend_config));
 
	  options_init(argc, argv, &config->mycfg, myopts, "server", &config->options);
 

	
 
	  return 0;
 
	}
 
	int distrend_config_free(struct distrend_config *config)
 
	{
 
	  options_free(config->options);
 
	  free(config);
 

	
 
	  return 0;
 
	}
 
// End non-working framework?
 

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

	
 
/* TODO: Put some arg-grabbing code here */
 
  /* TODO: Put some arg-grabbing code here */
 

	
 
  struct blendjob *head;
 

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

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

	
 
  head = NULL;
 
  cont = 1;
 

	
 
  distrend_do_config(argc, argv, config);
 

	
 
  distrend_listen(&listenset, config);
 
  /* This is called the ``main loop'' */
 
  while(cont)
 
    {
 
      struct distren_action *action;
 

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

	
 

	
 
      /* Somewhat Pseudo-code for basic server operation, should be more event-driven */
 

	
 
      start_data();
 
      status_report_generator(); // TODO: Add correct args
 
      blend_frame_watchdog();	 // TODO: Add correct args
 
      status_report_generator(&head);
 
      blend_frame_watchdog(head);	 // TODO: Add correct args
 

	
 

	
 
      struct frameset *frame;
 
      struct blendjob *job;
 

	
 
      /* If the client is idle (meaning a client without the "busy" status connected via ssh) */
 
      	if(clientstatus == "idle")
 
	  {
 
      		int returnnum = frame_finder(&head, job, frame); // give framefinder args, framefinder should return job number and frame number somehow
 
				if(returnnum == 1){
 
					fprinf(stderr,"No frames are available to render at this time");
 
					sleep(10);
 
				}
 
				else if(returnnum == 0){
 
					remotio_send_to_client(framenum, jobnum);
 
				}
 
				else(){
 
					fprintf(stderr,"Something is terribly wrong!");
 
				}
 
      	}
 
      if(clientstatus == CLIENTSTATUS_IDLE)
 
	{
 
	  /** 
 
	      normaldotcom: learn about ``return by pointer''
 
	  */
 
	  int returnnum = frame_finder(head, &job, &frame); // give framefinder args, framefinder should return job number and frame number somehow
 
	  if(returnnum)
 
	    {
 
	      fprinf(stderr,"No frames are available to render at this time");
 
	      sleep(10);
 
	    }
 
	  else
 
	    /* returnnum == 0 */
 
	    remotio_send_to_client(frame->num, job->jobnum);
 
	}
 
      /* If the client's status changes from running to idle */
 
      	if(clientstatus == DISTREN_REQUEST_DONEFRAME && iteration == 0){
 
      		finish_frame(jobnum, framenumprevious); // make it finish the previous frame or something.
 
      		frame_finder() ==> returns jobnum/framenum that are sent to slave, "render jobnum framenum"
 
      	if(clientsays == DISTREN_REQUEST_DONEFRAME && iteration == 0){
 
	  clientstatus = CLIENTSTATUS_IDLE;
 
	  finish_frame(jobnum, framenumprevious); // make it finish the previous frame or something.
 
	  frame_finder() ==> returns jobnum/framenum that are sent to slave, "render jobnum framenum"
 
      	}
 

	
 
      /* End Somewhat Pseudo-code */
 

	
 

	
 
      distrend_action_free(action);
 
    }
 

	
 
  distrend_unlisten(listenset);
 
  distrend_config_free(config);
 

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