Changeset - 9c2a6fb89ff2
[Not reviewed]
default
0 1 0
LordOfWar - 16 years ago 2009-10-09 14:52:35

fixed warnings and started a new function
1 file changed with 10 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -28,96 +28,98 @@
 
#include "asprintf.h"
 

	
 
#include <confuse.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <malloc.h>
 
#include <unistd.h> /* getopt */
 
#include <time.h>
 
#include <sys/stat.h>
 
#include <string.h>
 

	
 
#include <libxml/xmlmemory.h>
 
#include <libxml/parser.h>
 
#include <libxml/tree.h>
 
#include <libxml/encoding.h>
 
#include <libxml/xmlwriter.h>
 
#include <libxml/xmlreader.h>
 

	
 
/* ******************* Structs ************************ */
 

	
 
// Gets config info from confs
 
struct distrend_config
 
{
 
  cfg_t *mycfg;
 
  struct options_common *options;
 
  struct distrend_listen **listens; /*< Null terminated array of structs */
 
  char *datadir;
 
};
 

	
 
struct general_info {
 
  short int jobs_in_queue; //
 
  unsigned short int free_clients;
 
  unsigned short int rendering_clients;//
 
  unsigned short int total_finished_jobs; //
 
  unsigned int total_frames_rendered; //
 
  unsigned int highest_jobnum;
 
  short int hibernate;
 
} general_info;
 

	
 

	
 

	
 
/*
 
  internally defined funcs's prototypes @TODO: Make all functions nice and proper */
 
void distrenjob_remove(struct distrenjob *head, struct distrenjob *bj);
 

	
 
struct distrenjob *distrenjob_get(struct distrenjob *head, jobnum_t jobnum);
 
void distrenjob_enqueue(struct distrenjob *head, struct distrenjob *job);
 
void mortition(struct distrenjob *head, struct distrenjob *job);
 
int reCreateQueueFromXML(struct distrenjob *head, xmlDocPtr doc, xmlNodePtr current);
 

	
 

	
 
/* Global Vars, eliminate these */
 
jobnum_t jobnum = 0; // The next job number to create in the queue
 
int hcfjob; // Highest consecutively finished job
 
int highest_jobnum; // The job number of the most recently created job, this is used when creating new jobs
 

	
 

	
 
/* ********************** Functions ************************* */
 

	
 
/** Dumps all data in RAM to an xml file (such as current jobs, etc) which is parsed by start_data. Remember to invoke this before shutting down! */
 
int xml_dump()
 
{
 
  return 0;
 
}
 
/**
 
   Performs command stored in a client's request.
 
*/
 
int distrend_do()
 
{
 
  return 0;
 
}
 
/**
 
   Accepts a client's connection
 
 */
 
void distrend_accept()
 
{
 

	
 
}
 
/**
 
   Frees the action
 
*/
 
void distrend_action_free()
 
{
 

	
 
}
 
/**
 
   Start listening
 
*/
 
void distrend_listen()
 
{
 

	
 
}
 
/**
 
   Stop listening
 
*/
 
void distrend_unlisten()
 
{
 

	
 
@@ -465,167 +467,173 @@ int distrend_do_config(int argc, char *a
 
  xmlcleanup();
 
  return 0;
 
}
 
int distrend_config_free(struct distrend_config *config)
 
{
 
  options_free(config->options);
 
  free(config);
 

	
 
  return 0;
 
}
 
/* ************************** XML Functions ************************* */
 

	
 
// returns 1 on successful completion of xml file
 
int makeSlaveDataXML(struct distrenjob *job)
 
{
 
  xmlTextWriterPtr writer;
 
  char *tmp; // temporarily holds strings to be given to the xml writer
 

	
 
  _distren_asprintf(&tmp, "stor/job%d/job_info.xml", job->jobnum);
 

	
 
  // create xml document at the location tmp with no compression
 
  writer = xmlNewTextWriterFilename(tmp, 0);
 
  xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
 

	
 
  // write resolution element and add its attributes
 
  xmlTextWriterStartElement(writer, (xmlChar*)"distrenjob");
 
  xmlTextWriterWriteAttribute(writer, (xmlChar*)"name", (xmlChar*)job->name);
 
  xmlTextWriterWriteAttribute(writer, (xmlChar*)"submitter", (xmlChar*)job->submitter);
 
  _distren_asprintf(&tmp, "%d", job->priority);
 
  xmlTextWriterWriteAttribute(writer, (xmlChar*)"priority", (xmlChar*)tmp);
 

	
 
  // write resolution element and add its attributes
 
  xmlTextWriterStartElement(writer, (xmlChar*)"resolution");
 
  _distren_asprintf(&tmp, "%d", job->width);
 
  xmlTextWriterWriteAttribute(writer, (xmlChar*)"width", (xmlChar*)tmp);
 
  _distren_asprintf(&tmp, "%d", job->height);
 
  xmlTextWriterWriteAttribute(writer, (xmlChar*)"height", (xmlChar*)tmp);
 
  xmlTextWriterEndElement(writer);
 

	
 
  // end document
 
  xmlTextWriterEndDocument(writer);
 

	
 
  // free writer and save xml file to disk
 
  xmlFreeTextWriter(writer);
 

	
 
  return 1;
 
}
 

	
 
// extracts data from the xml created by above function and creates a job from it
 
// it returns a pointer to the created job
 
void createJobFromXML(int job_number)
 
{
 

	
 
}
 

	
 
// returns 1 if successful
 
// updates job_list.xml which lists all the jobs in the queue
 
int updateJobListXML(struct distrenjob *head)
 
{
 
  struct distrenjob *job;
 
  xmlTextWriterPtr writer;
 
  char *tmp;
 
  char *tmp2;
 
  int counter;
 

	
 
  _distren_asprintf(&tmp, "job_list.xml");
 
  writer = xmlNewTextWriterFilename(tmp, 0);
 
  xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL);
 

	
 
  // create root element job_list
 
  xmlTextWriterStartElement(writer, (xmlChar*)"job_list");
 

	
 
  _distren_asprintf(&tmp, "%d", general_info.jobs_in_queue);
 
  xmlTextWriterWriteAttribute(writer, (xmlChar*)"amount", (xmlChar*)tmp);
 

	
 
  counter = 0;
 
  for(job = head->next; !job; job = job->next)
 
    {
 
      _distren_asprintf(&tmp, "jobnum%d", counter);
 
      _distren_asprintf(&tmp2, "%d", job->jobnum);
 
      xmlTextWriterWriteElement(writer, (xmlChar*)tmp, (xmlChar*)tmp2);
 
      counter++;
 
    }
 

	
 
  // close elements and end document
 
  xmlTextWriterEndDocument(writer);
 

	
 
  // free writer and save xml file to disk
 
  xmlFreeTextWriter(writer);
 
  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
 
int createQueueFromXML(struct distrenjob *head)
 
{
 
  xmlChar *tmp;
 
  xmlDocPtr doc;  // holds xml document in memory
 
  xmlNodePtr cur; // points to the current xml element node
 

	
 
  // load xml document
 
  doc = xmlParseFile("job_list.xml");
 
  if(doc == NULL)
 
    {
 
      fprintf(stderr, "createQueueFromXML: document not found\n");
 
      return 0;
 
    }
 

	
 
  // have cur point to the root element of the xml document pointed to by doc
 
  cur = xmlDocGetRootElement(doc);
 
  if(cur == NULL)
 
    {
 
      fprintf(stderr, "createQueueFromXML: document empty\n");
 
      return 0;
 
    }
 

	
 
  if(xmlStrcmp(cur->name, (const xmlChar*)"job_list"))
 
    {
 
      fprintf(stderr, "createQueueFromXML: incorrect root element (%s)", (char*)cur->name);
 
    }
 

	
 
  // moves into the children elements of job_list
 
  cur = cur->xmlChildrenNode;
 

	
 
  reCreateQueueFromXML(doc, cur);
 
  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
 
    }*/
 

	
 
  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)
 
{
 
  char *status;
0 comments (0 inline, 0 general)