diff --git a/src/server/mysql.c b/src/server/mysql.c --- a/src/server/mysql.c +++ b/src/server/mysql.c @@ -22,6 +22,7 @@ #include #include "common/asprintf.h" +#include "common/protocol.h" #include #include @@ -149,3 +150,122 @@ int mysqlResultFree(distrend_mysql_resul return 0; } + +/** + Querying Functions + */ + +/** Finish-Setter: Sets a frame to the "completed" status.*/ +// @QUERY: update `distren`.`Job` set `Finish_Confirmed`=1 where `Job_Key`='1' and `Frame` = somenumber; +void finish_frame(int slaveKey, int jobKey, int frameNum) +{ + // Check to make sure the slavekey is the one who rendered the frame before finishing :D + /* + distrenjob->frameset[frame].status = FRAMESETSTATUS_DONE; + distrenjob->total_render_time = distrenjob->total_render_time + (clock() - distrenjob->frameset[frame].start_time); + distrenjob->completed_frames ++; + distrenjob->assigned_frames --; + geninfo->total_frames_rendered ++; //< Increase total frames var for stats + + update_general_info(geninfo); + updateJobStatsXML(distrenjob); + */ +} + +/** Changes the priority of an existing (and maybe running) job. @arg head I may end up changing the head if job == head */ +// @QUERY: update `distren`.`Job` set `Priority`='12', `Finish_Confirmed`=1 where `Job_Key`='1'; +int change_job_priority(int jobKey, int newPriority){ + /* + struct distrenjob *current_job; + struct distrenjob *prev_job; + char *serialname; + + distrenjob_remove(geninfo, job); + job->priority = new_priority; + + prev_job = &geninfo->head; + + if(job->frameset[0].status == FRAMESETSTATUS_UNASSIGNED) + + // if job was not yet started + + { + distrenjob_enqueue(geninfo, job); + return 0; + } + + + // iterate through linked list of jobs + for(current_job = &geninfo->head; + current_job != NULL + && job->priority > current_job->priority; + current_job = current_job->next) + prev_job = current_job; + + prev_job->next = job; + job->next = current_job; + + + update_xml_joblist(geninfo); + // reserialize after changes + job_getserialfilename(&serialname, geninfo, job->jobnum, 0); + distrenjob_serialize(job, serialname); + free(serialname); +*/ + return 0; +} + +/** + Frame Finder: matches your computer up with a lovely frame to render, starts looking at oldest job first + @TODO: We must return both jobnum and framenum + @TODO: Add calls in main() + @return 0 success, other: error +*/ +// @QUERY: Frame_Get() +int find_jobframe(int slaveKey, int *jobKey, int *frameNum) +{ + /* + if(geninfo->hibernate) + return 1; + + unsigned int frame_counter; + unsigned short int found; + + struct distrenjob *distrenjob_ptr; + + found = 0; + // iterate through jobs from first to last + for(distrenjob_ptr = geninfo->head.next; distrenjob_ptr && !distrenjob_ptr->hibernate; distrenjob_ptr = distrenjob_ptr->next) + { + for(frame_counter = (distrenjob_ptr->prev_frame_index + 1); frame_counter < distrenjob_ptr->total_frames; frame_counter ++) + { + if(distrenjob_ptr->frameset[frame_counter].status == FRAMESETSTATUS_UNASSIGNED) // jobframe found + { + found = 1; + distrenjob_ptr->frameset[frame_counter].status = FRAMESETSTATUS_ASSIGNED; + distrenjob_ptr->frameset[frame_counter].start_time = clock(); + distrenjob_ptr->assigned_frames++; + distrenjob_ptr->prev_frame_index = frame_counter; + updateJobStatsXML(distrenjob_ptr); + } + + if(found) + break; + } + + if(found) + break; + } + + if(!found) + { + fprintf(stderr, "No more jobs to render\n"); + sleep(1); //< @todo eliminate the need for this line + return 1; + } + + *job = distrenjob_ptr; + *frame = &distrenjob_ptr->frameset[frame_counter]; +*/ + return 0; +}