[svn r118] Added GMythBackendInfo class to fit our architecture needs trunk
authormelunko
Mon Nov 27 21:20:57 2006 +0000 (2006-11-27)
branchtrunk
changeset 117b90cf50ca3dc
parent 116 e3cedfae0f2e
child 118 1374c8f47f33
[svn r118] Added GMythBackendInfo class to fit our architecture needs
gmyth/src/Makefile.am
gmyth/src/gmyth_backendinfo.c
gmyth/src/gmyth_backendinfo.h
gmyth/src/gmyth_context.c
gmyth/src/gmyth_context.h
gmyth/src/gmyth_epg.c
gmyth/src/gmyth_epg.h
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_livetv.c
gmyth/src/gmyth_livetv.h
gmyth/src/gmyth_query.c
gmyth/src/gmyth_query.h
gmyth/src/gmyth_recorder.c
gmyth/src/gmyth_remote_util.c
gmyth/src/gmyth_remote_util.h
gmyth/src/gmyth_scheduler.c
gmyth/src/gmyth_scheduler.h
gmyth/src/gmyth_settings.c
gmyth/src/gmyth_settings.h
gmyth/src/gmyth_socket.c
gmyth/src/gmyth_socket.h
gmyth/src/gmyth_tvchain.c
gmyth/src/gmyth_tvchain.h
     1.1 --- a/gmyth/src/Makefile.am	Mon Nov 27 21:20:17 2006 +0000
     1.2 +++ b/gmyth/src/Makefile.am	Mon Nov 27 21:20:57 2006 +0000
     1.3 @@ -4,11 +4,9 @@
     1.4  
     1.5  libgmyth_la_SOURCES = 			\
     1.6  	gmyth_common.c				\
     1.7 -	gmyth_context.c				\
     1.8  	gmyth_epg.c 				\
     1.9  	gmyth_recorder.c		\
    1.10  	gmyth_remote_util.c			\
    1.11 -	gmyth_settings.c			\
    1.12  	gmyth_tvchain.c				\
    1.13  	gmyth_scheduler.c 			\
    1.14  	gmyth_util.c				\
    1.15 @@ -17,6 +15,7 @@
    1.16  	gmyth_stringlist.c			\
    1.17  	gmyth_file_transfer.c			\
    1.18  	gmyth_livetv.c				\
    1.19 +	gmyth_backendinfo.c			\
    1.20  	gmyth_uri.c
    1.21  
    1.22  libgmyth_la_CFLAGS = 			\
    1.23 @@ -44,11 +43,9 @@
    1.24  
    1.25  libgmyth_include_HEADERS =    	\
    1.26  	gmyth_common.h	 			\
    1.27 -	gmyth_context.h 			\
    1.28  	gmyth_epg.h 				\
    1.29  	gmyth_recorder.h 		\
    1.30  	gmyth_scheduler.h 			\
    1.31 -	gmyth_settings.h 			\
    1.32  	gmyth_tvchain.h 			\
    1.33  	gmyth_util.h 				\
    1.34  	gmyth_query.h 				\
    1.35 @@ -57,6 +54,7 @@
    1.36  	gmyth_stringlist.h 			\
    1.37  	gmyth_file_transfer.h			\
    1.38  	gmyth_livetv.h				\
    1.39 +	gmyth_backendinfo.h			\
    1.40  	gmyth_uri.h
    1.41  
    1.42  CLEANFILES = $(BUILT_SOURCES)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gmyth/src/gmyth_backendinfo.c	Mon Nov 27 21:20:57 2006 +0000
     2.3 @@ -0,0 +1,187 @@
     2.4 +
     2.5 +/**
     2.6 + * GMyth Library
     2.7 + *
     2.8 + * @file gmyth/gmyth_backend_info.c
     2.9 + * 
    2.10 + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    2.11 + * @author Hallyson Melo <hallyson.melo@indt.org.br>
    2.12 + *
    2.13 + *//*
    2.14 + * 
    2.15 + * This program is free software; you can redistribute it and/or modify
    2.16 + * it under the terms of the GNU Lesser General Public License as published by
    2.17 + * the Free Software Foundation; either version 2 of the License, or
    2.18 + * (at your option) any later version.
    2.19 + *
    2.20 + * This program is distributed in the hope that it will be useful,
    2.21 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.22 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.23 + * GNU General Public License for more details.
    2.24 + *
    2.25 + * You should have received a copy of the GNU Lesser General Public License
    2.26 + * along with this program; if not, write to the Free Software
    2.27 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.28 + */
    2.29 +
    2.30 +#include "gmyth_backendinfo.h"
    2.31 +
    2.32 +static void gmyth_backend_info_class_init  (GMythBackendInfoClass *klass);
    2.33 +static void gmyth_backend_info_init        (GMythBackendInfo *object);
    2.34 +
    2.35 +static void gmyth_backend_info_dispose  (GObject *object);
    2.36 +static void gmyth_backend_info_finalize (GObject *object);
    2.37 +
    2.38 +static gint get_record_id_from_database (GMythBackendInfo *scheduler);
    2.39 +static void update_backend  (gint record_id);
    2.40 +
    2.41 +G_DEFINE_TYPE(GMythBackendInfo, gmyth_backend_info, G_TYPE_OBJECT)
    2.42 +    
    2.43 +static void
    2.44 +gmyth_backend_info_class_init (GMythBackendInfoClass *klass)
    2.45 +{
    2.46 +    GObjectClass *gobject_class;
    2.47 +
    2.48 +    gobject_class = (GObjectClass *) klass;
    2.49 +
    2.50 +    gobject_class->dispose  = gmyth_backend_info_dispose;
    2.51 +    gobject_class->finalize = gmyth_backend_info_finalize;	
    2.52 +}
    2.53 +
    2.54 +static void
    2.55 +gmyth_backend_info_init (GMythBackendInfo *backend_info)
    2.56 +{
    2.57 +    backend_info->hostname = NULL;
    2.58 +    backend_info->username = NULL;
    2.59 +    backend_info->password = NULL;
    2.60 +    backend_info->db_name  = NULL;
    2.61 +    backend_info->port = -1;
    2.62 +}
    2.63 +
    2.64 +static void
    2.65 +gmyth_backend_info_dispose  (GObject *object)
    2.66 +{
    2.67 +    GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (object);
    2.68 +
    2.69 +    g_free (backend_info->hostname);
    2.70 +    g_free (backend_info->username);
    2.71 +    g_free (backend_info->password);
    2.72 +    g_free (backend_info->db_name);
    2.73 +
    2.74 +    backend_info->hostname = NULL;
    2.75 +    backend_info->username = NULL;
    2.76 +    backend_info->password = NULL;
    2.77 +    backend_info->db_name  = NULL;
    2.78 +    backend_info->port = -1;
    2.79 +
    2.80 +    G_OBJECT_CLASS (gmyth_backend_info_parent_class)->dispose (object);
    2.81 +}
    2.82 +
    2.83 +static void
    2.84 +gmyth_backend_info_finalize (GObject *object)
    2.85 +{
    2.86 +    g_signal_handlers_destroy (object);
    2.87 +
    2.88 +    G_OBJECT_CLASS (gmyth_backend_info_parent_class)->finalize (object);
    2.89 +}
    2.90 +
    2.91 +/** Creates a new instance of GMythBackendInfo.
    2.92 + * 
    2.93 + * @return a new instance of GMythBackendInfo.
    2.94 + */
    2.95 +GMythBackendInfo*
    2.96 +gmyth_backend_info_new ()
    2.97 +{
    2.98 +    GMythBackendInfo *backend_info = 
    2.99 +        GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
   2.100 +    
   2.101 +    return backend_info;
   2.102 +}
   2.103 +
   2.104 +GMythBackendInfo*
   2.105 +gmyth_backend_info_new_full (const char *hostname, const char *username,
   2.106 +	const char *password, const char *db_name, gint port)
   2.107 +{
   2.108 +    GMythBackendInfo *backend_info = 
   2.109 +        GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
   2.110 +    
   2.111 +    gmyth_backend_info_set_hostname (backend_info, hostname);
   2.112 +    gmyth_backend_info_set_username (backend_info, username);
   2.113 +    gmyth_backend_info_set_password (backend_info, password);
   2.114 +    gmyth_backend_info_set_db_name (backend_info, db_name);
   2.115 +    gmyth_backend_info_set_port (backend_info, port);
   2.116 +
   2.117 +    return backend_info;
   2.118 +}
   2.119 +
   2.120 +void
   2.121 +gmyth_backend_info_set_hostname (GMythBackendInfo *backend_info, const char *hostname)
   2.122 +{
   2.123 +    g_return_if_fail (backend_info != NULL);
   2.124 +
   2.125 +    backend_info->hostname = g_strdup (hostname);
   2.126 +}
   2.127 +
   2.128 +void
   2.129 +gmyth_backend_info_set_username (GMythBackendInfo *backend_info, const char *username)
   2.130 +{
   2.131 +    g_return_if_fail (backend_info != NULL);
   2.132 +
   2.133 +    backend_info->username = g_strdup (username);
   2.134 +}
   2.135 +
   2.136 +void
   2.137 +gmyth_backend_info_set_password (GMythBackendInfo *backend_info, const char *password)
   2.138 +{
   2.139 +    g_return_if_fail (backend_info != NULL);
   2.140 +
   2.141 +    backend_info->password = g_strdup (password);
   2.142 +}
   2.143 +
   2.144 +void
   2.145 +gmyth_backend_info_set_db_name (GMythBackendInfo *backend_info, const char *db_name)
   2.146 +{
   2.147 +    g_return_if_fail (backend_info != NULL);
   2.148 +
   2.149 +    backend_info->db_name = g_strdup (db_name);
   2.150 +}
   2.151 +
   2.152 +char*
   2.153 +gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info)
   2.154 +{
   2.155 +    g_return_val_if_fail (backend_info != NULL, NULL);
   2.156 +
   2.157 +    return backend_info->hostname;
   2.158 +}
   2.159 +
   2.160 +char*
   2.161 +gmyth_backend_info_get_username (GMythBackendInfo *backend_info)
   2.162 +{
   2.163 +    g_return_val_if_fail (backend_info != NULL, NULL);
   2.164 +
   2.165 +    return backend_info->username;
   2.166 +}
   2.167 +
   2.168 +char*
   2.169 +gmyth_backend_info_get_password (GMythBackendInfo *backend_info)
   2.170 +{
   2.171 +    g_return_val_if_fail (backend_info != NULL, NULL);
   2.172 +
   2.173 +    return backend_info->password;
   2.174 +}
   2.175 +
   2.176 +char*
   2.177 +gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info)
   2.178 +{
   2.179 +    g_return_val_if_fail (backend_info != NULL, NULL);
   2.180 +
   2.181 +    return backend_info->db_name;
   2.182 +}
   2.183 +
   2.184 +gint
   2.185 +gmyth_backend_info_get_port (GMythBackendInfo *backend_info)
   2.186 +{
   2.187 +    g_return_val_if_fail (backend_info != NULL, -1);
   2.188 +
   2.189 +    return backend_info->port;
   2.190 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gmyth/src/gmyth_backendinfo.h	Mon Nov 27 21:20:57 2006 +0000
     3.3 @@ -0,0 +1,88 @@
     3.4 +/**
     3.5 + * GMyth Library
     3.6 + *
     3.7 + * @file gmyth/gmyth_backend_info.h
     3.8 + * 
     3.9 + *
    3.10 + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    3.11 + * @author Hallyson Melo <hallyson.melo@indt.org.br>
    3.12 + *
    3.13 + *//*
    3.14 + * 
    3.15 + * This program is free software; you can redistribute it and/or modify
    3.16 + * it under the terms of the GNU Lesser General Public License as published by
    3.17 + * the Free Software Foundation; either version 2 of the License, or
    3.18 + * (at your option) any later version.
    3.19 + *
    3.20 + * This program is distributed in the hope that it will be useful,
    3.21 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.22 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.23 + * GNU General Public License for more details.
    3.24 + *
    3.25 + * You should have received a copy of the GNU Lesser General Public License
    3.26 + * along with this program; if not, write to the Free Software
    3.27 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.28 + */
    3.29 +
    3.30 +#ifndef __GMYTH_BACKEND_INFO_H__
    3.31 +#define __GMYTH_BACKEND_INFO_H__
    3.32 +
    3.33 +#include <glib-object.h>
    3.34 +
    3.35 +G_BEGIN_DECLS
    3.36 +
    3.37 +#define GMYTH_BACKEND_INFO_TYPE               (gmyth_backend_info_get_type ())
    3.38 +#define GMYTH_BACKEND_INFO(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_BACKEND_INFO_TYPE, GMythBackendInfo))
    3.39 +#define GMYTH_BACKEND_INFO_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_BACKEND_INFO_TYPE, GMythBackendInfoClass))
    3.40 +#define IS_GMYTH_BACKEND_INFO(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_BACKEND_INFO_TYPE))
    3.41 +#define IS_GMYTH_BACKEND_INFO_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_BACKEND_INFO_TYPE))
    3.42 +#define GMYTH_BACKEND_INFO_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_BACKEND_INFO_TYPE, GMythBackendInfoClass))
    3.43 +
    3.44 +
    3.45 +typedef struct _GMythBackendInfo         GMythBackendInfo;
    3.46 +typedef struct _GMythBackendInfoClass    GMythBackendInfoClass;
    3.47 +
    3.48 +struct _GMythBackendInfoClass
    3.49 +{
    3.50 +  GObjectClass parent_class;
    3.51 +
    3.52 +  /* callbacks */
    3.53 +  /* no one for now */
    3.54 +};
    3.55 +
    3.56 +struct _GMythBackendInfo
    3.57 +{
    3.58 +    GObject parent;
    3.59 +
    3.60 +    gchar *hostname;
    3.61 +    gchar *username;
    3.62 +    gchar *password;
    3.63 +    gchar *db_name;
    3.64 +    gint port;
    3.65 +};
    3.66 +
    3.67 +
    3.68 +GType           gmyth_backend_info_get_type (void);
    3.69 +
    3.70 +GMythBackendInfo* gmyth_backend_info_new ();
    3.71 +GMythBackendInfo* gmyth_backend_info_new_full (
    3.72 +	const char *hostname, const char *username, const char *password,
    3.73 +	const char *db_name, gint port);
    3.74 +
    3.75 +void gmyth_backend_info_set_hostname (GMythBackendInfo *backend_info, const char *hostname);
    3.76 +void gmyth_backend_info_set_username (GMythBackendInfo *backend_info, const char *username);
    3.77 +void gmyth_backend_info_set_password (GMythBackendInfo *backend_info, const char *password);
    3.78 +void gmyth_backend_info_set_db_name (GMythBackendInfo *backend_info, const char *db_name);
    3.79 +void gmyth_backend_info_set_port (GMythBackendInfo *backend_info, gint port);
    3.80 +
    3.81 +char* gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info);
    3.82 +char* gmyth_backend_info_get_username (GMythBackendInfo *backend_info);
    3.83 +char* gmyth_backend_info_get_password (GMythBackendInfo *backend_info);
    3.84 +char* gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info);
    3.85 +gint gmyth_backend_info_get_port (GMythBackendInfo *backend_info);
    3.86 +
    3.87 +
    3.88 +G_END_DECLS
    3.89 +
    3.90 +#endif /* __GMYTH_BACKEND_INFO_H__ */
    3.91 +
     4.1 --- a/gmyth/src/gmyth_context.c	Mon Nov 27 21:20:17 2006 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,311 +0,0 @@
     4.4 -/**
     4.5 - * GMyth Library
     4.6 - *
     4.7 - * @file gmyth/gmyth_context.c
     4.8 - * 
     4.9 - * @brief <p> GMythContext class contains general attributes and functions
    4.10 - * that express the connection state of each mythtvfrontend.
    4.11 - *
    4.12 - * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    4.13 - * @author Hallyson Luiz de Morais Melo <hallyson.melo@indt.org.br>
    4.14 - *
    4.15 - *//*
    4.16 - * 
    4.17 - * This program is free software; you can redistribute it and/or modify
    4.18 - * it under the terms of the GNU Lesser General Public License as published by
    4.19 - * the Free Software Foundation; either version 2 of the License, or
    4.20 - * (at your option) any later version.
    4.21 - *
    4.22 - * This program is distributed in the hope that it will be useful,
    4.23 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.24 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.25 - * GNU General Public License for more details.
    4.26 - *
    4.27 - * You should have received a copy of the GNU Lesser General Public License
    4.28 - * along with this program; if not, write to the Free Software
    4.29 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.30 - */
    4.31 -
    4.32 -#include "gmyth_context.h"
    4.33 -
    4.34 -#include <arpa/inet.h>
    4.35 -#include <sys/types.h>
    4.36 -#include <sys/socket.h>
    4.37 -#include <netdb.h>
    4.38 -#include <errno.h>
    4.39 -#include <stdlib.h>
    4.40 -
    4.41 -#include "gmyth_query.h"
    4.42 -#include "gmyth_socket.h"
    4.43 -
    4.44 -static void gmyth_context_class_init          (GMythContextClass *klass);
    4.45 -static void gmyth_context_init                (GMythContext *object);
    4.46 -
    4.47 -static void gmyth_context_dispose  (GObject *object);
    4.48 -static void gmyth_context_finalize (GObject *object);
    4.49 -
    4.50 -
    4.51 -G_DEFINE_TYPE(GMythContext, gmyth_context, G_TYPE_OBJECT)
    4.52 -
    4.53 -static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
    4.54 -
    4.55 -static GMythContext *gcontext = NULL; 
    4.56 -
    4.57 -static void
    4.58 -gmyth_context_class_init (GMythContextClass *klass)
    4.59 -{
    4.60 -	GObjectClass *gobject_class;
    4.61 -
    4.62 -	gobject_class = (GObjectClass *) klass;
    4.63 -
    4.64 -	gobject_class->dispose  = gmyth_context_dispose;
    4.65 -	gobject_class->finalize = gmyth_context_finalize;	
    4.66 -}
    4.67 -
    4.68 -static void
    4.69 -gmyth_context_init (GMythContext *gmyth_context)
    4.70 -{
    4.71 -
    4.72 -}
    4.73 -
    4.74 -static void
    4.75 -gmyth_context_dispose  (GObject *object)
    4.76 -{
    4.77 -	GMythContext *gmyth_context = GMYTH_CONTEXT(object);
    4.78 -
    4.79 -	if ( gmyth_context->gmyth_settings != NULL ) {
    4.80 -		g_object_unref (gmyth_context->gmyth_settings);	
    4.81 -		gmyth_context->gmyth_settings = NULL;
    4.82 -	}
    4.83 -
    4.84 -	if ( gmyth_context->localhostname != NULL ) {
    4.85 -		g_string_free ( gmyth_context->localhostname, TRUE );
    4.86 -		gmyth_context->localhostname = NULL;
    4.87 -	}
    4.88 -
    4.89 -	if (gmyth_context->server_socket != NULL) {
    4.90 -		g_object_unref (gmyth_context->server_socket);
    4.91 -		gmyth_context->server_socket = NULL;
    4.92 -	}
    4.93 -
    4.94 -	G_OBJECT_CLASS (gmyth_context_parent_class)->dispose (object);
    4.95 -}
    4.96 -
    4.97 -static void
    4.98 -gmyth_context_finalize (GObject *object)
    4.99 -{
   4.100 -	g_signal_handlers_destroy (object);
   4.101 -
   4.102 -	G_OBJECT_CLASS (gmyth_context_parent_class)->finalize (object);
   4.103 -}
   4.104 -
   4.105 -/** Gets the some important address translation info, 
   4.106 - * from the client socket that will open a connection.
   4.107 - *
   4.108 - * @return gint error number
   4.109 - */
   4.110 -static gint
   4.111 -myth_context_toaddrinfo( gchar *addr, gint port, struct addrinfo **addrInfo )
   4.112 -{
   4.113 -	struct addrinfo hints;
   4.114 -	gchar *portStr = g_strnfill( 32, ' ' );
   4.115 -	gint errorn = EADDRNOTAVAIL;
   4.116 -
   4.117 -	memset( &hints, 0, sizeof(hints) );
   4.118 -	hints.ai_family = AF_INET;
   4.119 -	hints.ai_socktype = SOCK_STREAM;
   4.120 -
   4.121 -	/* hints.ai_flags = AI_NUMERICHOST; */
   4.122 -	if ( port != -1 )
   4.123 -		sprintf(portStr, "%d", port);
   4.124 -	else
   4.125 -		portStr = NULL;
   4.126 -
   4.127 -	g_debug( "[%s] Address: %s, port: %s\n", __FUNCTION__, addr, portStr );
   4.128 -	if ( ( errorn = getaddrinfo(addr, portStr, &hints, addrInfo) ) != 0 ) {
   4.129 -		g_printerr( "[%s] Socket ERROR: %s\n", __FUNCTION__, gai_strerror(errorn) );
   4.130 -	}
   4.131 -
   4.132 -	return errorn;
   4.133 -
   4.134 -}
   4.135 -
   4.136 -/** Initializes the GMythContext object. It reads local system information
   4.137 - * load gmyth user settings and start connection to the database.
   4.138 - * 
   4.139 - * @return TRUE if initialization was successfull, 
   4.140 - * FALSE if any error happens.
   4.141 - */
   4.142 -gboolean
   4.143 -gmyth_context_initialize ()
   4.144 -{
   4.145 -	GString *localhost = NULL;
   4.146 -
   4.147 -	if (gcontext == NULL) {
   4.148 -		gcontext = GMYTH_CONTEXT ( g_object_new (GMYTH_CONTEXT_TYPE, FALSE));
   4.149 -	}
   4.150 -
   4.151 -	localhost = gmyth_socket_get_local_hostname( );
   4.152 -
   4.153 -	if (localhost==NULL || localhost->len <=0 ) {
   4.154 -		g_warning ("[%s] Could not determine local hostname. Setting to 127.0.0.1", __FUNCTION__);
   4.155 -		gcontext->localhostname = g_string_new ("127.0.0.1");
   4.156 -	} else {
   4.157 -		gcontext->localhostname = localhost;
   4.158 -	}
   4.159 -
   4.160 -	if (gcontext->gmyth_settings) {
   4.161 -		g_object_unref (gcontext->gmyth_settings);	
   4.162 -		gcontext->gmyth_settings = NULL;
   4.163 -	}
   4.164 -
   4.165 -	gcontext->gmyth_settings = gmyth_settings_new ();
   4.166 -	if (!gmyth_settings_load (gcontext->gmyth_settings)) {
   4.167 -		g_warning ("GMythContext: Settings file not opened!\n");	
   4.168 -	} else {
   4.169 -		g_debug ("GMythContext: Settings file loaded");
   4.170 -	}
   4.171 -
   4.172 -	if (gcontext->server_socket != NULL) {
   4.173 -		g_object_unref (gcontext->server_socket);
   4.174 -		gcontext->server_socket = NULL;
   4.175 -	}
   4.176 -
   4.177 -	GString *server_hostname = 
   4.178 -        gmyth_settings_get_backend_hostname(gcontext->gmyth_settings);
   4.179 -	int server_port = gmyth_settings_get_backend_port(gcontext->gmyth_settings);
   4.180 -
   4.181 -	gcontext->server_socket = gmyth_socket_new ();
   4.182 -	if (!gmyth_socket_connect_to_backend ( gcontext->server_socket,
   4.183 -				server_hostname->str, server_port, FALSE)) {
   4.184 -		g_warning ("[%s] Socket connection to backend error!", __FUNCTION__);
   4.185 -		g_object_unref (gcontext->server_socket);
   4.186 -		gcontext->server_socket = NULL;
   4.187 -		return FALSE;	
   4.188 -	}
   4.189 -
   4.190 -	return TRUE;
   4.191 -}
   4.192 -
   4.193 -/** Formats a Mythtv protocol command based on strlist and sends it to
   4.194 - * the connected backend. The backend response is overwritten into strlist.
   4.195 - * 
   4.196 - * @param strlist the string list to be sent, 
   4.197 - * and on which the answer will be written.
   4.198 - * @return TRUE if command was sent and an answer was received, FALSE if any
   4.199 - * error happens.
   4.200 - */
   4.201 -gboolean
   4.202 -gmyth_context_send_receive_stringlist (GMythStringList *strlist)
   4.203 -{
   4.204 -	gint ok = -1;
   4.205 -
   4.206 -	if (!gcontext || !(gcontext->server_socket)) {
   4.207 -		g_warning ("[%s] GMythContext not initialized", __FUNCTION__);
   4.208 -		return FALSE;
   4.209 -	}
   4.210 -
   4.211 -	//g_static_mutex_lock( &mutex );
   4.212 -
   4.213 -	ok = gmyth_socket_sendreceive_stringlist (gcontext->server_socket, strlist);
   4.214 -
   4.215 -	//g_static_mutex_unlock( &mutex );
   4.216 -
   4.217 -	if (!ok) {
   4.218 -		g_warning ("Connection to backend server lost");
   4.219 -	}
   4.220 -
   4.221 -	return (ok ? TRUE : FALSE);
   4.222 -}
   4.223 -
   4.224 -/** Gets the GMythSettings object associated to this context.
   4.225 - * 
   4.226 - * @return The GMythSettings object currently valid or NULL if the settings
   4.227 - * were not opened.
   4.228 - */
   4.229 -GMythSettings*
   4.230 -gmyth_context_get_settings ()
   4.231 -{
   4.232 -	if (!gcontext) {
   4.233 -		g_warning ("[%s] GMythContext not initialized\n", __FUNCTION__);
   4.234 -		return NULL;
   4.235 -	}
   4.236 -
   4.237 -	return gcontext->gmyth_settings;
   4.238 -}
   4.239 -
   4.240 -/** Gets the machine local hostname.
   4.241 - * 
   4.242 - * @param hostname a valid GString object to be overwritten with the local
   4.243 - * hostname.
   4.244 - * @return true if the hostname was read, false if any error happened.
   4.245 - */
   4.246 -gboolean
   4.247 -gmyth_context_get_local_hostname (GString *hostname)
   4.248 -{
   4.249 -	if (!hostname) {
   4.250 -		g_warning ("[%s] Received null argument", __FUNCTION__);
   4.251 -		return FALSE;
   4.252 -	}
   4.253 -
   4.254 -	g_string_assign (hostname, gcontext->localhostname->str);
   4.255 -
   4.256 -	return TRUE;
   4.257 -}
   4.258 -
   4.259 -/** Gets a setting information from the backend mysql database.
   4.260 - * 
   4.261 - * @param key The setting key to be retrieved.
   4.262 - * @param host the hostname associated to the desired setting.
   4.263 - * @param default_value the default setting value if could not query from
   4.264 - * backend database.
   4.265 - * @return The setting value loaded from database, or the given default value
   4.266 - * if the query fails.
   4.267 - */
   4.268 -GString*
   4.269 -gmyth_context_get_setting_onhost (GString *key, GString *host, GString *default_value)
   4.270 -{
   4.271 -	GString *query_str;
   4.272 -
   4.273 -	// TODO: Reuse msql query in gmyth_context
   4.274 -	GMythQuery *gmyth_query = gmyth_query_new ();
   4.275 -
   4.276 -	if (gmyth_query_connect (gmyth_query)) {
   4.277 -		MYSQL_RES *msql_res;
   4.278 -		MYSQL_ROW msql_row;
   4.279 -
   4.280 -		query_str = g_string_new ("");
   4.281 -		g_string_printf (query_str, "SELECT data FROM settings WHERE value = \"%s\" "
   4.282 -				"AND hostname = \"%s\" ;", key->str, host->str);
   4.283 -
   4.284 -		msql_res = gmyth_query_process_statement (gmyth_query, query_str->str);
   4.285 -		if (msql_res) {
   4.286 -			msql_row = mysql_fetch_row (msql_res);
   4.287 -			if (msql_row != NULL) {
   4.288 -				return g_string_new (msql_row[0]);
   4.289 -			}
   4.290 -		}
   4.291 -
   4.292 -		g_object_unref (gmyth_query);
   4.293 -	} else {
   4.294 -		g_warning ("Database not open while trying to load setting: %s", key->str);
   4.295 -	}
   4.296 -
   4.297 -	return default_value;
   4.298 -}
   4.299 -
   4.300 -/** Verify if the context is currently connected to a backend.
   4.301 - * 
   4.302 - * @return true if connection was opened, false if not.
   4.303 - */
   4.304 -gboolean
   4.305 -gmyth_context_check_connection ()
   4.306 -{
   4.307 -	// FIXME: Check this based on socket states
   4.308 -	if (!gcontext) {
   4.309 -		g_warning ("[%s] GMythContext not initialized", __FUNCTION__);
   4.310 -		return FALSE;
   4.311 -	}
   4.312 -
   4.313 -	return (gcontext->server_socket != NULL);
   4.314 -}
     5.1 --- a/gmyth/src/gmyth_context.h	Mon Nov 27 21:20:17 2006 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,88 +0,0 @@
     5.4 -/**
     5.5 - * GMyth Library
     5.6 - *
     5.7 - * @file gmyth/gmyth_context.h
     5.8 - * 
     5.9 - * @brief <p> GMythContext class contains general attributes and functions
    5.10 - * that express the connection state of each mythtvfrontend.
    5.11 - *
    5.12 - * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    5.13 - * @author Hallyson Luiz de Morais Melo <hallyson.melo@indt.org.br>
    5.14 - *
    5.15 - *//*
    5.16 - * 
    5.17 - * This program is free software; you can redistribute it and/or modify
    5.18 - * it under the terms of the GNU Lesser General Public License as published by
    5.19 - * the Free Software Foundation; either version 2 of the License, or
    5.20 - * (at your option) any later version.
    5.21 - *
    5.22 - * This program is distributed in the hope that it will be useful,
    5.23 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.24 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.25 - * GNU General Public License for more details.
    5.26 - *
    5.27 - * You should have received a copy of the GNU Lesser General Public License
    5.28 - * along with this program; if not, write to the Free Software
    5.29 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.30 - */
    5.31 -
    5.32 -#ifndef __GMYTH_CONTEXT_H__
    5.33 -#define __GMYTH_CONTEXT_H__
    5.34 -
    5.35 -#include <glib-object.h>
    5.36 -
    5.37 -#include "gmyth_settings.h"
    5.38 -#include "gmyth_socket.h"
    5.39 -#include "gmyth_stringlist.h"
    5.40 -
    5.41 -G_BEGIN_DECLS
    5.42 -
    5.43 -#define GMYTH_CONTEXT_TYPE               (gmyth_context_get_type ())
    5.44 -#define GMYTH_CONTEXT(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_CONTEXT_TYPE, GMythContext))
    5.45 -#define GMYTH_CONTEXT_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_CONTEXT_TYPE, GMythContextClass))
    5.46 -#define IS_GMYTH_CONTEXT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_CONTEXT_TYPE))
    5.47 -#define IS_GMYTH_CONTEXT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_CONTEXT_TYPE))
    5.48 -#define GMYTH_CONTEXT_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_CONTEXT_TYPE, GMythContextClass))
    5.49 -
    5.50 -#define MYTHTV_VERSION_DEFAULT          30
    5.51 -
    5.52 -typedef struct _GMythContext         GMythContext;
    5.53 -typedef struct _GMythContextClass    GMythContextClass;
    5.54 -
    5.55 -struct _GMythContextClass
    5.56 -{
    5.57 -  GObjectClass parent_class;
    5.58 -
    5.59 -  /* callbacks */
    5.60 -  /* no one for now */
    5.61 -};
    5.62 -
    5.63 -struct _GMythContext
    5.64 -{
    5.65 -    GObject parent;
    5.66 -
    5.67 -	GMythSettings *gmyth_settings;
    5.68 -	GMythSocket *server_socket;  
    5.69 -	
    5.70 -	GString *localhostname;
    5.71 -};
    5.72 -
    5.73 -
    5.74 -GType           gmyth_context_get_type (void);
    5.75 -void            gmyth_context_create();
    5.76 -
    5.77 -gboolean gmyth_context_initialize ();
    5.78 -gboolean gmyth_context_check_connection ();
    5.79 -GMythSettings* gmyth_context_get_settings ();
    5.80 -
    5.81 -gboolean gmyth_context_send_receive_stringlist (GMythStringList *strlist);
    5.82 -
    5.83 -GString* gmyth_context_get_setting_onhost (GString *key, GString *host, GString *default_value);
    5.84 -gboolean gmyth_context_get_local_hostname (GString *hostname);
    5.85 -
    5.86 -GString* gmyth_context_get_setting_onhost (GString *key, GString *host, GString *default_value);
    5.87 -
    5.88 -
    5.89 -G_END_DECLS
    5.90 -
    5.91 -#endif /* __GMYTH_CONTEXT_H__ */
     6.1 --- a/gmyth/src/gmyth_epg.c	Mon Nov 27 21:20:17 2006 +0000
     6.2 +++ b/gmyth/src/gmyth_epg.c	Mon Nov 27 21:20:57 2006 +0000
     6.3 @@ -56,7 +56,7 @@
     6.4  static void
     6.5  gmyth_epg_init (GMythEPG *gmyth_epg)
     6.6  {
     6.7 -	gmyth_epg->sqlquery = gmyth_query_new ();
     6.8 +
     6.9  }
    6.10  
    6.11  static void
    6.12 @@ -70,7 +70,7 @@
    6.13  static void
    6.14  gmyth_epg_finalize (GObject *object)
    6.15  {
    6.16 -	g_signal_handlers_destroy (object);
    6.17 +    g_signal_handlers_destroy (object);
    6.18  
    6.19      G_OBJECT_CLASS (gmyth_epg_parent_class)->finalize (object);
    6.20  }
    6.21 @@ -95,16 +95,16 @@
    6.22   * @return true if connection was success, false if failed.
    6.23   */
    6.24  gboolean
    6.25 -gmyth_epg_connect (GMythEPG *gmyth_epg)
    6.26 +gmyth_epg_connect (GMythEPG *gmyth_epg, GMythBackendInfo *backend_info)
    6.27  {
    6.28 -	assert(gmyth_epg);
    6.29 +    assert(gmyth_epg);
    6.30  
    6.31 -	if (gmyth_epg->sqlquery	== NULL) {
    6.32 -		g_warning ("[%s] GMythEPG db initializing", __FUNCTION__);
    6.33 -	    gmyth_epg->sqlquery = gmyth_query_new ();		
    6.34 -	}
    6.35 +    if (gmyth_epg->sqlquery	== NULL) {
    6.36 +	g_debug ("[%s] Creating gmyth_query", __FUNCTION__);
    6.37 +        gmyth_epg->sqlquery = gmyth_query_new ( );
    6.38 +    }
    6.39  
    6.40 -    if (!gmyth_query_connect(gmyth_epg->sqlquery)) {
    6.41 +    if (!gmyth_query_connect(gmyth_epg->sqlquery, backend_info)) {
    6.42          g_warning ("[%s] Error while connecting to db", __FUNCTION__);
    6.43          return FALSE;
    6.44      }
     7.1 --- a/gmyth/src/gmyth_epg.h	Mon Nov 27 21:20:17 2006 +0000
     7.2 +++ b/gmyth/src/gmyth_epg.h	Mon Nov 27 21:20:57 2006 +0000
     7.3 @@ -65,7 +65,7 @@
     7.4  
     7.5  GMythEPG* gmyth_epg_new (void);
     7.6  
     7.7 -gboolean gmyth_epg_connect (GMythEPG *gmyth_epg);
     7.8 +gboolean gmyth_epg_connect (GMythEPG *gmyth_epg, GMythBackendInfo *backend_info);
     7.9  gboolean gmyth_epg_disconnect (GMythEPG *gmyth_epg);
    7.10  
    7.11  gint gmyth_epg_get_channel_list (GMythEPG *gmyth_epg, GList **glist_ptr);
     8.1 --- a/gmyth/src/gmyth_file_transfer.c	Mon Nov 27 21:20:17 2006 +0000
     8.2 +++ b/gmyth/src/gmyth_file_transfer.c	Mon Nov 27 21:20:57 2006 +0000
     8.3 @@ -37,7 +37,6 @@
     8.4  #include "gmyth_livetv.h"
     8.5  #include "gmyth_util.h"
     8.6  #include "gmyth_socket.h"
     8.7 -#include "gmyth_context.h"
     8.8  #include "gmyth_stringlist.h"
     8.9  
    8.10  #include <unistd.h>
    8.11 @@ -49,6 +48,7 @@
    8.12  #include <netdb.h>
    8.13  #include <errno.h>
    8.14  #include <stdlib.h>
    8.15 +#include <assert.h>
    8.16  
    8.17  #define GMYTHTV_QUERY_HEADER		"QUERY_FILETRANSFER "
    8.18  
    8.19 @@ -74,8 +74,6 @@
    8.20  #define GMYTHTV_ENABLE_DEBUG				1
    8.21  #endif
    8.22  
    8.23 -//static gboolean has_io_access = TRUE;
    8.24 -
    8.25  enum myth_sock_types {
    8.26    GMYTH_PLAYBACK_TYPE = 0,
    8.27    GMYTH_MONITOR_TYPE,
    8.28 @@ -92,8 +90,6 @@
    8.29  
    8.30  static GCond*				io_watcher_cond  = NULL;
    8.31  
    8.32 -static GMainContext *io_watcher_context = NULL;
    8.33 -
    8.34  static void gmyth_file_transfer_class_init          (GMythFileTransferClass *klass);
    8.35  static void gmyth_file_transfer_init                (GMythFileTransfer *object);
    8.36  
    8.37 @@ -101,7 +97,6 @@
    8.38  static void gmyth_file_transfer_finalize (GObject *object);
    8.39  
    8.40  static gboolean gmyth_connect_to_backend (GMythFileTransfer *transfer);
    8.41 -//static gboolean myth_init_io_watchers( GMythFileTransfer *transfer );
    8.42  
    8.43  void gmyth_file_transfer_close( GMythFileTransfer *transfer );
    8.44  
    8.45 @@ -674,3 +669,11 @@
    8.46    return TRUE;
    8.47  }
    8.48  
    8.49 +
    8.50 +guint64
    8.51 +gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer)
    8.52 +{
    8.53 +    assert (transfer);
    8.54 +    
    8.55 +    return transfer->filesize;
    8.56 +}
     9.1 --- a/gmyth/src/gmyth_livetv.c	Mon Nov 27 21:20:17 2006 +0000
     9.2 +++ b/gmyth/src/gmyth_livetv.c	Mon Nov 27 21:20:57 2006 +0000
     9.3 @@ -25,9 +25,9 @@
     9.4   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     9.5   */
     9.6   
     9.7 -#include "gmyth_context.h"
     9.8  #include "gmyth_remote_util.h"
     9.9  #include "gmyth_tvchain.h"
    9.10 +#include "gmyth_socket.h"
    9.11  
    9.12  #include "gmyth_livetv.h"
    9.13  #include "gmyth_file_transfer.h"
    9.14 @@ -111,25 +111,29 @@
    9.15  }
    9.16  
    9.17  gboolean
    9.18 -gmyth_livetv_setup ( GMythLiveTV *livetv )
    9.19 +gmyth_livetv_setup ( GMythLiveTV *livetv, GMythBackendInfo *backend_info )
    9.20  {
    9.21 -	GMythSettings *msettings = gmyth_context_get_settings ();
    9.22  	gboolean res = TRUE;
    9.23 +	char *hostname;
    9.24  
    9.25 -	livetv->is_livetv = TRUE;
    9.26 +	GMythSocket *socket = gmyth_socket_new ();
    9.27  
    9.28 -	res = gmyth_context_check_connection();
    9.29 +	// FIME: Implement this at gmyth_socket
    9.30 +	res = gmyth_socket_connect_to_backend (socket, backend_info->hostname,
    9.31 +			backend_info->port, TRUE);
    9.32  	if (!res) {
    9.33  		g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);	
    9.34  		res = FALSE;
    9.35  		goto error;
    9.36  	}
    9.37  
    9.38 -	livetv->backend_hostname = gmyth_settings_get_backend_hostname(msettings);
    9.39 -	livetv->backend_port = gmyth_settings_get_backend_port (msettings);
    9.40 +	livetv->is_livetv = TRUE;
    9.41  
    9.42 -	livetv->local_hostname  = g_string_new("");    
    9.43 -	gmyth_context_get_local_hostname (livetv->local_hostname);
    9.44 +	hostname = gmyth_backend_info_get_hostname(backend_info);
    9.45 +	livetv->backend_hostname = g_string_new (hostname);
    9.46 +	livetv->backend_port = gmyth_backend_info_get_port (backend_info);
    9.47 +
    9.48 +	livetv->local_hostname  = gmyth_socket_get_local_hostname ( );
    9.49  
    9.50  	if ( livetv->local_hostname == NULL ) {
    9.51  		res = FALSE;
    9.52 @@ -137,7 +141,8 @@
    9.53  	}
    9.54  
    9.55  	// Gets the recorder num
    9.56 -	livetv->recorder = remote_request_next_free_recorder (-1);
    9.57 +	livetv->recorder = remote_request_next_free_recorder (socket, -1);
    9.58 +	gmyth_socket_close_connection (socket);
    9.59  
    9.60  	if ( livetv->recorder == NULL ) {
    9.61  		g_warning ("[%s] None remote encoder available", __FUNCTION__);
    9.62 @@ -147,7 +152,7 @@
    9.63  
    9.64  	// Creates livetv chain handler
    9.65  	livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
    9.66 -	gmyth_tvchain_initialize ( livetv->tvchain, livetv->local_hostname );
    9.67 +	gmyth_tvchain_initialize ( livetv->tvchain, backend_info );
    9.68  
    9.69  	if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) {
    9.70  		res = FALSE;
    9.71 @@ -305,6 +310,7 @@
    9.72  	}
    9.73  }
    9.74  
    9.75 +// FIXME: put here just a wrapper function to call gmyth_recorder_is_recording()...
    9.76  gboolean
    9.77  gmyth_livetv_is_recording ( GMythLiveTV *livetv )
    9.78  {
    10.1 --- a/gmyth/src/gmyth_livetv.h	Mon Nov 27 21:20:17 2006 +0000
    10.2 +++ b/gmyth/src/gmyth_livetv.h	Mon Nov 27 21:20:57 2006 +0000
    10.3 @@ -33,6 +33,7 @@
    10.4  #include "gmyth_recorder.h"
    10.5  #include "gmyth_tvchain.h"
    10.6  #include "gmyth_common.h"
    10.7 +#include "gmyth_backendinfo.h"
    10.8  
    10.9  #include "gmyth_file_transfer.h"
   10.10  
   10.11 @@ -82,7 +83,7 @@
   10.12  gboolean gmyth_livetv_is_recording ( GMythLiveTV *livetv );
   10.13  	
   10.14  
   10.15 -gboolean gmyth_livetv_setup (GMythLiveTV *livetv);
   10.16 +gboolean gmyth_livetv_setup (GMythLiveTV *livetv, GMythBackendInfo *backend_info);
   10.17  gboolean gmyth_livetv_next_program_chain ( GMythLiveTV *livetv );
   10.18  
   10.19  #define G_END_DECLS
    11.1 --- a/gmyth/src/gmyth_query.c	Mon Nov 27 21:20:17 2006 +0000
    11.2 +++ b/gmyth/src/gmyth_query.c	Mon Nov 27 21:20:57 2006 +0000
    11.3 @@ -31,8 +31,6 @@
    11.4  #include <assert.h>
    11.5  
    11.6  #include "gmyth_query.h"
    11.7 -#include "gmyth_settings.h"
    11.8 -#include "gmyth_context.h"
    11.9  
   11.10  static void gmyth_query_class_init          (GMythQueryClass *klass);
   11.11  static void gmyth_query_init                (GMythQuery *object);
   11.12 @@ -47,7 +45,7 @@
   11.13  static void
   11.14  gmyth_query_class_init (GMythQueryClass *klass)
   11.15  {
   11.16 -	GObjectClass *gobject_class;
   11.17 +    GObjectClass *gobject_class;
   11.18  
   11.19      gobject_class = (GObjectClass *) klass;
   11.20  	
   11.21 @@ -58,12 +56,7 @@
   11.22  static void
   11.23  gmyth_query_init (GMythQuery *gmyth_query)
   11.24  {
   11.25 -	GMythSettings *gmyth_settings = gmyth_context_get_settings ();
   11.26 -	
   11.27 -    gmyth_query->opt_host_name = gmyth_settings_get_backend_hostname(gmyth_settings);
   11.28 -    gmyth_query->opt_user_name = gmyth_settings_get_username(gmyth_settings);
   11.29 -    gmyth_query->opt_password = gmyth_settings_get_password(gmyth_settings);
   11.30 -    gmyth_query->opt_db_name = gmyth_settings_get_dbname(gmyth_settings);
   11.31 +    gmyth_query->backend_info = NULL;
   11.32  
   11.33      /* initialize connection handler */
   11.34      gmyth_query->conn = mysql_init (NULL);
   11.35 @@ -78,16 +71,18 @@
   11.36  {
   11.37      GMythQuery *gmyth_query = GMYTH_QUERY (object);
   11.38      
   11.39 -    /* disconnect from server */
   11.40 -	gmyth_query_disconnect (gmyth_query);
   11.41 -	
   11.42 -	G_OBJECT_CLASS (gmyth_query_parent_class)->dispose (object);
   11.43 +    if (gmyth_query->backend_info) {
   11.44 +        g_object_unref (gmyth_query->backend_info);
   11.45 +	gmyth_query->backend_info = NULL;
   11.46 +    }	    
   11.47 +
   11.48 +    G_OBJECT_CLASS (gmyth_query_parent_class)->dispose (object);
   11.49  }
   11.50  
   11.51  static void
   11.52  gmyth_query_finalize (GObject *object)
   11.53  {
   11.54 -	g_signal_handlers_destroy (object);
   11.55 +    g_signal_handlers_destroy (object);
   11.56  
   11.57      G_OBJECT_CLASS (gmyth_query_parent_class)->finalize (object);
   11.58  }
   11.59 @@ -105,35 +100,35 @@
   11.60  }
   11.61  
   11.62  /** Connects to the Mysql database in the backend. The backend address
   11.63 - * is loaded from the GMythSettings instance.
   11.64 + * is loaded from the GMythBackendInfo instance.
   11.65   * 
   11.66   * @param gmyth_query the GMythEPG instance to be connected.
   11.67   * @return true if connection was success, false if failed.
   11.68   */
   11.69  gboolean
   11.70 -gmyth_query_connect (GMythQuery *gmyth_query) 
   11.71 +gmyth_query_connect (GMythQuery *gmyth_query, GMythBackendInfo *backend_info) 
   11.72  {
   11.73 -    char *opt_host_name;
   11.74 -    char *opt_user_name;
   11.75 -    char *opt_password;
   11.76 -    char *opt_db_name;
   11.77 +    assert(gmyth_query);
   11.78 +    g_return_val_if_fail (backend_info != NULL, FALSE);
   11.79 +    g_return_val_if_fail (backend_info->hostname != NULL, FALSE);
   11.80 +    g_return_val_if_fail (backend_info->username != NULL, FALSE);
   11.81 +    g_return_val_if_fail (backend_info->password != NULL, FALSE);
   11.82 +    g_return_val_if_fail (backend_info->db_name != NULL, FALSE);
   11.83 +    
   11.84 +    g_object_ref (backend_info);
   11.85 +    gmyth_query->backend_info = backend_info;
   11.86  
   11.87 -    assert(gmyth_query);
   11.88 -    
   11.89 -    opt_host_name   = (gmyth_query->opt_host_name ? gmyth_query->opt_host_name->str : NULL);
   11.90 -    opt_db_name     = (gmyth_query->opt_db_name ? gmyth_query->opt_db_name->str : NULL);
   11.91 -    opt_user_name   = (gmyth_query->opt_user_name ? gmyth_query->opt_user_name->str : NULL);
   11.92 -    opt_password    = (gmyth_query->opt_password ? gmyth_query->opt_password->str : NULL);
   11.93 -
   11.94 -    
   11.95      if (gmyth_query->conn == NULL) {
   11.96          gmyth_query_print_error (NULL, "mysql_init() failed (probably out of memory)");
   11.97          return FALSE;
   11.98      }
   11.99      
  11.100      /* connect to server */
  11.101 -    if (mysql_real_connect (gmyth_query->conn, opt_host_name, 
  11.102 -            opt_user_name, opt_password, opt_db_name, 
  11.103 +    if (mysql_real_connect (gmyth_query->conn, 
  11.104 +	    gmyth_query->backend_info->hostname, 
  11.105 +            gmyth_query->backend_info->username,
  11.106 +	    gmyth_query->backend_info->password,
  11.107 +	    gmyth_query->backend_info->db_name, 
  11.108              0, NULL, 0) == NULL) {
  11.109              	
  11.110          gmyth_query_print_error (gmyth_query->conn, "mysql_real_connect() failed");
    12.1 --- a/gmyth/src/gmyth_query.h	Mon Nov 27 21:20:17 2006 +0000
    12.2 +++ b/gmyth/src/gmyth_query.h	Mon Nov 27 21:20:57 2006 +0000
    12.3 @@ -34,6 +34,8 @@
    12.4  /* MYSQL includes */
    12.5  #include <mysql.h>
    12.6  
    12.7 +#include "gmyth_backendinfo.h"
    12.8 +
    12.9  G_BEGIN_DECLS
   12.10  
   12.11  #define GMYTH_QUERY_TYPE               (gmyth_query_get_type ())
   12.12 @@ -59,24 +61,22 @@
   12.13  {
   12.14      GObject parent;
   12.15    
   12.16 -    GString *opt_host_name; /* server host (default=localhost) */
   12.17 -    GString *opt_user_name; /* username (default=login name) */
   12.18 -    GString *opt_password; /* password (default=none) */
   12.19 -    unsigned int opt_port_num; /* port number (use built-in value) */
   12.20 +    GMythBackendInfo *backend_info;
   12.21 +
   12.22      GString *opt_socket_name; /* socket name (use built-in value) */
   12.23 -    GString *opt_db_name; /* database name (default=none) */
   12.24      unsigned int opt_flags; /* connection flags (none) */
   12.25 +
   12.26      MYSQL *conn; /* pointer to connection handler */  
   12.27  };
   12.28  
   12.29  
   12.30  GType gmyth_query_get_type (void);
   12.31  
   12.32 -GMythQuery* gmyth_query_new ();
   12.33 +GMythQuery* gmyth_query_new ( );
   12.34  MYSQL_RES * gmyth_query_process_statement 
   12.35                  (GMythQuery *gmyth_query, char *stmt_str);
   12.36  
   12.37 -gboolean gmyth_query_connect (GMythQuery *gmyth_query);
   12.38 +gboolean gmyth_query_connect (GMythQuery *gmyth_query, GMythBackendInfo *backend_info);
   12.39  gboolean gmyth_query_disconnect (GMythQuery *gmyth_query);
   12.40  
   12.41  G_END_DECLS
    13.1 --- a/gmyth/src/gmyth_recorder.c	Mon Nov 27 21:20:17 2006 +0000
    13.2 +++ b/gmyth/src/gmyth_recorder.c	Mon Nov 27 21:20:57 2006 +0000
    13.3 @@ -219,7 +219,7 @@
    13.4  	GMythStringList *str_list;
    13.5  	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
    13.6  	
    13.7 -	g_debug ( "[%s] FRONTEND_READY with recorder id = %d\n", __FUNCTION__, recorder->recorder_num );
    13.8 +	g_debug ( "[%s] FRONTEND_READY with recorder id = %d", __FUNCTION__, recorder->recorder_num );
    13.9  	
   13.10  	str_list = gmyth_string_list_new ();
   13.11  	
    14.1 --- a/gmyth/src/gmyth_remote_util.c	Mon Nov 27 21:20:17 2006 +0000
    14.2 +++ b/gmyth/src/gmyth_remote_util.c	Mon Nov 27 21:20:57 2006 +0000
    14.3 @@ -27,7 +27,6 @@
    14.4  
    14.5  #include "gmyth_remote_util.h"
    14.6   
    14.7 -#include "gmyth_context.h"
    14.8  #include "gmyth_recorder.h"
    14.9  #include "gmyth_stringlist.h"
   14.10  
   14.11 @@ -37,20 +36,20 @@
   14.12   * @return the remote encoder instance available, or NULL if any error happens.
   14.13   */
   14.14  GMythRecorder*
   14.15 -remote_request_next_free_recorder (int curr)
   14.16 +remote_request_next_free_recorder (GMythSocket *socket, int curr)
   14.17  {
   14.18 -	GMythRecorder *recorder = NULL;
   14.19 -	GString *hostname;
   14.20 -	int num, port;
   14.21 +    GMythRecorder *recorder = NULL;
   14.22 +    GString *hostname;
   14.23 +    int num, port;
   14.24  	
   14.25 -	GMythStringList *strlist = gmyth_string_list_new();
   14.26 +    GMythStringList *strlist = gmyth_string_list_new();
   14.27  	
   14.28 -	g_debug ("[%s] Request next free recorder in the backend", __FUNCTION__);
   14.29 +    g_debug ("[%s] Request next free recorder in the backend", __FUNCTION__);
   14.30  	
   14.31      gmyth_string_list_append_char_array (strlist, "GET_NEXT_FREE_RECORDER");
   14.32      gmyth_string_list_append_int (strlist, curr);
   14.33  
   14.34 -    if (!gmyth_context_send_receive_stringlist(strlist)) {
   14.35 +    if (!gmyth_socket_sendreceive_stringlist(socket, strlist)) {
   14.36      	g_warning ("GET_NEXT_FREE_RECORDER request error!\n");
   14.37          return NULL;
   14.38      }
    15.1 --- a/gmyth/src/gmyth_remote_util.h	Mon Nov 27 21:20:17 2006 +0000
    15.2 +++ b/gmyth/src/gmyth_remote_util.h	Mon Nov 27 21:20:57 2006 +0000
    15.3 @@ -30,10 +30,11 @@
    15.4  
    15.5  #include <glib.h>
    15.6  #include "gmyth_recorder.h"
    15.7 +#include "gmyth_socket.h"
    15.8  
    15.9  G_BEGIN_DECLS
   15.10  
   15.11 -GMythRecorder* remote_request_next_free_recorder (int curr);
   15.12 +GMythRecorder* remote_request_next_free_recorder (GMythSocket *socket, int curr);
   15.13  
   15.14  G_END_DECLS
   15.15  
    16.1 --- a/gmyth/src/gmyth_scheduler.c	Mon Nov 27 21:20:17 2006 +0000
    16.2 +++ b/gmyth/src/gmyth_scheduler.c	Mon Nov 27 21:20:57 2006 +0000
    16.3 @@ -30,9 +30,9 @@
    16.4  
    16.5  #include "gmyth_scheduler.h"
    16.6  
    16.7 -#include "gmyth_context.h"
    16.8  #include "gmyth_util.h"
    16.9  #include "gmyth_query.h"
   16.10 +#include "gmyth_socket.h"
   16.11  
   16.12  static void gmyth_scheduler_class_init  (GMythSchedulerClass *klass);
   16.13  static void gmyth_scheduler_init        (GMythScheduler *object);
   16.14 @@ -41,14 +41,14 @@
   16.15  static void gmyth_scheduler_finalize (GObject *object);
   16.16  
   16.17  static gint get_record_id_from_database (GMythScheduler *scheduler);
   16.18 -static void update_backend  (gint record_id);
   16.19 +static void update_backend  (GMythScheduler *scheduler, gint record_id);
   16.20  
   16.21  G_DEFINE_TYPE(GMythScheduler, gmyth_scheduler, G_TYPE_OBJECT)
   16.22      
   16.23  static void
   16.24  gmyth_scheduler_class_init (GMythSchedulerClass *klass)
   16.25  {
   16.26 -	GObjectClass *gobject_class;
   16.27 +    GObjectClass *gobject_class;
   16.28  
   16.29      gobject_class = (GObjectClass *) klass;
   16.30  
   16.31 @@ -59,7 +59,7 @@
   16.32  static void
   16.33  gmyth_scheduler_init (GMythScheduler *sched)
   16.34  {
   16.35 -	sched->recordid =0;
   16.36 +    sched->recordid =0;
   16.37      sched->type = 0;
   16.38      sched->search = 0;
   16.39      sched->profile =  g_string_new("");
   16.40 @@ -97,13 +97,20 @@
   16.41  static void
   16.42  gmyth_scheduler_dispose  (GObject *object)
   16.43  {
   16.44 -	G_OBJECT_CLASS (gmyth_scheduler_parent_class)->dispose (object);
   16.45 +    GMythScheduler *scheduler = GMYTH_SCHEDULER (object);
   16.46 +
   16.47 +    if (scheduler->backend_info) { 
   16.48 +	g_object_unref (scheduler->backend_info);
   16.49 +	scheduler->backend_info = NULL;
   16.50 +    }
   16.51 +
   16.52 +    G_OBJECT_CLASS (gmyth_scheduler_parent_class)->dispose (object);
   16.53  }
   16.54  
   16.55  static void
   16.56  gmyth_scheduler_finalize (GObject *object)
   16.57  {
   16.58 -	g_signal_handlers_destroy (object);
   16.59 +    g_signal_handlers_destroy (object);
   16.60  
   16.61      G_OBJECT_CLASS (gmyth_scheduler_parent_class)->finalize (object);
   16.62  }
   16.63 @@ -128,16 +135,20 @@
   16.64   * @return true if connection was success, false if failed.
   16.65   */
   16.66  gboolean
   16.67 -gmyth_scheduler_connect (GMythScheduler *scheduler)
   16.68 +gmyth_scheduler_connect (GMythScheduler *scheduler, GMythBackendInfo *backend_info)
   16.69  {
   16.70      assert(scheduler);
   16.71 +    g_return_val_if_fail (backend_info != NULL, FALSE);
   16.72 +    
   16.73 +    g_object_ref (backend_info);
   16.74 +    scheduler->backend_info = backend_info;
   16.75  
   16.76      if (scheduler->msqlquery == NULL) {
   16.77          g_warning ("[%s] GMythScheduler db initializing", __FUNCTION__);
   16.78  	    scheduler->msqlquery = gmyth_query_new ();		
   16.79  	}
   16.80  
   16.81 -    if (!gmyth_query_connect(scheduler->msqlquery)) {
   16.82 +    if (!gmyth_query_connect(scheduler->msqlquery, scheduler->backend_info)) {
   16.83      	g_warning ("[%s] Error while connecting to db", __FUNCTION__);
   16.84          return FALSE;
   16.85      }
   16.86 @@ -156,6 +167,7 @@
   16.87      assert(scheduler);
   16.88  
   16.89      if (scheduler->msqlquery != NULL) {
   16.90 +        gmyth_query_disconnect (scheduler->msqlquery);
   16.91          g_object_unref (scheduler->msqlquery);
   16.92      }
   16.93  
   16.94 @@ -171,8 +183,8 @@
   16.95  gint
   16.96  gmyth_scheduler_get_schedule_list ( GMythScheduler *scheduler, GList **schedule_list)
   16.97  {
   16.98 -	ScheduleInfo *schedule;
   16.99 -	MYSQL_RES *msql_res;
  16.100 +    ScheduleInfo *schedule;
  16.101 +    MYSQL_RES *msql_res;
  16.102      GString *query_str = g_string_new ("");
  16.103      GString *date_time = g_string_new ("");
  16.104      
  16.105 @@ -182,10 +194,10 @@
  16.106      	"SELECT recordid,programid,chanid,starttime,startdate,"
  16.107      	"endtime,enddate,title,subtitle,description,category FROM record;");
  16.108  
  16.109 -	if (scheduler->msqlquery == NULL) {
  16.110 -		g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
  16.111 -		return -1;
  16.112 -	}
  16.113 +    if (scheduler->msqlquery == NULL) {
  16.114 +	g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
  16.115 +	return -1;
  16.116 +    }
  16.117      msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
  16.118  
  16.119      if (msql_res == NULL) {
  16.120 @@ -237,8 +249,8 @@
  16.121  gint
  16.122  gmyth_scheduler_get_recorded_list (GMythScheduler *scheduler, GList **recorded_list)
  16.123  {
  16.124 -	RecordedInfo *record;
  16.125 -	MYSQL_RES *msql_res;
  16.126 +    RecordedInfo *record;
  16.127 +    MYSQL_RES *msql_res;
  16.128      GString *query_str = g_string_new ("");
  16.129      GString *date_time = g_string_new ("");
  16.130  	
  16.131 @@ -317,29 +329,29 @@
  16.132      struct tm start_tm;
  16.133      struct tm end_tm;
  16.134  
  16.135 -	MYSQL_RES *msql_res;
  16.136 +    MYSQL_RES *msql_res;
  16.137      GString *query_str = g_string_new ("");
  16.138  
  16.139      assert(scheduler);
  16.140      
  16.141 -	if (scheduler->msqlquery == NULL) {
  16.142 -		g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
  16.143 -		return 0;
  16.144 -	}
  16.145 +    if (scheduler->msqlquery == NULL) {
  16.146 +	g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
  16.147 +	return 0;
  16.148 +    }
  16.149  	
  16.150  	/* manipulating time */
  16.151 - 	if(localtime_r(&schedule_info->start_time, &start_tm) == NULL) {
  16.152 +    if(localtime_r(&schedule_info->start_time, &start_tm) == NULL) {
  16.153          g_warning ("localtime_r error in libgmyth scheduler!\n");
  16.154          return FALSE;                 
  16.155      }
  16.156          
  16.157 - 	if(localtime_r(&schedule_info->end_time, &end_tm) == NULL) {
  16.158 +    if(localtime_r(&schedule_info->end_time, &end_tm) == NULL) {
  16.159          g_warning ("localtime_r error in libgmyth scheduler!\n");
  16.160          return FALSE;
  16.161      }	
  16.162  	
  16.163 -	//TODO: verify if this funtion realy does what it should do!
  16.164 -	g_string_printf (query_str, "REPLACE INTO record "
  16.165 +    //TODO: verify if this funtion realy does what it should do!
  16.166 +    g_string_printf (query_str, "REPLACE INTO record "
  16.167  	    "(recordid, type, chanid, starttime, "
  16.168  	    "startdate, endtime, enddate, title,"
  16.169  	    "profile, recpriority, maxnewest, inactive, "
  16.170 @@ -383,7 +395,7 @@
  16.171  	    schedule_info->record_id = get_record_id_from_database(scheduler);
  16.172      
  16.173      /* Notify the backend of changes */
  16.174 -    update_backend(schedule_info->record_id);
  16.175 +    update_backend(scheduler, schedule_info->record_id);
  16.176      
  16.177      /* free allocated memory */
  16.178      mysql_free_result (msql_res);
  16.179 @@ -402,15 +414,15 @@
  16.180  gmyth_scheduler_delete_schedule (GMythScheduler *scheduler, gint record_id)
  16.181  {
  16.182  
  16.183 -	MYSQL_RES *msql_res;
  16.184 +    MYSQL_RES *msql_res;
  16.185      GString *query_str = g_string_new ("");
  16.186  
  16.187      assert(scheduler);
  16.188      
  16.189 -	if (scheduler->msqlquery == NULL) {
  16.190 -		g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
  16.191 -		return FALSE;
  16.192 -	}
  16.193 +    if (scheduler->msqlquery == NULL) {
  16.194 +	g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
  16.195 +	return FALSE;
  16.196 +    }
  16.197  
  16.198      //========================================
  16.199      g_string_printf (query_str, 
  16.200 @@ -423,12 +435,12 @@
  16.201      	return FALSE;
  16.202      }
  16.203  
  16.204 -	update_backend(record_id);// Notify the backend of the changes
  16.205 +    update_backend(scheduler, record_id);// Notify the backend of the changes
  16.206      
  16.207      mysql_free_result (msql_res);
  16.208      g_string_free(query_str, TRUE);
  16.209  
  16.210 -	return TRUE;
  16.211 +    return TRUE;
  16.212  }
  16.213  
  16.214  /** Requests the Mysql database in the backend to remove an existing recorded item.
  16.215 @@ -441,7 +453,8 @@
  16.216  gmyth_scheduler_delete_recorded (GMythScheduler *scheduler, gint record_id)
  16.217  {
  16.218  
  16.219 -	MYSQL_RES *msql_res;
  16.220 +    MYSQL_RES *msql_res;
  16.221 +
  16.222      GString *query_str = g_string_new ("");
  16.223  
  16.224      assert(scheduler);
  16.225 @@ -457,12 +470,12 @@
  16.226  
  16.227      msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
  16.228  
  16.229 -	update_backend(record_id);// Notify the backend of the changes
  16.230 +    update_backend(scheduler, record_id);// Notify the backend of the changes
  16.231      
  16.232      mysql_free_result (msql_res);
  16.233      g_string_free(query_str, TRUE);
  16.234  
  16.235 -	return TRUE;
  16.236 +    return TRUE;
  16.237  }
  16.238  
  16.239  /** Retrieves an existing recorded item information from database. The information
  16.240 @@ -595,15 +608,22 @@
  16.241   * @param record_id the id of the modified recording.
  16.242   */
  16.243  static void
  16.244 -update_backend(gint record_id)//fixme: put void and discovery record_id inside
  16.245 +update_backend(GMythScheduler *scheduler, gint record_id)//fixme: put void and discovery record_id inside
  16.246  {
  16.247 +    GMythSocket *socket;
  16.248      GMythStringList *strlist = gmyth_string_list_new ();
  16.249      GString *datastr = g_string_new ("RESCHEDULE_RECORDINGS ");
  16.250  
  16.251      g_string_append_printf (datastr, "%d", record_id);
  16.252      gmyth_string_list_append_string (strlist, datastr);
  16.253  
  16.254 -    gmyth_context_send_receive_stringlist (strlist);
  16.255 +    socket = gmyth_socket_new ();
  16.256 +    if (gmyth_socket_connect (socket, scheduler->backend_info->hostname,
  16.257 +			    scheduler->backend_info->port)) {
  16.258 +        gmyth_socket_sendreceive_stringlist (socket, strlist);
  16.259 +    } else {
  16.260 +	g_warning ("[%s] Connection to backend failed!", __FUNCTION__);
  16.261 +    }
  16.262      
  16.263      g_string_free(datastr, TRUE);
  16.264      g_object_unref(strlist);
    17.1 --- a/gmyth/src/gmyth_scheduler.h	Mon Nov 27 21:20:17 2006 +0000
    17.2 +++ b/gmyth/src/gmyth_scheduler.h	Mon Nov 27 21:20:57 2006 +0000
    17.3 @@ -34,6 +34,7 @@
    17.4  
    17.5  #include "gmyth_common.h"
    17.6  #include "gmyth_query.h"
    17.7 +#include "gmyth_backendinfo.h"
    17.8  
    17.9  G_BEGIN_DECLS
   17.10  
   17.11 @@ -93,6 +94,7 @@
   17.12      GString *searchForWhat;
   17.13      
   17.14      GMythQuery *msqlquery;
   17.15 +    GMythBackendInfo *backend_info;
   17.16  };
   17.17  
   17.18  typedef struct {
   17.19 @@ -131,7 +133,7 @@
   17.20  GType           gmyth_scheduler_get_type (void);
   17.21  
   17.22  GMythScheduler* gmyth_scheduler_new ();
   17.23 -gboolean        gmyth_scheduler_connect      (GMythScheduler *scheduler);
   17.24 +gboolean        gmyth_scheduler_connect      (GMythScheduler *scheduler, GMythBackendInfo *backend_info);
   17.25  gboolean        gmyth_scheduler_disconnect   (GMythScheduler *scheduler);
   17.26  
   17.27  gint            gmyth_scheduler_get_schedule_list (GMythScheduler *scheduler, 
    18.1 --- a/gmyth/src/gmyth_settings.c	Mon Nov 27 21:20:17 2006 +0000
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,417 +0,0 @@
    18.4 -/**
    18.5 - * GMyth Library
    18.6 - *
    18.7 - * @file gmyth/gmyth_settings.c
    18.8 - * 
    18.9 - * @brief <p> This component contains functions acessing and modifying 
   18.10 - * user and program settings.
   18.11 - * 
   18.12 - * The standard settings file is created in the user home folder, in the
   18.13 - * file ~/.gmyth/settings.dat.  
   18.14 - *
   18.15 - * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
   18.16 - * @author Alexsandro Jose Virginio dos Santos <alexsandro.santos@indt.org.br>
   18.17 - *
   18.18 - *//*
   18.19 - * 
   18.20 - * This program is free software; you can redistribute it and/or modify
   18.21 - * it under the terms of the GNU Lesser General Public License as published by
   18.22 - * the Free Software Foundation; either version 2 of the License, or
   18.23 - * (at your option) any later version.
   18.24 - *
   18.25 - * This program is distributed in the hope that it will be useful,
   18.26 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.27 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.28 - * GNU General Public License for more details.
   18.29 - *
   18.30 - * You should have received a copy of the GNU Lesser General Public License
   18.31 - * along with this program; if not, write to the Free Software
   18.32 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.33 - */
   18.34 -
   18.35 -#include "gmyth_settings.h"
   18.36 - 
   18.37 -#include <string.h>
   18.38 -#include <stdlib.h>
   18.39 -#include <unistd.h>
   18.40 -#include <fcntl.h>
   18.41 -
   18.42 -#include <glib.h>
   18.43 -#include <glib/gprintf.h>
   18.44 -#include <glib/gstdio.h>
   18.45 -
   18.46 -#define GMYTH_SETTINGS_FILE_NAME	"settings.dat"
   18.47 -#define GMYTH_SETTINGS_DIR		".gmyth"
   18.48 -
   18.49 -static void gmyth_settings_class_init          (GMythSettingsClass *klass);
   18.50 -static void gmyth_settings_init                (GMythSettings *object);
   18.51 -
   18.52 -static void gmyth_settings_dispose  (GObject *object);
   18.53 -static void gmyth_settings_finalize (GObject *object);
   18.54 -
   18.55 -static void fill_settings_data(GMythSettings *gmyth_settings, char* line);
   18.56 -
   18.57 -G_DEFINE_TYPE(GMythSettings, gmyth_settings, G_TYPE_OBJECT)
   18.58 -
   18.59 -static void
   18.60 -gmyth_settings_class_init (GMythSettingsClass *klass)
   18.61 -{
   18.62 -	GObjectClass *gobject_class;
   18.63 -
   18.64 -    gobject_class = (GObjectClass *) klass;
   18.65 -
   18.66 -    gobject_class->dispose  = gmyth_settings_dispose;
   18.67 -    gobject_class->finalize = gmyth_settings_finalize;	
   18.68 -}
   18.69 -
   18.70 -static void
   18.71 -gmyth_settings_init (GMythSettings *gmyth_settings)
   18.72 -{
   18.73 -
   18.74 -	gmyth_settings->settings_file = NULL;
   18.75 -	
   18.76 -    gmyth_settings->backend_hostname = g_string_new("127.0.0.1");
   18.77 -    gmyth_settings->backend_port = 6543;
   18.78 -    gmyth_settings->mysql_dbname = g_string_new("mythconverg");
   18.79 -	gmyth_settings->mysql_username = g_string_new("mythtv");
   18.80 -    gmyth_settings->mysql_password = g_string_new("mythtv");
   18.81 -    gmyth_settings->database_type = g_string_new("mysql");
   18.82 -    	
   18.83 -}
   18.84 -
   18.85 -
   18.86 -static void
   18.87 -gmyth_settings_dispose  (GObject *object)
   18.88 -{
   18.89 -	GMythSettings *gmyth_settings = GMYTH_SETTINGS(object);
   18.90 -
   18.91 -	if ( gmyth_settings->backend_hostname != NULL )
   18.92 -		g_string_free( gmyth_settings->backend_hostname, TRUE );
   18.93 -	if ( gmyth_settings->mysql_dbname != NULL )
   18.94 -		g_string_free( gmyth_settings->mysql_dbname, TRUE );
   18.95 -	if ( gmyth_settings->mysql_username != NULL )
   18.96 -		g_string_free( gmyth_settings->mysql_username, TRUE );
   18.97 -	if ( gmyth_settings->mysql_password != NULL )
   18.98 -		g_string_free( gmyth_settings->mysql_password, TRUE );
   18.99 -	if ( gmyth_settings->database_type != NULL )
  18.100 -		g_string_free( gmyth_settings->database_type, TRUE );
  18.101 -
  18.102 -	G_OBJECT_CLASS (gmyth_settings_parent_class)->dispose (object);
  18.103 -}
  18.104 -
  18.105 -static void
  18.106 -gmyth_settings_finalize (GObject *object)
  18.107 -{
  18.108 -	g_signal_handlers_destroy (object);
  18.109 -
  18.110 -    G_OBJECT_CLASS (gmyth_settings_parent_class)->finalize (object);
  18.111 -}
  18.112 -
  18.113 -/** Creates a new instance of GMythSettings.
  18.114 - * 
  18.115 - * @return a new instance of GMythSettings.
  18.116 - */
  18.117 -GMythSettings*
  18.118 -gmyth_settings_new (void)
  18.119 -{
  18.120 -    GMythSettings *gmyth_settings = GMYTH_SETTINGS (g_object_new(GMYTH_SETTINGS_TYPE, NULL));
  18.121 -
  18.122 -    return gmyth_settings;
  18.123 -}
  18.124 -
  18.125 -static gboolean
  18.126 -gmyth_settings_ensure_dir_exists (const gchar *dir)
  18.127 -{
  18.128 -
  18.129 -	g_debug ("[%s] \tdir = %s\n", __FUNCTION__, dir);
  18.130 -
  18.131 -    if (g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE) {
  18.132 -	    if (g_file_test (dir, G_FILE_TEST_EXISTS) == TRUE) {
  18.133 -            g_warning ("%s exists, please move it out of the way.", dir);
  18.134 -            return FALSE;
  18.135 -	    }
  18.136 -
  18.137 -        if (mkdir (dir, 488) != 0) {
  18.138 -            g_warning ("Failed to create directory %s.", dir);
  18.139 -            return FALSE;
  18.140 -        }
  18.141 -    }
  18.142 -
  18.143 -    return TRUE;
  18.144 -}
  18.145 -
  18.146 -static gboolean
  18.147 -gmyth_settings_ensure_file_exists (const gchar *file_name) {
  18.148 -
  18.149 -	int file = 0;
  18.150 -	
  18.151 -    if ( g_file_test( file_name, G_FILE_TEST_EXISTS ) == FALSE ) {
  18.152 -        g_debug ( "\n\tCreating %s file...\n", file_name );
  18.153 -        file = creat( file_name, S_IRWXU | S_IRWXO | S_IRWXG );
  18.154 -
  18.155 -		if ( close( file ) == -1 )
  18.156 -			return FALSE;
  18.157 -    }
  18.158 -
  18.159 -	return TRUE;
  18.160 -}
  18.161 -
  18.162 -/** Loads the GMyth settings from the given file.
  18.163 - * 
  18.164 - * @param gmyth_settings the GMythSettings instance.
  18.165 - * @param filename The desired file to be opened.
  18.166 - * @return TRUE if success, FALSE if error.
  18.167 - */
  18.168 -gboolean
  18.169 -gmyth_settings_load_from_file (GMythSettings *gmyth_settings, GString *filename)
  18.170 -{
  18.171 -    FILE *file_desc;
  18.172 -    char line[100];
  18.173 -	
  18.174 -	g_debug ("[%s] Loading GMyth settings file: %s", __FUNCTION__, filename->str);
  18.175 -	
  18.176 -    file_desc = fopen(filename->str, "r");
  18.177 -    if( file_desc == NULL) {
  18.178 -        g_warning ("[%s] Settings file %s could not be opened", __FUNCTION__, filename->str);
  18.179 -        return FALSE;
  18.180 -    }
  18.181 -	
  18.182 -	gmyth_settings->settings_file = g_string_new (filename->str);
  18.183 -	
  18.184 -    while(fgets(line, 100, file_desc)) {
  18.185 -        int i;
  18.186 -
  18.187 -        /* Removes the new line characters from the end of line */
  18.188 -        for ( i = strlen(line)-1; i >= 0; i--) {
  18.189 -            if ( !g_ascii_iscntrl (line[i]) ) {
  18.190 -                line[i+1] = '\0';
  18.191 -                break;
  18.192 -            }
  18.193 -        }
  18.194 -        
  18.195 -        fill_settings_data(gmyth_settings, line);
  18.196 -    }
  18.197 -
  18.198 -    fclose (file_desc);
  18.199 -
  18.200 -    return TRUE;
  18.201 -}
  18.202 -
  18.203 -/** Loads the GMyth settings from the standard settings file
  18.204 - * (~/.gmyth/settings.dat).
  18.205 - * 
  18.206 - * @param gmyth_settings the GMythSettings instance.
  18.207 - * @return TRUE if success, FALSE if error.
  18.208 - */
  18.209 -gboolean
  18.210 -gmyth_settings_load (GMythSettings *gmyth_settings)
  18.211 -{
  18.212 -	GString* file_full_path = g_string_new( g_build_filename( g_get_home_dir(), 
  18.213 -				GMYTH_SETTINGS_DIR, GMYTH_SETTINGS_FILE_NAME, NULL ) );
  18.214 -
  18.215 -	gmyth_settings->settings_file = file_full_path;
  18.216 -		
  18.217 -	gmyth_settings_ensure_dir_exists( g_build_filename( g_get_home_dir(), GMYTH_SETTINGS_DIR, NULL ) );
  18.218 -
  18.219 -	// Verifies if the file already exist
  18.220 -	if ( g_file_test( file_full_path->str, G_FILE_TEST_EXISTS ) == FALSE ) {
  18.221 -		g_debug ("[%s] Settings file does not exist. A new one will be created.\n", __FUNCTION__);
  18.222 -
  18.223 -		if ( gmyth_settings_ensure_file_exists( file_full_path->str ) == FALSE )
  18.224 -			return FALSE;
  18.225 -
  18.226 -		// Creates the file with default values (see _init function)
  18.227 -		return gmyth_settings_save (gmyth_settings);
  18.228 -		
  18.229 -	} else {
  18.230 -		g_debug ("[%s] Opening settings from file %s", __FUNCTION__, file_full_path->str);
  18.231 -		
  18.232 -		return gmyth_settings_load_from_file (gmyth_settings, file_full_path);
  18.233 -	}	
  18.234 -}	
  18.235 -
  18.236 -/** Saves the current gmyth_settings to the settings file related to the
  18.237 - * given instance.
  18.238 - * 
  18.239 - * @param gmyth_settings the GMythSettings instance.
  18.240 - * @return TRUE if success, FALSE if error.
  18.241 - */
  18.242 -gboolean
  18.243 -gmyth_settings_save (GMythSettings *gmyth_settings)
  18.244 -{
  18.245 -    FILE *file_desc;
  18.246 -	
  18.247 -	if (gmyth_settings->settings_file == NULL) {
  18.248 -		g_warning ("[%s] Settings were not loaded from file, could not save!", __FUNCTION__);
  18.249 -	}
  18.250 -	
  18.251 -    file_desc = fopen(gmyth_settings->settings_file->str, "w");
  18.252 -    if( file_desc == NULL) {
  18.253 -        g_warning ("GMYTH_SETTINGS: settings file %s not found", gmyth_settings->settings_file->str);
  18.254 -        return FALSE;
  18.255 -    }
  18.256 -    
  18.257 -	g_fprintf(file_desc, "#Maemo-Myth Settings\n");
  18.258 -
  18.259 -	g_fprintf(file_desc, "#General settings related with mythtv database\n");
  18.260 -	g_fprintf(file_desc, "dbname=%s\n", gmyth_settings->mysql_dbname->str);
  18.261 -	g_fprintf(file_desc, "username=%s\n", gmyth_settings->mysql_username->str);
  18.262 -	g_fprintf(file_desc, "password=%s\n", gmyth_settings->mysql_password->str);
  18.263 -
  18.264 -	g_fprintf(file_desc, "\n#General settings related with mythtv backend\n");
  18.265 -	g_fprintf(file_desc, "hostname=%s\n", gmyth_settings->backend_hostname->str);
  18.266 -	g_fprintf(file_desc, "backend_port=%d\n", gmyth_settings->backend_port);
  18.267 -
  18.268 -    fclose (file_desc);
  18.269 -
  18.270 -	g_debug ("[%s] Settings file saved", __FUNCTION__);
  18.271 -    return TRUE;
  18.272 -}
  18.273 -
  18.274 -/** Gets the backend hostname from the settings.
  18.275 - * 
  18.276 - * @param gmyth_settings the GMythSettings instance.
  18.277 - * @return The loaded backend hostname, or the default value "127.0.0.1" if settings
  18.278 - * file was not opened.
  18.279 - */
  18.280 -GString*
  18.281 -gmyth_settings_get_backend_hostname (GMythSettings *gmyth_settings)
  18.282 -{
  18.283 -	return g_string_new (gmyth_settings->backend_hostname->str);
  18.284 -}
  18.285 -
  18.286 -/** Sets the backend hostname to the settings.
  18.287 - * 
  18.288 - * @param gmyth_settings the GMythSettings instance.
  18.289 - * @param new_hostname The new hostname.
  18.290 - */
  18.291 -void
  18.292 -gmyth_settings_set_backend_hostname (GMythSettings *gmyth_settings, GString *new_hostname)
  18.293 -{
  18.294 -	g_string_assign (gmyth_settings->backend_hostname, new_hostname->str);
  18.295 -}
  18.296 -
  18.297 -/** Gets the user name to connect to backend database.
  18.298 - * 
  18.299 - * @param gmyth_settings the GMythSettings instance.
  18.300 - * @return The loaded user name, or the default value "mythtv" if settings
  18.301 - * file was not opened.
  18.302 - */
  18.303 -GString*
  18.304 -gmyth_settings_get_username (GMythSettings *gmyth_settings)
  18.305 -{
  18.306 -	return g_string_new (gmyth_settings->mysql_username->str);
  18.307 -}
  18.308 -
  18.309 -/** Sets the username to connect to backend database.
  18.310 - * 
  18.311 - * @param gmyth_settings the GMythSettings instance.
  18.312 - * @param new_username The new username.
  18.313 - */
  18.314 -void
  18.315 -gmyth_settings_set_username (GMythSettings *gmyth_settings, GString *new_username)
  18.316 -{
  18.317 -	g_string_assign (gmyth_settings->mysql_username, new_username->str);
  18.318 -}
  18.319 -
  18.320 -/** Gets the database password from the settings file.
  18.321 - * 
  18.322 - * @param gmyth_settings the GMythSettings instance.
  18.323 - * @return The loaded password, or the default value "mythtv" if settings
  18.324 - * file was not opened.
  18.325 - */
  18.326 -GString*
  18.327 -gmyth_settings_get_password (GMythSettings *gmyth_settings)
  18.328 -{
  18.329 -	return g_string_new (gmyth_settings->mysql_password->str);	
  18.330 -}
  18.331 -
  18.332 -/** Sets the database password.
  18.333 - * 
  18.334 - * @param gmyth_settings the GMythSettings instance.
  18.335 - * @param new_password The new password.
  18.336 - */
  18.337 -
  18.338 -void
  18.339 -gmyth_settings_set_password (GMythSettings *gmyth_settings, GString *new_password)
  18.340 -{
  18.341 -	g_string_assign (gmyth_settings->mysql_password, new_password->str);
  18.342 -}
  18.343 -
  18.344 -/** Gets the backend database name from the settings file.
  18.345 - * 
  18.346 - * @param gmyth_settings the GMythSettings instance.
  18.347 - * @return The loaded database name, or the default value "mythconverg" if settings
  18.348 - * file was not opened.
  18.349 - */
  18.350 -GString*
  18.351 -gmyth_settings_get_dbname (GMythSettings *gmyth_settings)
  18.352 -{
  18.353 -	return g_string_new (gmyth_settings->mysql_dbname->str);
  18.354 -}
  18.355 -
  18.356 -/** Sets the Mythtv database name to the settings.
  18.357 - * 
  18.358 - * @param gmyth_settings the GMythSettings instance.
  18.359 - * @param new_dbname The new database name.
  18.360 - */
  18.361 -
  18.362 -void
  18.363 -gmyth_settings_set_dbname (GMythSettings *gmyth_settings, GString *new_dbname)
  18.364 -{
  18.365 -	g_string_assign (gmyth_settings->mysql_dbname, new_dbname->str);
  18.366 -}
  18.367 -
  18.368 -/** Gets the backend port from the settings.
  18.369 - * 
  18.370 - * @param gmyth_settings the GMythSettings instance.
  18.371 - * @return The loaded backend port, or the default value "6543" if settings
  18.372 - * file was not opened.
  18.373 - */
  18.374 -int
  18.375 -gmyth_settings_get_backend_port (GMythSettings *gmyth_settings)
  18.376 -{
  18.377 -	return gmyth_settings->backend_port;
  18.378 -}
  18.379 -
  18.380 -/** Sets the backend port.
  18.381 - * 
  18.382 - * @param gmyth_settings the GMythSettings instance.
  18.383 - * @param new_port The new port.
  18.384 - */
  18.385 -void
  18.386 -gmyth_settings_set_backend_port (GMythSettings *gmyth_settings, gint new_port)
  18.387 -{
  18.388 -	gmyth_settings->backend_port = new_port;
  18.389 -}
  18.390 -
  18.391 -
  18.392 -static void
  18.393 -fill_settings_data(GMythSettings *gmyth_settings, char* line)
  18.394 -{
  18.395 -    gchar** str_splited;
  18.396 -
  18.397 -	GString *gstr_splited;
  18.398 -	gstr_splited = g_string_new("");
  18.399 -	str_splited = g_strsplit (line, "=", -1);
  18.400 -
  18.401 -	if(!(strcmp(str_splited[0], "hostname"))){
  18.402 -		g_string_assign(gstr_splited, str_splited[1]);
  18.403 -		gmyth_settings_set_backend_hostname(gmyth_settings, gstr_splited);
  18.404 -	}
  18.405 -	else if (!(strcmp(str_splited[0], "dbname"))){
  18.406 -		g_string_assign(gstr_splited, str_splited[1]);
  18.407 -		gmyth_settings_set_dbname(gmyth_settings, gstr_splited);	
  18.408 -	}
  18.409 -	else if (!(strcmp(str_splited[0], "username"))){
  18.410 -		g_string_assign(gstr_splited, str_splited[1]);
  18.411 -		gmyth_settings_set_username(gmyth_settings, gstr_splited);
  18.412 -	}	
  18.413 -	else if (!(strcmp(str_splited[0], "password"))){
  18.414 -		g_string_assign(gstr_splited, str_splited[1]);
  18.415 -		gmyth_settings_set_password(gmyth_settings, gstr_splited);
  18.416 -	}
  18.417 -	else if (!(strcmp(str_splited[0], "backend_port"))){
  18.418 -		gmyth_settings_set_backend_port(gmyth_settings, atoi(str_splited[1]));
  18.419 -	}		
  18.420 -}
    19.1 --- a/gmyth/src/gmyth_settings.h	Mon Nov 27 21:20:17 2006 +0000
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,106 +0,0 @@
    19.4 -/**
    19.5 - * GMyth Library
    19.6 - *
    19.7 - * @file gmyth/gmyth_settings.h
    19.8 - * 
    19.9 - * @brief <p> This component contains functions acessing and modifying 
   19.10 - * user and program settings.
   19.11 - * 
   19.12 - * The standard settings file is created in the user home folder, in the
   19.13 - * file ~/.gmyth/settings.dat.  
   19.14 - *
   19.15 - * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
   19.16 - * @author Alexsandro Jose Virginio dos Santos <alexsandro.santos@indt.org.br>
   19.17 - *
   19.18 - *//*
   19.19 - * 
   19.20 - * This program is free software; you can redistribute it and/or modify
   19.21 - * it under the terms of the GNU Lesser General Public License as published by
   19.22 - * the Free Software Foundation; either version 2 of the License, or
   19.23 - * (at your option) any later version.
   19.24 - *
   19.25 - * This program is distributed in the hope that it will be useful,
   19.26 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.27 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.28 - * GNU General Public License for more details.
   19.29 - *
   19.30 - * You should have received a copy of the GNU Lesser General Public License
   19.31 - * along with this program; if not, write to the Free Software
   19.32 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19.33 - */
   19.34 -
   19.35 -#ifndef __GMYTH_SETTINGS_H__
   19.36 -#define __GMYTH_SETTINGS_H__
   19.37 -
   19.38 -#include <glib-object.h>
   19.39 -
   19.40 -G_BEGIN_DECLS
   19.41 -
   19.42 -#define GMYTH_SETTINGS_TYPE               (gmyth_settings_get_type ())
   19.43 -#define GMYTH_SETTINGS(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_SETTINGS_TYPE, GMythSettings))
   19.44 -#define GMYTH_SETTINGS_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_SETTINGS_TYPE, GMythSettingsClass))
   19.45 -#define IS_GMYTH_SETTINGS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_SETTINGS_TYPE))
   19.46 -#define IS_GMYTH_SETTINGS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_SETTINGS_TYPE))
   19.47 -#define GMYTH_SETTINGS_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_SETTINGS_TYPE, GMythSettingsClass))
   19.48 -
   19.49 -
   19.50 -typedef struct _GMythSettings         GMythSettings;
   19.51 -typedef struct _GMythSettingsClass    GMythSettingsClass;
   19.52 -
   19.53 -struct _GMythSettingsClass
   19.54 -{
   19.55 -  GObjectClass parent_class;
   19.56 -
   19.57 -  /* callbacks */
   19.58 -  /* no one for now */
   19.59 -};
   19.60 -
   19.61 -struct _GMythSettings
   19.62 -{
   19.63 -    GObject parent;
   19.64 -
   19.65 -	GString *settings_file;
   19.66 -	
   19.67 -    GString *backend_hostname;
   19.68 -    int backend_port;
   19.69 -
   19.70 -    GString *mysql_dbname;
   19.71 -	GString *mysql_username;
   19.72 -    GString *mysql_password;
   19.73 -    // FIXME: Why do we need database_type? Do we intend to support other dbs?
   19.74 -    GString *database_type;
   19.75 -};
   19.76 -
   19.77 -
   19.78 -GType gmyth_settings_get_type (void);
   19.79 -
   19.80 -GMythSettings* gmyth_settings_new (void);
   19.81 -
   19.82 -gboolean gmyth_settings_load_from_file (GMythSettings *gmyth_settings, 
   19.83 -                                        GString *filename);
   19.84 -gboolean gmyth_settings_load (GMythSettings *msettings);
   19.85 -gboolean gmyth_settings_save (GMythSettings *gmyth_settings);
   19.86 -
   19.87 -GString* gmyth_settings_get_backend_hostname (GMythSettings *gmyth_settings);
   19.88 -void     gmyth_settings_set_backend_hostname (GMythSettings *gmyth_settings, 
   19.89 -                                              GString *new_hostname);
   19.90 -
   19.91 -GString* gmyth_settings_get_username (GMythSettings *gmyth_settings);
   19.92 -void     gmyth_settings_set_username (GMythSettings *gmyth_settings, 
   19.93 -                                      GString *new_username);
   19.94 -
   19.95 -GString* gmyth_settings_get_password (GMythSettings *gmyth_settings);
   19.96 -void     gmyth_settings_set_password (GMythSettings *gmyth_settings, 
   19.97 -                                      GString *new_password);
   19.98 -
   19.99 -GString* gmyth_settings_get_dbname (GMythSettings *gmyth_settings);
  19.100 -void     gmyth_settings_set_dbname (GMythSettings *gmyth_settings, 
  19.101 -                                    GString *new_dbname);
  19.102 -
  19.103 -int      gmyth_settings_get_backend_port (GMythSettings *gmyth_settings);
  19.104 -void     gmyth_settings_set_backend_port (GMythSettings *gmyth_settings, 
  19.105 -                                          gint new_port);
  19.106 -
  19.107 -G_END_DECLS
  19.108 -
  19.109 -#endif /* __GMYTH_SETTINGS_H__ */
    20.1 --- a/gmyth/src/gmyth_socket.c	Mon Nov 27 21:20:17 2006 +0000
    20.2 +++ b/gmyth/src/gmyth_socket.c	Mon Nov 27 21:20:57 2006 +0000
    20.3 @@ -58,7 +58,6 @@
    20.4  
    20.5  #include "gmyth_socket.h"
    20.6  #include "gmyth_stringlist.h"
    20.7 -#include "gmyth_context.h"
    20.8  #include "gmyth_uri.h"
    20.9  
   20.10  #define BUFLEN 				        			512
   20.11 @@ -68,6 +67,9 @@
   20.12  /* max number of iterations */
   20.13  #define MYTHTV_MAX_VERSION_CHECKS		40
   20.14  
   20.15 +// FIXME: put this in the right place
   20.16 +#define  MYTHTV_VERSION_DEFAULT			30
   20.17 +
   20.18  static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
   20.19  
   20.20  static void gmyth_socket_class_init          (GMythSocketClass *klass);
    21.1 --- a/gmyth/src/gmyth_socket.h	Mon Nov 27 21:20:17 2006 +0000
    21.2 +++ b/gmyth/src/gmyth_socket.h	Mon Nov 27 21:20:57 2006 +0000
    21.3 @@ -82,7 +82,7 @@
    21.4  
    21.5  GType           gmyth_socket_get_type (void);
    21.6  
    21.7 -GMythSocket *   gmyth_socket_new (void);
    21.8 +GMythSocket *   gmyth_socket_new ( );
    21.9  
   21.10  GIOChannel *    gmyth_socket_get_io_channel (GMythSocket *gmyth_socket );
   21.11  
    22.1 --- a/gmyth/src/gmyth_tvchain.c	Mon Nov 27 21:20:17 2006 +0000
    22.2 +++ b/gmyth/src/gmyth_tvchain.c	Mon Nov 27 21:20:57 2006 +0000
    22.3 @@ -30,6 +30,7 @@
    22.4  #include <time.h>
    22.5  #include <stdio.h>
    22.6  #include <stdlib.h>
    22.7 +#include <assert.h>
    22.8  
    22.9  #include "gmyth_epg.h"
   22.10  #include "gmyth_tvchain.h"
   22.11 @@ -70,32 +71,38 @@
   22.12  static void
   22.13  gmyth_tvchain_dispose  (GObject *object)
   22.14  {
   22.15 -	GMythTVChain *tvchain = GMYTH_TVCHAIN(object);
   22.16 +    GMythTVChain *tvchain = GMYTH_TVCHAIN(object);
   22.17  
   22.18 -	if ( tvchain->tvchain_id != NULL ) {
   22.19 -		g_string_free( tvchain->tvchain_id, TRUE );
   22.20 -		tvchain->tvchain_id = NULL;
   22.21 -	}
   22.22 +    if ( tvchain->tvchain_id != NULL ) {
   22.23 +	g_string_free( tvchain->tvchain_id, TRUE );
   22.24 +	tvchain->tvchain_id = NULL;
   22.25 +    }
   22.26  
   22.27 -	if ( tvchain->tvchain_list != NULL ) {
   22.28 -		g_list_free( tvchain->tvchain_list );
   22.29 -		tvchain->tvchain_list = NULL;
   22.30 -	}
   22.31 +    if ( tvchain->tvchain_list != NULL ) {
   22.32 +	g_list_free( tvchain->tvchain_list );
   22.33 +	tvchain->tvchain_list = NULL;
   22.34 +    }
   22.35  
   22.36 -	if ( tvchain->cur_chanid != NULL ) {
   22.37 -		g_string_free( tvchain->cur_chanid, TRUE );
   22.38 -		tvchain->cur_chanid = NULL;
   22.39 -	}
   22.40 +    if ( tvchain->cur_chanid != NULL ) {
   22.41 +	g_string_free( tvchain->cur_chanid, TRUE );
   22.42 +	tvchain->cur_chanid = NULL;
   22.43 +    }
   22.44  
   22.45 -	G_OBJECT_CLASS (gmyth_tvchain_parent_class)->dispose (object);
   22.46 +    if ( tvchain->backend_info) {
   22.47 +        g_object_unref (tvchain->backend_info);
   22.48 +        tvchain->backend_info = NULL;
   22.49 +    }
   22.50 +
   22.51 +
   22.52 +    G_OBJECT_CLASS (gmyth_tvchain_parent_class)->dispose (object);
   22.53  }
   22.54  
   22.55  static void
   22.56  gmyth_tvchain_finalize (GObject *object)
   22.57  {
   22.58 -	g_signal_handlers_destroy (object);
   22.59 +    g_signal_handlers_destroy (object);
   22.60  
   22.61 -	G_OBJECT_CLASS (gmyth_tvchain_parent_class)->finalize (object);
   22.62 +    G_OBJECT_CLASS (gmyth_tvchain_parent_class)->finalize (object);
   22.63  }
   22.64  
   22.65  /** Initializes the tvchain and generates the tvchain id.
   22.66 @@ -103,27 +110,38 @@
   22.67   * @param tvchain The GMythTVChain instance.
   22.68   * @param hostname The local hostname used to generate the tvchain id.
   22.69   */
   22.70 -void
   22.71 -gmyth_tvchain_initialize (GMythTVChain *tvchain, GString *hostname)
   22.72 +gboolean
   22.73 +gmyth_tvchain_initialize (GMythTVChain *tvchain, GMythBackendInfo *backend_info)
   22.74  {
   22.75 -	if (tvchain->tvchain_id == NULL) {
   22.76 -		GString *isodate;
   22.77 -		time_t cur_time;
   22.78 +    char *hostname;
   22.79  
   22.80 -		time(&cur_time);
   22.81 -		isodate = gmyth_util_time_to_isoformat (cur_time);
   22.82 +    assert (tvchain);
   22.83 +    g_return_val_if_fail (backend_info != NULL, FALSE);
   22.84  
   22.85 -		tvchain->tvchain_id = g_string_sized_new(7 + hostname->len + isodate->len);
   22.86 -		g_string_printf(tvchain->tvchain_id, 
   22.87 -				"live-%s-%s", hostname->str, isodate->str);
   22.88 +    g_object_ref (backend_info);
   22.89 +    tvchain->backend_info = backend_info;
   22.90  
   22.91 -		g_print("tv_chain_id: %s\n", tvchain->tvchain_id->str);
   22.92 +    hostname = gmyth_backend_info_get_hostname (backend_info);
   22.93 +    
   22.94 +    if (tvchain->tvchain_id == NULL) {
   22.95 +	GString *isodate;
   22.96 +	time_t cur_time;
   22.97  
   22.98 -		g_string_free(isodate, TRUE);
   22.99 +	time(&cur_time);
  22.100 +	isodate = gmyth_util_time_to_isoformat (cur_time);
  22.101  
  22.102 -	} else {
  22.103 -		g_warning ("[%s] TVchain already initialized", __FUNCTION__);
  22.104 -	}
  22.105 +	tvchain->tvchain_id = g_string_sized_new (7 + strlen (hostname) + isodate->len);
  22.106 +	g_string_printf(tvchain->tvchain_id, 
  22.107 +		"live-%s-%s", hostname, isodate->str);
  22.108 +
  22.109 +	g_debug ("[%s] tv_chain_id: %s", __FUNCTION__, tvchain->tvchain_id->str);
  22.110 +
  22.111 +	g_string_free(isodate, TRUE);
  22.112 +    } else {
  22.113 +	g_warning ("[%s] TVchain already initialized", __FUNCTION__);
  22.114 +    }
  22.115 +
  22.116 +    return TRUE;
  22.117  }
  22.118  
  22.119  /** Gets the tvchain id.
  22.120 @@ -168,7 +186,7 @@
  22.121  
  22.122  	// TODO: Reuse gmyth_query already connected from context
  22.123  	gmyth_query = gmyth_query_new ();
  22.124 -	if (!gmyth_query_connect (gmyth_query)) {
  22.125 +	if (!gmyth_query_connect (gmyth_query, tvchain->backend_info)) {
  22.126  		g_warning ("[%s] Could not connect to db", __FUNCTION__);
  22.127  		g_static_mutex_unlock( &mutex );
  22.128  
  22.129 @@ -349,7 +367,7 @@
  22.130  
  22.131  	GMythScheduler *scheduler = gmyth_scheduler_new ();
  22.132  
  22.133 -	gmyth_scheduler_connect( scheduler );
  22.134 +	gmyth_scheduler_connect( scheduler, tvchain->backend_info );
  22.135  	proginfo = gmyth_scheduler_get_recorded (scheduler, 
  22.136  			entry->chanid, entry->starttime);
  22.137  	gmyth_scheduler_disconnect( scheduler );
    23.1 --- a/gmyth/src/gmyth_tvchain.h	Mon Nov 27 21:20:17 2006 +0000
    23.2 +++ b/gmyth/src/gmyth_tvchain.h	Mon Nov 27 21:20:57 2006 +0000
    23.3 @@ -33,6 +33,7 @@
    23.4  #include <time.h>
    23.5  
    23.6  #include "gmyth_common.h"
    23.7 +#include "gmyth_backendinfo.h"
    23.8  
    23.9  G_BEGIN_DECLS
   23.10  
   23.11 @@ -81,13 +82,15 @@
   23.12  	time_t  cur_startts;
   23.13  	GString *cur_chanid;
   23.14  	int     cur_pos;
   23.15 +
   23.16 +    GMythBackendInfo *backend_info;
   23.17  };
   23.18  
   23.19  
   23.20  GType       gmyth_tvchain_get_type (void);
   23.21  
   23.22 -void        gmyth_tvchain_initialize    (GMythTVChain *tvchain, 
   23.23 -                                         GString *hostname);
   23.24 +gboolean        gmyth_tvchain_initialize    (GMythTVChain *tvchain, 
   23.25 +                                         GMythBackendInfo *backend_info);
   23.26  gboolean    gmyth_tvchain_reload_all    (GMythTVChain *tvchain);
   23.27  GString*    gmyth_tvchain_get_id        (GMythTVChain *tvchain);
   23.28  int         gmyth_tvchain_program_is_at (GMythTVChain *tvchain,