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
 
@@ -392,161 +392,170 @@ void blend_frame_watchdog(struct blendjo
 

	
 
}
 

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