Changeset - 17ee4de48309
[Not reviewed]
default
0 3 0
Ethan Zonca (ethanzonca) - 16 years ago 2010-02-09 19:52:41
e@ethanzonca.com
Added mysql wrapper calls
3 files changed with 9 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -142,96 +142,103 @@ int main(int argc, char *argv[])
 
	  return 2;
 
      }
 

	
 
      else if(strcmp(argv[counter], "-t") == 0)
 
      {
 
    	  fprintf(stderr, "Entering into test mode...\n\n");
 
    	  test = 1;
 
      }
 
    }
 

	
 

	
 
  if(distrend_do_config(argc, argv, &general_info.config))
 
    return 1;
 

	
 
  /** preset paths */
 
  _distren_asprintf(&general_info.files.geninfo, "%s/general_info.xml",
 
		    general_info.config->datadir);
 

	
 
  if(start_data(&general_info))
 
    {
 
      fprintf(stderr, "%s:%d: start_data() failed\n", __FILE__, __LINE__);
 
      return 1;
 
    }
 

	
 
  /** MySQL Connection */
 
  MYSQL *conn;
 
  *conn = mysqlConnect();
 

	
 
  /** pre-loaded jobs for testing */
 
  prepare_distrenjob(&general_info, 1, "awesome", "LordOfWar", 8, 1, 100, 640, 480);
 
  prepare_distrenjob(&general_info, 1, "hamburger", "ohnobinki", 3, 1, 50, 1280, 720);
 

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

	
 
  distrend_listen(general_info.config, &clients);
 

	
 
  /* 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, &job, &frame); // Finds a frame to render
 
	  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, job, frame->num); // @TODO: Make sure this actually works.
 
      	}
 
      	// Check the connection to the database
 
      	mysqlPing(conn);
 
    } /* while(!general_info.config->die) */
 

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

	
 
  xmlcleanup();
 

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

	
 
  return 0;
 
}
 

	
 
/* ********************** 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! @TODO: Fill this stub*/
 
int xml_dump()
 
{
 
  return 0;
 
}
 
/**
 
   Performs command stored in a client's request. @TODO: Fill stub
 
*/
 
int distrend_do()
 
{
 
  return 0;
 
}
 

	
 
/** 
 
    Fill variables at startup from XML dumps or defaults
 
 */
 
int start_data(struct general_info *general_info)
 
{
src/server/mysql.c
Show inline comments
 
@@ -45,29 +45,25 @@ MYSQL mysqlConnect(){
 
    fprintf(stderr, "%s\n", mysql_error(conn));
 

	
 
  return *conn;
 
}
 

	
 
MYSQL_RES mysqlQuery(MYSQL *conn, char *query){
 
  if (mysql_query(conn, query))
 
     fprintf(stderr, "%s\n", mysql_error(conn));
 

	
 
  MYSQL_RES *result;
 
  result = mysql_use_result(conn);
 
  return *result;
 
}
 

	
 
// Check if connection is alive, reconnect if broken.
 
int mysqlPing(MYSQL *conn){
 
  if(mysql_ping(conn)){
 
    fprintf(stderr, "MySQL Connection broken, attempting reconnection...");
 
    return 1;
 
  }
 
  else
 
    return 0; // Connection is still alive
 
}
 

	
 
int mysqlFree(MYSQL_RES *res, MYSQL *conn){
 
  mysql_free_result(res);
 
  mysql_close(conn);
 
  return 0;
 
}
 

	
src/server/mysql.h
Show inline comments
 
@@ -5,28 +5,27 @@
 

	
 
  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 <mysql/mysql.h>
 

	
 
MYSQL mysqlConnect();
 
MYSQL_RES mysqlQuery(MYSQL *conn, char *query);
 
MYSQL_RES mysqlQuery(MYSQL *conn, char *query);
 
int mysqlFree(MYSQL_RES *res, MYSQL *conn);
 
int mysqlPing(MYSQL *conn);
 

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