# HG changeset patch # User LordOfWar # Date 2009-09-12 17:33:11 # Node ID 7fa6b34e407e9d93cbee3f55f8a973bc8ef65d72 # Parent ba60368f2032fe3e0e47d3727a2e82656b270cc2 updated queue function, it now creates the job, then passes it to the add_job_to_queue function which properly places it in the queue based on its priority... but currently it only creates blender jobs, although I plan on using a switch statement to create different job types in the future. diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -158,23 +158,41 @@ void finish_frame(struct distrenjob *dis general_info.total_frames_rendered++; // Increase total frames var for stats } -/* This @TODO: replace queue function*/ -/* This function creates a structure from starting data, then calls another function to actually add that struct to the queue -void make_blendjob(char *name, char *submitter, char *email, int priority, int start_frame, int end_frame){ - struct distrenjob *new_distrenjob; - distrenjob->type = 1; /*@TODO: add type to blendjob struct + +// This function creates a structure from starting data, then calls another function to actually add that struct to the queue +void queue(int type, char *name, char *submitter, char *email, int priority, int start_frame, int end_frame){ + struct distrenjob *distrenjob; + distrenjob->type = 1; /*@TODO: add type to blendjob struct*/ distrenjob->name = name; distrenjob->submitter = submitter; distrenjob->email = email; distrenjob->priority = priority; distrenjob->frameset = frameset[end_frame - start_frame + 1]; + distrenjob->total_frames = (end_frame - start_frame + 1); // sets the total number of frames in animation for status purposes - /* @TODO: change frame_num_struct_builder to add_blendjob_to_queue - add_blendjob_to_queue(new_distrenjob); + /* @TODO: what does this do? frameset array is declared above */ + /* + distrenjob->frameset = malloc(sizeof(struct frameset) * numframes); + if(!job->frameset) + fprintf(stderr, "Error allocating memory\n"); + */ + + /* prepares all the frames by setting that status to "unassigned" */ + int counter2 = start_frame; + for(int counter = 0; counter <= (end_frame- start_frame + 1); counter++){ + distrenjob->frameset[counter].num = counter2; + distrenjob->frameset[counter].status = 0; + + counter2++; + } + + /* @TODO: change frame_num_struct_builder to add_blendjob_to_queue */ + add_job_to_queue(distrenjob); + + general_info.jobs_in_queue++; } - */ -/** Queuer: Adds files to the queue */ +/** -- OLD -- Queuer: Adds files to the queue int queue(struct distrenjob *distrenjob, int type, char *name, char *submitter, char *email, int priority, int mode, int spp, struct frameset *frameset) { // Type: 1 = blender, add more types later // jobnum is the next available job number @@ -192,7 +210,7 @@ int queue(struct distrenjob *distrenjob, } jobnum++; // Advance the jobnumber for the next queued job return 0; // OK -} +}*/ /** @@ -289,22 +307,22 @@ void status_report_generator(struct dist /** Structure Builder: This function creates frame array based on the total number of frames to be rendered, which will then be parsed by function frame_farmer. */ -void frame_num_struct_builder(struct distrenjob *job, unsigned int startframe, unsigned int numframes) { - int jobnum_new = highest_jobnum + 1; /* global vars will someday leave us */ - unsigned int counter; - - job->frameset = malloc(sizeof(struct frameset) * numframes); - if(!job->frameset) - fprintf(stderr, "Error allocating memory\n"); +void add_job_to_queue(struct distrenjob *job) { + struct distrenjob *prev_job = head; // create pointer to previous job + struct distrenjob *current_job; // create pointer to current_job (which job is being compared to) - job->total_frames = numframes; // sets the total number of frames in animation for status purposes - job->jobnum = jobnum_new; - - for(counter = 0; counter < numframes; counter ++) - /* This builds the array, with the array starting at zero and the frameset.num starting at sframe */ - job->frameset[counter].num = counter + startframe; - - highest_jobnum++; // After it has created the job, it adds one to the highest_jobnum interger + // iterate through linked list of jobs + for(current_job = head; current_job != NULL; current_job = current_job.next){ + if(current_job == NULL){ // if it has reached the end of the list, add job there + current_job = job; + break; + } + else if(job.priority < current_job.priority){ // if job's priority is less than current_job's priority, insert job + prev_job.next = job; // keep in mind 1 is the lowest priority + job.next = current_job; + break; + } + } // end of for statement }