Changeset - 12d457aff611
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 16 years ago 2010-02-18 22:23:35
ohnobinki@ohnopublishing.net
fix find_jobframe() call for real
3 files changed with 7 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -144,49 +144,49 @@ int main(int argc, char *argv[])
 
  fprintf(stderr,"Finished connecting!\n");
 

	
 
  /** Execute test function */
 
  interactiveTest(test, general_info, general_info.conn);
 

	
 
  distrend_listen(general_info.config, &clients);
 

	
 
  int slaveKey = 0; // Remotio should set me on a per-slave basis
 
  /* Main Loop */
 
  while(!general_info.config->die)
 
    {
 
      int clientsays = 0; /*< temporary example variable, will be replaced when we can handle messages */
 

	
 
      distrend_accept(general_info.config, clients);
 

	
 
      /* Make the following code more event-driven */
 
      frame_watchdog(&general_info.head);
 

	
 
      struct frameset *frame;
 
      struct distrenjob *job;
 

	
 
      /* If the client is idle, must be modified for climbing through linked list of clients (client->clientnum) */
 
      if(clientstatus == CLIENTSTATUS_IDLE)
 
	{
 
	  int returnnum = find_jobframe(general_info.conn, slaveKey, job->jobnum, frame->num); // Finds a frame to render @FIXME: Slavenum :D
 
	  int returnnum = find_jobframe(general_info.conn, slaveKey, &job->jobnum, &frame->num); // Finds a frame to render @FIXME: Slavenum :D
 
	  if(returnnum)
 
	    {
 
	      fprintf(stderr,"No frames are available to render at this time. Idling...\n");
 
	      sleep(10);
 
	    }
 
	  else
 
	    remotio_send_to_client(frame->num, job->jobnum); // Pseudo-sends data to client
 
	}
 
      /* If the client states that they finished the frame */
 
      	if(clientsays == DISTREN_REQUEST_DONEFRAME){
 
      	  clientstatus = CLIENTSTATUS_IDLE; // Sets the client back to idle
 
      	  finish_frame(general_info.conn, 0, job->jobnum, frame->num); // @TODO: Make sure this actually works.
 
      	}
 
    }
 

	
 
  distrend_unlisten(general_info.config->listens, clients);
 
  distrend_config_free(general_info.config);
 

	
 
  xmlcleanup();
 

	
 
  /** free() paths */
 
  free(general_info.files.geninfo);
 
  mysqlDisconnect(general_info.conn);
 

	
 
@@ -401,49 +401,49 @@ int update_xml_joblist(struct general_in
 

	
 
  xmlTextWriterEndElement(writer);
 

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

	
 
  /**
 
     free writer and save xml file to disk
 
  */
 
  xmlFreeTextWriter(writer);
 
  return 0;
 
}
 

	
 
/* ************************** Test Functions ************************* */
 

	
 

	
 
/** Interactive test for the queuing system */
 
/* @QUEUE: Test uses methods not present in C code using mysql web-based system */
 
int interactiveTest(int test, struct general_info general_info, distrend_mysql_conn_t conn){
 
  int command;
 
  fprintf(stderr,"Hello!\n");
 
  int32_t slaveKey = 1;
 
  int32_t jobKey = 0;
 
  jobnum_t jobKey = 0;
 
  int32_t frameNum = 0;
 
  int32_t newPriority = 0;
 
  int tmp = 0;
 

	
 
  while(test == 1)
 
   {
 
     fprintf(stderr, "Welcome to DistRen Alpha Interactive Test Mode\n\n");
 
     fprintf(stderr, "\t1 \tGet a frame to render\n");
 
     fprintf(stderr, "\t2 \tChange job priority\n");
 
     fprintf(stderr, "\t3 \tSet frame finished\n");
 
     fprintf(stderr, "\t4 \tSet frame started\n");
 
     fprintf(stderr, "\t5 \tQuit\n");
 

	
 
     scanf("%d", &command);
 

	
 
     switch(command)
 
     {
 
     case 1:
 
       fprintf(stderr,"Slave Key: ");
 
       scanf("%d", &slaveKey);
 
       fprintf(stderr, "Got frame: ");
 
       find_jobframe(conn, slaveKey, &jobKey, &frameNum);
 
       fprintf(stderr, "jobKey: %d, frameNum: %d\n",jobKey,frameNum);
 
       break;
src/server/mysql.c
Show inline comments
 
@@ -223,54 +223,54 @@ void start_frame(distrend_mysql_conn_t c
 
  char *query;
 
  distrend_mysql_result_t result;
 

	
 
  _distren_asprintf(&query, "CALL `distren`.`Frame_Start`(%d,%d,%d);", slavekey, jobkey, framenum);
 

	
 
  result = mysqlQuery(conn, query);
 
  free(query);
 

	
 
  mysqlResultFree(result);
 
}
 

	
 
int change_job_priority(distrend_mysql_conn_t conn, int32_t jobkey, int32_t newpriority)
 
{
 
  char *query;
 
  distrend_mysql_result_t result;
 

	
 
  _distren_asprintf(&query, "UPDATE `distren`.`Job` SET `Priority`=%d WHERE `Job_Key`=%d",
 
		    newpriority, jobkey);
 
  result = mysqlQuery(conn, query);
 
  mysqlResultFree(result);
 

	
 
  return 0;
 
}
 

	
 
int find_jobframe(distrend_mysql_conn_t conn, int32_t slavekey, int32_t *jobkey, int32_t *framenum)
 
int find_jobframe(distrend_mysql_conn_t conn, int32_t slavekey, jobnum_t *jobkey, int32_t *framenum)
 
{
 
  distrend_mysql_result_t result;
 
  char *query;
 
  MYSQL_ROW row;
 

	
 
  _distren_asprintf(&query, "CALL `distren`.`Frame_Get`(%d);", slavekey);
 

	
 
  result = mysqlQuery(conn, query);
 
  free(query);
 

	
 
  if(!result)
 
    return 1;
 

	
 
  row = mysql_fetch_row(result->mysqlresult);
 
  if(!row)
 
    {
 
      mysqlResultFree(result);
 
      return 1;
 
    }
 

	
 
  distrend_mysql_getint(row, 0, jobkey);
 
  distrend_mysql_getint(row, 0, (int32_t *)jobkey);
 
  distrend_mysql_getint(row, 1, framenum);
 

	
 

	
 
  
 
  mysqlResultFree(result);
 

	
 
  return 0;
 
}
src/server/mysql.h
Show inline comments
 
/*
 
  Copyright 2009 Nathan Phillip Brink, Ethan Zonca, Matthew Orlando
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 

	
 
#ifndef MYSQL_H_
 
#define MYSQL_H_
 

	
 
#include "distrenjob.h"
 

	
 
#include <stdint.h>
 

	
 
struct distrend_mysql_conn;
 
struct distrend_mysql_result;
 

	
 
typedef struct distrend_mysql_conn *distrend_mysql_conn_t;
 
typedef struct distrend_mysql_result *distrend_mysql_result_t;
 

	
 
/**
 
   initiates a MySQL connection
 
   @param conn, pointer will be set to the struct
 
   @return 0 on success
 
 */
 
int mysqlConnect(distrend_mysql_conn_t *conn);
 

	
 
/**
 
   cleans and disconnects MySQL connection
 
   @param conn connection to clean
 
   @return 0 on success
 
*/
 
int mysqlDisconnect(distrend_mysql_conn_t conn);
 

	
 
/**
 
   Mark a frame as finished in the database and calculate the seconds spent on that frame.
 
 */
 
void finish_frame(distrend_mysql_conn_t conn, int32_t slavekey, int32_t jobkey, int32_t framenum);
 

	
 
/**
 
   Mark a frame as started in the database and save the time at which it started.
 
 */
 
void start_frame(distrend_mysql_conn_t conn, int32_t slavekey, int32_t jobkey, int32_t framenum);
 

	
 
/**
 
   Changes the priority of an existing (and maybe running) job. @arg head I may end up changing the head if job == head
 
*/
 
int change_job_priority(distrend_mysql_conn_t conn, int32_t jobkey, int32_t newpriority);
 

	
 
/**
 
  Frame Finder: Finds a frame for a slave to render
 
*/
 
int find_jobframe(distrend_mysql_conn_t conn, int32_t slaveKey, int32_t *jobKey, int32_t *frameNum);
 
int find_jobframe(distrend_mysql_conn_t conn, int32_t slaveKey, jobnum_t *jobKey, int32_t *frameNum);
 

	
 

	
 

	
 

	
 
#endif /* MYSQL_H_ */
0 comments (0 inline, 0 general)