diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -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,15 +589,42 @@ 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; } +// 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; +} + /* ************************** Test Functions ************************* */ void printFrameInfo(struct frameset *frame) {