[svn r258] Added gmyth_query and gmyth_scheduler connection methods with timeout. Besides, configura.ac now checks libmysqlclient in the right way trunk
authormelunko
Wed Jan 10 21:47:24 2007 +0000 (2007-01-10)
branchtrunk
changeset 25786e15690a104
parent 256 7776e35d59d4
child 258 835d5cc01a0a
[svn r258] Added gmyth_query and gmyth_scheduler connection methods with timeout. Besides, configura.ac now checks libmysqlclient in the right way
gmyth/configure.ac
gmyth/src/gmyth_query.c
gmyth/src/gmyth_query.h
gmyth/src/gmyth_scheduler.c
gmyth/src/gmyth_scheduler.h
gmyth/tests/gmyth_test_connection.c
     1.1 --- a/gmyth/configure.ac	Wed Jan 10 20:52:55 2007 +0000
     1.2 +++ b/gmyth/configure.ac	Wed Jan 10 21:47:24 2007 +0000
     1.3 @@ -196,42 +196,17 @@
     1.4  #
     1.5  # mysql libraries
     1.6  #
     1.7 -MYSQL_CFLAGS="$CFLAGS -DBIG_JOINS=1"
     1.8 -MYSQL_LIBS="$LIBS -L/usr/lib"
     1.9 +AC_CHECK_PROG(MYSQL_CFLAGS,mysql_config,`mysql_config --cflags`)
    1.10 +if test -z "$MYSQL_CFLAGS"; then
    1.11 +        AC_MSG_ERROR([Could not find mysql_config script. Make sure the mysql client libraries are installed])
    1.12 +fi
    1.13 +AC_SUBST(MYSQL_CFLAGS)
    1.14  
    1.15 -AC_CHECK_LIB( mysqlclient, mysql_init, 
    1.16 -					[
    1.17 -						MYSQL_CFLAGS="$MYSQL_CFLAGS -DBIG_JOINS=1"
    1.18 -						MYSQL_LIBS="$MYSQL_LIBS -lmysqlclient"
    1.19 -					], AC_MSG_ERROR([Could not find mysqlclient library. Make sure the mysql client libraries are installed] ) )
    1.20  
    1.21 -AC_CHECK_LIB( z, deflate, 
    1.22 -					[
    1.23 -						MYSQL_LIBS="$MYSQL_LIBS -lz"
    1.24 -					], AC_MSG_WARN([Could not find a mysqlclient library dependency - Z. Make sure the mysql client libraries are installed]) )
    1.25 -
    1.26 -AC_CHECK_LIB( crypt, encrypt, 
    1.27 -					[
    1.28 -						MYSQL_LIBS="$MYSQL_LIBS -lcrypt"
    1.29 -					], AC_MSG_WARN([Could not find a mysqlclient library dependency - Crypt library. Make sure the mysql client libraries are installed]) )
    1.30 -
    1.31 -AC_CHECK_LIB( nsl, yp_all, 
    1.32 -					[
    1.33 -						MYSQL_LIBS="$MYSQL_LIBS -lnsl"
    1.34 -					], AC_MSG_WARN([Could not find a mysqlclient library dependency - NSL library. Make sure the mysql client libraries are installed]) )
    1.35 -
    1.36 -AC_CHECK_LIB( m, ccos, 
    1.37 -					[
    1.38 -						MYSQL_LIBS="$MYSQL_LIBS -lm"
    1.39 -					], AC_MSG_WARN([Could not find a mysqlclient library dependency - M library. Make sure the mysql client libraries are installed]) )
    1.40 -
    1.41 -AC_CHECK_HEADERS( [mysql/mysql.h mysql/mysql_version.h], [ AC_MSG_NOTICE([Found MySQL headers!]) ],
    1.42 -					[ AC_MSG_WARN([Could not find mysqlclient headers, but it will work fine instead of this...]) ],
    1.43 -					[
    1.44 -					#include <mysql/mysql.h>
    1.45 -					])
    1.46 -
    1.47 -AC_SUBST(MYSQL_CFLAGS)
    1.48 +AC_CHECK_PROG(MYSQL_LIBS,mysql_config,`mysql_config --libs`)
    1.49 +if test -z "$MYSQL_LIBS"; then
    1.50 +        AC_MSG_ERROR([Could not find mysql_config script. Make sure the mysql client libraries are installed])
    1.51 +fi
    1.52  AC_SUBST(MYSQL_LIBS)
    1.53  
    1.54  #dnl Enable gtk-doc
     2.1 --- a/gmyth/src/gmyth_query.c	Wed Jan 10 20:52:55 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_query.c	Wed Jan 10 21:47:24 2007 +0000
     2.3 @@ -65,6 +65,7 @@
     2.4  
     2.5      /* initialize connection handler */
     2.6      gmyth_query->conn = mysql_init (NULL);
     2.7 +
     2.8      
     2.9      if (!(gmyth_query->conn))
    2.10      	g_warning ("[%s] MSQL structure not initialized", __FUNCTION__);
    2.11 @@ -104,6 +105,21 @@
    2.12      return sql_query;
    2.13  }
    2.14  
    2.15 +gboolean
    2.16 +gmyth_query_connect_with_timeout (GMythQuery *gmyth_query, 
    2.17 +		GMythBackendInfo *backend_info, guint timeout)
    2.18 +{
    2.19 +    assert(gmyth_query);
    2.20 +    g_return_val_if_fail (gmyth_query->conn != NULL, FALSE);
    2.21 +printf ("XXXXXXXXX timeout %d\n", timeout);
    2.22 +    if (timeout != 0) {
    2.23 +        /* sets connection timeout */
    2.24 +        mysql_options (gmyth_query->conn, MYSQL_OPT_CONNECT_TIMEOUT, (gchar*) &timeout);
    2.25 +    }
    2.26 +
    2.27 +    return gmyth_query_connect (gmyth_query, backend_info);
    2.28 +}
    2.29 +
    2.30  /** Connects to the Mysql database in the backend. The backend address
    2.31   * is loaded from the GMythBackendInfo instance.
    2.32   * 
     3.1 --- a/gmyth/src/gmyth_query.h	Wed Jan 10 20:52:55 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_query.h	Wed Jan 10 21:47:24 2007 +0000
     3.3 @@ -77,6 +77,8 @@
     3.4                  (GMythQuery *gmyth_query, gchar *stmt_str);
     3.5  
     3.6  gboolean gmyth_query_connect (GMythQuery *gmyth_query, GMythBackendInfo *backend_info);
     3.7 +gboolean gmyth_query_connect_with_timeout (GMythQuery *gmyth_query,
     3.8 +	                GMythBackendInfo *backend_info, guint timeout);
     3.9  gboolean gmyth_query_disconnect (GMythQuery *gmyth_query);
    3.10  
    3.11  G_END_DECLS
     4.1 --- a/gmyth/src/gmyth_scheduler.c	Wed Jan 10 20:52:55 2007 +0000
     4.2 +++ b/gmyth/src/gmyth_scheduler.c	Wed Jan 10 21:47:24 2007 +0000
     4.3 @@ -134,6 +134,12 @@
     4.4      return scheduler;
     4.5  }
     4.6  
     4.7 +gboolean
     4.8 +gmyth_scheduler_connect (GMythScheduler *scheduler, GMythBackendInfo *backend_info)
     4.9 +{
    4.10 +    return gmyth_scheduler_connect_with_timeout (scheduler, backend_info, 0);
    4.11 +}
    4.12 +
    4.13  /** Connects to the Mysql database in the backend. The backend address
    4.14   * is loaded from the GMythSettings instance.
    4.15   * 
    4.16 @@ -141,7 +147,8 @@
    4.17   * @return true if connection was success, false if failed.
    4.18   */
    4.19  gboolean
    4.20 -gmyth_scheduler_connect (GMythScheduler *scheduler, GMythBackendInfo *backend_info)
    4.21 +gmyth_scheduler_connect_with_timeout (GMythScheduler *scheduler,
    4.22 +	       GMythBackendInfo *backend_info, guint timeout)
    4.23  {
    4.24      assert(scheduler);
    4.25      g_return_val_if_fail (backend_info != NULL, FALSE);
    4.26 @@ -154,7 +161,8 @@
    4.27          scheduler->msqlquery = gmyth_query_new ();		
    4.28      }
    4.29  
    4.30 -    if (!gmyth_query_connect(scheduler->msqlquery, scheduler->backend_info)) {
    4.31 +    if (!gmyth_query_connect_with_timeout (scheduler->msqlquery, 
    4.32 +			    scheduler->backend_info, timeout)) {
    4.33      	g_warning ("[%s] Error while connecting to db", __FUNCTION__);
    4.34          return FALSE;
    4.35      }
     5.1 --- a/gmyth/src/gmyth_scheduler.h	Wed Jan 10 20:52:55 2007 +0000
     5.2 +++ b/gmyth/src/gmyth_scheduler.h	Wed Jan 10 21:47:24 2007 +0000
     5.3 @@ -136,6 +136,8 @@
     5.4  
     5.5  GMythScheduler* gmyth_scheduler_new ();
     5.6  gboolean        gmyth_scheduler_connect      (GMythScheduler *scheduler, GMythBackendInfo *backend_info);
     5.7 +gboolean        gmyth_scheduler_connect_with_timeout      (GMythScheduler *scheduler, 
     5.8 +		GMythBackendInfo *backend_info, guint timeout);
     5.9  gboolean        gmyth_scheduler_disconnect   (GMythScheduler *scheduler);
    5.10  
    5.11  gint            gmyth_scheduler_get_schedule_list (GMythScheduler *scheduler, 
     6.1 --- a/gmyth/tests/gmyth_test_connection.c	Wed Jan 10 20:52:55 2007 +0000
     6.2 +++ b/gmyth/tests/gmyth_test_connection.c	Wed Jan 10 21:47:24 2007 +0000
     6.3 @@ -25,7 +25,7 @@
     6.4  {
     6.5      GMythQuery *query = gmyth_query_new ();
     6.6  
     6.7 -    if (gmyth_query_connect (query, backend_info) == TRUE) {
     6.8 +    if (gmyth_query_connect_with_timeout (query, backend_info, 3) == TRUE) {
     6.9  	g_debug ("Mysql connection success");
    6.10  	return TRUE;
    6.11      } else {
    6.12 @@ -47,9 +47,8 @@
    6.13  
    6.14      backend_info = gmyth_backend_info_new_with_uri (argv[1]);
    6.15  
    6.16 +    test_mysql_connection1 (backend_info);
    6.17      test_backend_connection1 (backend_info);
    6.18 -
    6.19 -    test_mysql_connection1 (backend_info);
    6.20  }
    6.21  
    6.22