Changeset - 0b46b7cc6eab
[Not reviewed]
default
0 1 0
LordOfWar - 16 years ago 2009-10-09 14:31:18

a little taste of recursion for re-creating the queue from an xml file
1 file changed with 30 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -580,7 +580,8 @@ int createQueueFromXML(struct distrenjob
 
  // moves into the children elements of job_list
 
  cur = cur->xmlChildrenNode;
 

	
 
  // scans the list of all jobs that were in queue before DistRen shutdown
 
  reCreateQueueFromXML(doc, cur);
 
  /* scans the list of all jobs that were in queue before DistRen shutdown
 
  while(cur != NULL)
 
    {
 
      tmp = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 
@@ -588,11 +589,38 @@ int createQueueFromXML(struct distrenjob
 
      // add job from job number @TODO create function with parameters (struct distrenjob *head, int job_number)
 
      // LordOfWar calls dibs on above todo
 

	
 

	
 
      xmlFree(tmp);
 
      cur = cur->next; // go to next child element of job_list element
 
    }*/
 

	
 
  xmlFreeDoc(doc);
 

	
 
  return 1;
 
    }
 

	
 
  xmlFreeDoc(doc);
 
// inserts jobs at front of queue, starting with the last job in the job_list xml file
 
// to preserve the order of the queue
 
int reCreateQueueFromXML(struct distrenjob *head, xmlDocPtr doc, xmlNodePtr current)
 
{
 
  struct distrenjob *holder; // holds the job that "was" after head, so that the new struct can be inserted after head
 
  struct distrenjob *job; // job to be added
 
  xmlChar *tmp;
 
  if(current == NULL) // base case, if element doesn't exist then don't do anything
 
    return 0;
 

	
 
  // recursively call itself so that the next job in the queue is added to the front before the current one
 
  reCreateQueueFromXML(head, doc, current->next);
 

	
 
  // now actual work is done, adding the job to the front of the queue
 
  holder = head->next; // initialize holder
 
  tmp = xmlNodeListGetString(doc, current->xmlChildrenNode, 1); // get job number
 
  // job = another function that reads data from xml for that job, prepares the job, and returns a pointer to the job
 
  xmlFree(tmp); // free xml char (that holds the job number)
 

	
 
  // insert job at front of the queue
 
  head->next = job;
 
  job->next = holder;
 

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