Changeset - 4b53912fd49c
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2009-12-01 00:23:47
ohnobinki@ohnopublishing.net
createQueueFromXML(): slight cleanup, error handling
1 file changed with 24 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -796,11 +796,14 @@ struct distrenjob *createJobFromXML(int 
 
  int counter;
 
  int counter2;
 

	
 
  distrenjob_new(&distrenjob);
 

	
 
  _distren_asprintf(&file_name, "stor/job%d/job_info.xml", job_number);
 

	
 
  doc = xmlParseFile(file_name);
 
  if(!doc)
 
    return NULL;
 

	
 
  distrenjob_new(&distrenjob);
 

	
 
  cur = xmlDocGetRootElement(doc);
 

	
 
  distrenjob->name = (char*)xmlGetProp(cur, (xmlChar*)"name");
 
@@ -923,11 +926,15 @@ int update_xml_joblist(struct general_in
 
  return 1;
 
}
 

	
 
// returns 1 if completed successfully, 0 if not
 
// this reads a list of jobs in the queue before DistRen was shut down
 
// and then adds the jobs to the queue, as if it were never shut down
 
/**
 
 returns 0 if completed successfully
 
 this reads a list of jobs in the queue before DistRen was shut down
 
 and then adds the jobs to the queue, as if it were never shut down
 
*/
 
int createQueueFromXML(struct distrenjob *head)
 
{
 
  int tmp;
 

	
 
  xmlDocPtr doc;  // holds xml document in memory
 
  xmlNodePtr cur; // points to the current xml element node
 

	
 
@@ -936,7 +943,7 @@ int createQueueFromXML(struct distrenjob
 
  if(doc == NULL)
 
    {
 
      fprintf(stderr, "createQueueFromXML: document not found\n");
 
      return 0;
 
      return 1;
 
    }
 

	
 
  // have cur point to the root element of the xml document pointed to by doc
 
@@ -944,7 +951,7 @@ int createQueueFromXML(struct distrenjob
 
  if(cur == NULL)
 
    {
 
      fprintf(stderr, "createQueueFromXML: document empty\n");
 
      return 0;
 
      return 1;
 
    }
 

	
 
  if(xmlStrcmp(cur->name, (const xmlChar*)"job_list"))
 
@@ -955,23 +962,11 @@ int createQueueFromXML(struct distrenjob
 
  // moves into the children elements of job_list
 
  cur = cur->xmlChildrenNode;
 

	
 
  reCreateQueueFromXML(head, doc, cur);
 
  /* scans the list of all jobs that were in queue before DistRen shutdown
 
  while(cur != NULL)
 
    {
 
      tmp = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 
      fprintf(stderr, "adding job: %s", tmp);
 
      // 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
 
    }*/
 
  tmp = reCreateQueueFromXML(head, doc, cur);
 

	
 
  xmlFreeDoc(doc);
 

	
 
  return 1;
 
  return tmp;
 
}
 

	
 
// inserts jobs at front of queue, starting with the last job in the job_list xml file
 
@@ -986,20 +981,25 @@ int reCreateQueueFromXML(struct distrenj
 
    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);
 
  if(reCreateQueueFromXML(head, doc, current->next))
 
    return 1;
 

	
 
  // 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_num = atoi((char*)tmp);
 
  xmlFree(tmp);
 

	
 
  job = createJobFromXML(job_num);
 
  xmlFree(tmp); // free xml char (that holds the job number)
 
  if(job == NULL)
 
    return 1;
 

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

	
 
  return 1;
 
  return 0;
 
}
 

	
 
/* ************************** Test Functions ************************* */
0 comments (0 inline, 0 general)