# HG changeset patch # User melunko # Date 1174324283 0 # Node ID 60a60397ffdf14c4ad6e2d71e7703c703a405d6e # Parent 2127788267bdd2ae6ae8f02070ea386c8bd983eb [svn r417] Added some documentation. Some string memory leak resolved. Memory handling errors in GMythStringlist solved. Some improvements in gmyth_jobqueue. Some other fixes diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_backendinfo.c --- a/gmyth/src/gmyth_backendinfo.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_backendinfo.c Mon Mar 19 17:11:23 2007 +0000 @@ -59,7 +59,7 @@ backend_info->password = NULL; backend_info->db_name = NULL; backend_info->port = -1; - backend_info->uri = NULL; + backend_info->status_port = -1; } static void @@ -77,14 +77,8 @@ backend_info->password = NULL; backend_info->db_name = NULL; backend_info->port = -1; + backend_info->status_port = -1; -/* - if ( backend_info->uri != NULL ) - { - g_object_unref(backend_info->uri); - backend_info->uri = NULL; - } -*/ G_OBJECT_CLASS (gmyth_backend_info_parent_class)->dispose (object); } @@ -115,9 +109,6 @@ { GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL)); - - backend_info->uri = gmyth_uri_new_with_value( - g_strdup_printf( "myth://%s:%s@%s:%d/?%s", username, password, hostname, port, db_name ) ); gmyth_backend_info_set_hostname (backend_info, hostname); gmyth_backend_info_set_username (backend_info, username); @@ -134,19 +125,21 @@ GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL)); - backend_info->uri = gmyth_uri_new_with_value( uri_str ); + GMythURI *uri = gmyth_uri_new_with_value( uri_str ); - gchar** path_parts = g_strsplit( gmyth_uri_get_path( backend_info->uri ), "&", -1 ); + gchar** path_parts = g_strsplit( gmyth_uri_get_path (uri), "&", -1 ); - gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host ( backend_info->uri ) ); - gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( backend_info->uri ) ); - gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password( backend_info->uri ) ); + gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri) ); + gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user (uri) ); + gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password (uri) ); + /* gets the path info to database name, from the URI, and removes the trash chars */ gmyth_backend_info_set_db_name (backend_info, path_parts != NULL && path_parts[0] != NULL && strlen( path_parts[0] ) > 0 ? g_strstrip( g_strdup( g_strdelimit( path_parts[0], "/?", ' ' ) ) ) - : gmyth_uri_get_path( backend_info->uri ) ); - gmyth_backend_info_set_port ( backend_info, gmyth_uri_get_port( backend_info->uri ) ); + : gmyth_uri_get_path (uri) ); + gmyth_backend_info_set_port ( backend_info, gmyth_uri_get_port (uri) ); + g_object_unref (uri); g_strfreev( path_parts ); return backend_info; @@ -157,11 +150,10 @@ { g_return_if_fail (backend_info != NULL); - if ( NULL == hostname || strlen(hostname) <= 0 ) - { - gmyth_debug ( "Error trying to set a hostname equals to NULL." ); + if ( NULL == hostname || strlen(hostname) <= 0 ) { + gmyth_debug ( "Error trying to set a hostname equals to NULL." ); } else { - backend_info->hostname = g_strdup (hostname); + backend_info->hostname = g_strdup (hostname); } } @@ -194,11 +186,10 @@ { g_return_if_fail (backend_info != NULL); - if ( port <= 0 ) - { - gmyth_debug ( "Error trying to set a port less than 0." ); + if ( port <= 0 ) { + gmyth_debug ( "Error trying to set a port less than 0." ); } else { - backend_info->port = port; + backend_info->port = port; } } @@ -207,11 +198,10 @@ { g_return_if_fail (backend_info != NULL); - if ( port <= 0 ) - { - gmyth_debug ( "Error trying to set the status port to less than zero." ); + if ( port <= 0 ) { + gmyth_debug ( "Error trying to set the status port to less than zero." ); } else { - backend_info->status_port = port; + backend_info->status_port = port; } } @@ -255,18 +245,17 @@ return backend_info->port; } -const GMythURI* +GMythURI* gmyth_backend_info_get_uri (GMythBackendInfo *backend_info) { - - if ( NULL == backend_info->uri ) - { - backend_info->uri = gmyth_uri_new_with_value( - g_strdup_printf( "myth://%s:%s@%s:%d/?%s", backend_info->username, backend_info->password, - backend_info->hostname, backend_info->port, backend_info->db_name ) ); - } - - return backend_info->uri; + GMythURI *uri = NULL; + gchar* uri_str = g_strdup_printf( "myth://%s:%s@%s:%d/?%s", backend_info->username, backend_info->password, + backend_info->hostname, backend_info->port, backend_info->db_name ); + uri = gmyth_uri_new_with_value (uri_str); + + g_free (uri_str); + + return uri; } diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_backendinfo.h --- a/gmyth/src/gmyth_backendinfo.h Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_backendinfo.h Mon Mar 19 17:11:23 2007 +0000 @@ -56,15 +56,21 @@ { GObject parent; + /** The backend hostname or ip address. */ gchar *hostname; + /** The username to connect to the mysql server. */ gchar *username; + /** The password to connect to the mysql server. */ gchar *password; + /** The mythtv's mysql database name. */ gchar *db_name; + /** The backend port. */ gint port; + /** The backend status port for http connection */ gint status_port; - gchar *path; + //gchar *path; - GMythURI* uri; + //GMythURI* uri; }; @@ -94,9 +100,7 @@ const gchar* gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info); gint gmyth_backend_info_get_port (GMythBackendInfo *backend_info); -const GMythURI* gmyth_backend_info_get_uri (GMythBackendInfo *backend_info); - -/*const gchar* gmyth_backend_info_get_full_uri (GMythBackendInfo *backend_info);*/ +GMythURI* gmyth_backend_info_get_uri (GMythBackendInfo *backend_info); G_END_DECLS diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_common.c --- a/gmyth/src/gmyth_common.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_common.c Mon Mar 19 17:11:23 2007 +0000 @@ -36,26 +36,24 @@ static void free_channel_data(gpointer data, gpointer user_data); static void free_program_data(gpointer data, gpointer user_data); -/** Frees the memory allocated to the GMythChannelInfo objects inside list. +/** + * Frees the memory allocated to the GMythChannelInfo objects inside list. * The list memory is also released by g_list_free(). If LIST is NULL it * simply returns. * * @param list the GList containing a list of GMythChannelInfo to free. */ void -gmyth_free_channel_list(GList *list) +gmyth_free_channel_list (GList *list) { - if (list == NULL) { - g_warning ("%s received null GList as parameter", __FUNCTION__); - return; - } + g_return_if_fail (list != NULL); - g_list_foreach (list, free_channel_data, NULL); - - g_list_free (list); + g_list_foreach (list, free_channel_data, NULL); + g_list_free (list); } -/** Frees the memory allocated to the GMythProgramInfo objects inside list. +/** + * Frees the memory allocated to the GMythProgramInfo objects inside list. * The list memory is also released by g_list_free(). If list is NULL it * simply returns. * @@ -64,61 +62,63 @@ void gmyth_free_program_list(GList *list) { - if (list == NULL) { - g_warning ("%s received null GList as parameter", __FUNCTION__); - return; - } + g_return_if_fail (list != NULL); - g_list_foreach (list, free_program_data, NULL); - - g_list_free (list); + g_list_foreach (list, free_program_data, NULL); + g_list_free (list); } +#ifdef GMYTH_USE_DEBUG +/** + * Prints the channel info to the standard output. The gmyth debug must be enabled. + * @param channel_info the GMythChannelInfo instance + */ void -gmyth_channel_info_print(GMythChannelInfo *channel_info) +gmyth_channel_info_print (GMythChannelInfo *channel_info) { - if ( channel_info != NULL ) - { - gmyth_debug("ChannelInfo (Name, Num, ID) = (%s, %s, %d)\n", + if ( channel_info != NULL ) { + gmyth_debug("ChannelInfo (Name, Num, ID) = (%s, %s, %d)\n", channel_info->channel_name->str, channel_info->channel_num->str, channel_info->channel_ID); - } + } } +/** + * Prints the program info to the standard output. The gmyth debug must be enabled. + * @param channel_info the GMythProgramInfo instance + */ void gmyth_program_info_print(GMythProgramInfo *program_info) { - - if ( program_info != NULL ) { - - gmyth_debug( "ProgramInfo\n\tTitle = %s\n\t" - "Description = %s\n\t" - "Start time= %s\t" - "End time = %s\n" - "Path name = %s\n" - "File size = %lld\n" - , program_info->title->str, - program_info->description->str, - gmyth_util_time_to_string_from_time_val(program_info->startts), - gmyth_util_time_to_string_from_time_val(program_info->endts), - program_info->pathname->str, - program_info->filesize ); - - } - + g_return_if_fail (program_info); + + gmyth_debug( "ProgramInfo\n\tTitle = %s\n\t" + "Description = %s\n\t" + "Start time= %s\t" + "End time = %s\n" + "Path name = %s\n" + "File size = %lld\n", + program_info->title->str, + program_info->description->str, + gmyth_util_time_to_string_from_time_val(program_info->startts), + gmyth_util_time_to_string_from_time_val(program_info->endts), + program_info->pathname->str, + program_info->filesize ); } +#endif static void -free_channel_data(gpointer data, gpointer user_data) +free_channel_data (gpointer data, gpointer user_data) { - if(data) - g_free((GMythChannelInfo*) data); + // Frees the GMythChannelInfo structure + g_free(data); } static void free_program_data(gpointer data, gpointer user_data) { - if(data) - g_object_unref((GMythProgramInfo*) data); + g_return_if_fail (data != NULL); + + g_object_unref((GMythProgramInfo*) data); } diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_common.h --- a/gmyth/src/gmyth_common.h Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_common.h Mon Mar 19 17:11:23 2007 +0000 @@ -53,8 +53,10 @@ void gmyth_free_channel_list(GList *list); void gmyth_free_program_list(GList *list); -void gmyth_channel_info_print(GMythChannelInfo *channel_info); -void gmyth_program_info_print(GMythProgramInfo *program_info); +#ifdef GMYTH_USE_DEBUG +void gmyth_channel_info_print (GMythChannelInfo *channel_info); +void gmyth_program_info_print (GMythProgramInfo *program_info); +#endif G_END_DECLS diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_epg.c --- a/gmyth/src/gmyth_epg.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_epg.c Mon Mar 19 17:11:23 2007 +0000 @@ -51,7 +51,7 @@ static void gmyth_epg_class_init (GMythEPGClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->dispose = gmyth_epg_dispose; gobject_class->finalize = gmyth_epg_finalize; @@ -66,9 +66,14 @@ static void gmyth_epg_dispose (GObject *object) { - //GMythEPG *gmyth_epg = GMYTH_EPG(object); + GMythEPG *gmyth_epg = GMYTH_EPG(object); - G_OBJECT_CLASS (gmyth_epg_parent_class)->dispose (object); + if (gmyth_epg->sqlquery != NULL) { + g_object_unref (gmyth_epg->sqlquery); + gmyth_epg->sqlquery = NULL; + } + + G_OBJECT_CLASS (gmyth_epg_parent_class)->dispose (object); } static void @@ -103,7 +108,7 @@ { assert(gmyth_epg); - if (gmyth_epg->sqlquery == NULL) { + if (gmyth_epg->sqlquery == NULL) { gmyth_debug ("[%s] Creating gmyth_query", __FUNCTION__); gmyth_epg->sqlquery = gmyth_query_new ( ); } @@ -124,14 +129,14 @@ gboolean gmyth_epg_disconnect (GMythEPG *gmyth_epg) { - assert(gmyth_epg); + assert(gmyth_epg); - if (gmyth_epg->sqlquery != NULL) { - g_object_unref (gmyth_epg->sqlquery); + if (gmyth_epg->sqlquery != NULL) { + g_object_unref (gmyth_epg->sqlquery); gmyth_epg->sqlquery = NULL; - } + } - return TRUE; + return TRUE; } /** Retrieves the available list of channels from the backend Mysql database. @@ -143,14 +148,14 @@ gint gmyth_epg_get_channel_list (GMythEPG *gmyth_epg, GList **glist_ptr) { - MYSQL_RES *msql_res; + MYSQL_RES *msql_res; assert(gmyth_epg); msql_res = gmyth_query_process_statement (gmyth_epg->sqlquery, "SELECT chanid, channum, name FROM channel;"); - (*glist_ptr) = NULL; + (*glist_ptr) = NULL; if (msql_res == NULL) { g_warning ("[%s] msql query returned NULL MYSQL_RES", __FUNCTION__); @@ -159,19 +164,20 @@ MYSQL_ROW row; GMythChannelInfo *channel_info; - while ((row = mysql_fetch_row (msql_res)) != NULL){ + while ((row = mysql_fetch_row (msql_res)) != NULL) { - channel_info = g_new0(GMythChannelInfo, 1); + channel_info = g_new0(GMythChannelInfo, 1); channel_info->channel_ID = g_ascii_strtoull (row[0], NULL, 10); channel_info->channel_num = g_string_new (row[1]); channel_info->channel_name = g_string_new (row[2]); - +#ifdef GMYTH_USE_DEBUG gmyth_channel_info_print(channel_info); - +#endif (*glist_ptr) = g_list_append ((*glist_ptr), channel_info); } } mysql_free_result (msql_res); + return (!(*glist_ptr)) ? 0 : g_list_length (*glist_ptr); } @@ -286,8 +292,8 @@ *proglist = g_list_append((*proglist), p); -#if 0 - gmyth_program_info_print(p); +#ifdef GMYTH_USE_DEBUG + gmyth_program_info_print (p); #endif } diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_jobqueue.c --- a/gmyth/src/gmyth_jobqueue.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_jobqueue.c Mon Mar 19 17:11:23 2007 +0000 @@ -66,11 +66,14 @@ * @return the value returned by the backend * */ -static GString* send_command(GMythSocket *socket, gchar* action, +static gchar* send_command(GMythSocket *socket, gchar* action, gchar* job, gint chanid, gchar* starttime, gchar* options) { GString* command = g_string_new (""); + GString* ret_str; + gchar* ret; + GMythStringList *retlist = gmyth_string_list_new(); g_string_printf(command, "JOBQUEUE %s %s %d %s %s", action, job, @@ -83,7 +86,16 @@ // receive answer gmyth_socket_read_stringlist (socket, retlist); - return gmyth_string_list_get_string(retlist, 0); + ret_str = gmyth_string_list_get_string(retlist, 0); + + ret = ret_str->str; + g_string_free( ret_str, FALSE); + g_string_free (command, TRUE); + + gmyth_string_list_clear_all (retlist); + g_object_unref (retlist); + + return ret; } @@ -96,9 +108,9 @@ */ static gboolean test_result(gchar* ret, gchar* value) { - if (g_ascii_strcasecmp(ret, value) == 0) + if (g_ascii_strcasecmp(ret, value) == 0) { return TRUE; - else { + } else { g_debug("JobQueue Error: %s", ret); return FALSE; } @@ -111,14 +123,15 @@ * @return TRUE if the job was added, FALSE if not * */ -gint gmyth_jobqueue_add_job (GMythTranscoder* transcode, gchar* job) +gboolean gmyth_jobqueue_add_job (GMythTranscoder* transcode, gchar* job) { - //fixme: disconnect this socket GMythSocket *socket = backend_connect (transcode->backend_info); - if (socket != NULL) - { + gboolean res = FALSE; + + if (socket != NULL) { GString* options = g_string_new (""); - + gchar* ret; + if (g_ascii_strcasecmp(job, "JOB_TRANSCODE") == 0) { if (transcode->cutlist) @@ -131,21 +144,19 @@ if (transcode->profile != NULL) g_string_append_printf(options, " %s", transcode->profile); } + ret = send_command(socket, "ADD", job, transcode->chanid, + transcode->starttime, options->str); + res = test_result(ret, "JOBQUEUE_OK"); + gmyth_socket_close_connection (socket); - //fixme: allocation - GString* ret = send_command(socket, "ADD", job, transcode->chanid, - transcode->starttime, options->str); - - g_free(options); - g_free(socket); - int res = test_result(ret->str, "JOBQUEUE_OK"); - g_free(ret); - - return res; + g_object_unref (socket); + g_string_free (options, TRUE); + g_free (ret); } else { g_debug("JobQueue Connection Failed"); - return -1; } + + return res; } /** Function to change a job cmd inside JOBQUEUE @@ -160,19 +171,23 @@ gchar* job) { GMythSocket *socket = backend_connect(transcode->backend_info); - if (socket != NULL) - { + gboolean res; + + if (socket != NULL) { GString* ret = send_command(socket, action, job, transcode->chanid, transcode->starttime, ""); - g_free(socket); - int res = test_result(ret->str, "JOBQUEUE_CHANGED_CMD_OK"); - g_free(ret); + res = test_result(ret->str, "JOBQUEUE_CHANGED_CMD_OK"); - return res; + gmyth_socket_close_connection (socket); + g_object_unref (socket); + + g_string_free(ret, TRUE); + } else { g_debug("JobQueue Connection Failed"); - return -1; } + + return res; } diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_jobqueue.h --- a/gmyth/src/gmyth_jobqueue.h Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_jobqueue.h Mon Mar 19 17:11:23 2007 +0000 @@ -44,8 +44,8 @@ G_BEGIN_DECLS -gint gmyth_jobqueue_add_job (GMythTranscoder* transcoder, gchar* job); -gint gmyth_jobqueue_change_cmd (GMythTranscoder* transcoder, gchar* action, +gboolean gmyth_jobqueue_add_job (GMythTranscoder* transcoder, gchar* job); +gboolean gmyth_jobqueue_change_cmd (GMythTranscoder* transcoder, gchar* action, gchar* job); G_END_DECLS diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_livetv.c Mon Mar 19 17:11:23 2007 +0000 @@ -458,24 +458,15 @@ } /* if - Program Info */ /* prints program info data text */ +#ifdef GMYTH_USE_DEBUG gmyth_debug( "New ProgramInfo...\n" ); gmyth_program_info_print( prog_info ); - /* DEBUG message */ - /* - gmyth_debug( "Old ProgramInfo...\n" ); - gmyth_program_info_print( livetv->proginfo ); - */ - /* - GMythProgramInfo* prog_inf = gmyth_recorder_get_next_program_info( livetv->recorder, BROWSE_DIRECTION_UP ); - - gmyth_debug( "Next ProgramInfo...\n" ); - gmyth_program_info_print( prog_inf ); - */ - +#endif + /* check if the program chain could be obtained from the MythTV protocol message */ if ( prog_info != NULL ) { - g_debug( "Program Info: %s\n", gmyth_program_info_to_string( prog_info ) ); + gmyth_debug( "Program Info: %s\n", gmyth_program_info_to_string( prog_info ) ); livetv->proginfo = prog_info; /* testing change channel */ //gmyth_recorder_spawntv_no_tvchain( livetv->recorder ); diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_programinfo.c --- a/gmyth/src/gmyth_programinfo.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_programinfo.c Mon Mar 19 17:11:23 2007 +0000 @@ -107,8 +107,8 @@ GMythProgramInfo *gmyth_program_info = GMYTH_PROGRAM_INFO(object); if ( gmyth_program_info->chanid != NULL ) { - g_string_free( gmyth_program_info->chanid, TRUE ); - gmyth_program_info->chanid = NULL; + g_string_free( gmyth_program_info->chanid, TRUE ); + gmyth_program_info->chanid = NULL; } /** The program start time. */ diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_scheduler.c --- a/gmyth/src/gmyth_scheduler.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_scheduler.c Mon Mar 19 17:11:23 2007 +0000 @@ -497,6 +497,8 @@ gchar *time_str = gmyth_util_time_to_string_from_time_val (starttime); assert(scheduler); + + gmyth_debug ("[%s] channel: %s", __FUNCTION__, channel->str); if (scheduler->msqlquery == NULL) { g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__); @@ -564,7 +566,7 @@ proginfo->playgroup = g_string_new (msql_row[21]); proginfo->recpriority = (gint) g_ascii_strtoull (msql_row[22], NULL, 10); - proginfo->pathname = g_string_new (msql_row[25]); + proginfo->pathname = g_string_new (g_strdup(msql_row[25])); gmyth_debug ("One program info loaded from mysql database\n"); } diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_socket.c Mon Mar 19 17:11:23 2007 +0000 @@ -951,23 +951,20 @@ GIOCondition io_cond; /* verify if the input (read) buffer is ready to receive data */ - g_mutex_lock( gmyth_socket->mutex ); - //g_static_rw_lock_reader_lock (&rwlock); - //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE); buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' '); - if ( NULL == gmyth_socket->sd_io_ch ) - { - gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port ); - } + if ( NULL == gmyth_socket->sd_io_ch ) { + gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port ); + } - io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch); -/* - if ( NULL == gmyth_socket->sd_io_ch->read_buf || ( NULL == gmyth_socket->sd_io_ch->read_buf->str ) ) - gmyth_socket->sd_io_ch = g_io_channel_unix_new( gmyth_socket->sd ); - */ - if ( gmyth_socket->sd_io_ch->is_readable /*&& !( ( io_cond & G_IO_IN ) == 0 )*/ ) + io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch); + /* + if ( NULL == gmyth_socket->sd_io_ch->read_buf || ( NULL == gmyth_socket->sd_io_ch->read_buf->str ) ) + gmyth_socket->sd_io_ch = g_io_channel_unix_new( gmyth_socket->sd ); + */ + + if ( gmyth_socket->sd_io_ch->is_readable /*&& !( ( io_cond & G_IO_IN ) == 0 )*/ ) io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error); else return g_string_new(""); @@ -975,68 +972,68 @@ /* verify if the input (read) buffer is ready to receive data */ io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch); - //if ( ( io_cond & G_IO_IN ) == 0 ) - // return NULL; + //if ( ( io_cond & G_IO_IN ) == 0 ) + // return NULL; gmyth_debug ( "[%s] Bytes read = %d\n", __FUNCTION__, bytes_read ); if( (io_status == G_IO_STATUS_ERROR) || (bytes_read <= 0) ) { - g_debug ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__); - str = NULL; - //return NULL; + g_debug ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__); + str = NULL; + //return NULL; } else if ( buffer != NULL && strlen(buffer) > 0 ) { - //io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error ); - /* verify if the input (read) buffer is ready to receive data */ - //io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch ); + //io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error ); + /* verify if the input (read) buffer is ready to receive data */ + //io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch ); - //if ( ( io_cond & G_IO_IN ) != 0 ) { + //if ( ( io_cond & G_IO_IN ) != 0 ) { //gchar *buffer_aux = NULL; - /* removes trailing whitespace */ - //buffer_aux = g_strstrip (buffer); - len = (gint)g_ascii_strtoull ( g_strstrip (buffer), NULL, 10 ); + /* removes trailing whitespace */ + //buffer_aux = g_strstrip (buffer); + len = (gint)g_ascii_strtoull ( g_strstrip (buffer), NULL, 10 ); - if (buffer != NULL) { - g_free (buffer); - buffer = NULL; - } + if (buffer != NULL) { + g_free (buffer); + buffer = NULL; + } - /* - if (buffer_aux != NULL) { - g_free (buffer_aux); - buffer_aux = NULL; - } - */ + /* + if (buffer_aux != NULL) { + g_free (buffer_aux); + buffer_aux = NULL; + } + */ - buffer = g_new0 (gchar, len+1); + buffer = g_new0 (gchar, len+1); - bytes_read = 0; - if ( !( gmyth_socket != NULL && gmyth_socket->sd_io_ch != NULL) ) - return NULL; - if ( gmyth_socket->sd_io_ch->is_readable ) - io_status = g_io_channel_read_chars( gmyth_socket->sd_io_ch, buffer, len, &bytes_read, &error); - else - return g_string_new(""); + bytes_read = 0; + if ( !( gmyth_socket != NULL && gmyth_socket->sd_io_ch != NULL) ) + return NULL; + + if ( gmyth_socket->sd_io_ch->is_readable ) + io_status = g_io_channel_read_chars( gmyth_socket->sd_io_ch, buffer, len, &bytes_read, &error); + else + return g_string_new(""); - buffer[bytes_read] = '\0'; + buffer[bytes_read] = '\0'; //} } g_mutex_unlock( gmyth_socket->mutex ); //g_static_rw_lock_reader_unlock (&rwlock); - gmyth_debug ("Response received from backend: {%s}\n", buffer); - + gmyth_debug ("Response received from backend: ----- {%s}\n", buffer); if ( ( bytes_read != len ) || ( io_status == G_IO_STATUS_ERROR ) ) - str = NULL; + str = NULL; else - str = g_string_new (buffer); + str = g_string_new (buffer); if ( error != NULL ) { - g_debug( "[%s] Error found receiving response from the IO channel: (%d, %s)\n", __FUNCTION__, error->code, error->message ); - str = NULL; - g_error_free (error); + g_debug( "[%s] Error found receiving response from the IO channel: (%d, %s)\n", __FUNCTION__, error->code, error->message ); + str = NULL; + g_error_free (error); } g_free (buffer); diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_stringlist.c --- a/gmyth/src/gmyth_stringlist.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_stringlist.c Mon Mar 19 17:11:23 2007 +0000 @@ -62,15 +62,13 @@ static void gmyth_string_list_dispose (GObject *object) { - GMythStringList *gmyth_string_list = GMYTH_STRING_LIST(object); + GMythStringList *gmyth_string_list = GMYTH_STRING_LIST(object); - if (gmyth_string_list->glist) - gmyth_string_list_clear_all(gmyth_string_list); + //if (gmyth_string_list) + // gmyth_string_list_clear_all(gmyth_string_list); - if ( gmyth_string_list->glist != NULL ) - g_list_free( gmyth_string_list->glist ); - G_OBJECT_CLASS (gmyth_string_list_parent_class)->dispose (object); + G_OBJECT_CLASS (gmyth_string_list_parent_class)->dispose (object); } static void @@ -105,13 +103,13 @@ GString* gmyth_string_list_append_int ( GMythStringList *strlist, const gint value ) { - GString *tmp_str = g_string_new (""); + GString *value_str = g_string_new (""); - g_string_printf (tmp_str, "%d", value); + g_string_printf (value_str, "%d", value); - gmyth_string_list_append_string (strlist, tmp_str); + strlist->glist = g_list_append (strlist->glist, value_str); - return tmp_str; + return value_str; } /** Appends a guint64 to the string list. @@ -136,7 +134,6 @@ gmyth_debug( "[%s] uint64 (high) = %s\n", __FUNCTION__, tmp_str1->str ); - //gmyth_string_list_append_string (strlist, tmp_str1); strlist->glist = g_list_append( strlist->glist, tmp_str1 ); /* low order part of guint64 value */ @@ -146,8 +143,6 @@ strlist->glist = g_list_append( strlist->glist, tmp_str2 ); - //gmyth_string_list_append_string (strlist, tmp_str2); - return tmp_str2; } @@ -173,7 +168,6 @@ gmyth_debug( "[%s] int64 (high) = %s\n", __FUNCTION__, tmp_str1->str ); - //gmyth_string_list_append_string (strlist, tmp_str1); strlist->glist = g_list_append( strlist->glist, tmp_str1 ); /* low order part of gint64 value */ @@ -205,7 +199,7 @@ if ( NULL == tmp_str ) return NULL; - gmyth_string_list_append_string (strlist, tmp_str); + strlist->glist = g_list_append (strlist->glist, tmp_str); return tmp_str; } @@ -220,11 +214,15 @@ GString* gmyth_string_list_append_string ( GMythStringList *strlist, GString *value ) { - g_return_val_if_fail( strlist != NULL, NULL ); + g_return_val_if_fail (strlist != NULL, NULL ); - strlist->glist = g_list_append (strlist->glist, value); + if (value != NULL) { + strlist->glist = g_list_append (strlist->glist, g_string_new (value->str)); + } else { + strlist->glist = g_list_append (strlist->glist, NULL); + } - return value; + return value; } /** Gets an integer value from the string list at the given position. @@ -340,7 +338,7 @@ } -/** Gets a string from the string list at the given position. +/** Gets a string from the string list at the given position. The GString must be deallocated. * * @param strlist The GMythStringList instance. * @param index the string position in the list, starting with zero. @@ -349,24 +347,26 @@ GString* gmyth_string_list_get_string ( GMythStringList *strlist, const gint index ) { - if (!strlist || !(strlist->glist)) { - g_warning ("%s received Null arguments", __FUNCTION__); - return NULL; - } + GString *ret; - return (GString *) g_list_nth_data (strlist->glist, index); + if (!strlist || !(strlist->glist)) { + g_warning ("%s received Null arguments", __FUNCTION__); + return NULL; + } + + ret = (GString *) g_list_nth_data (strlist->glist, index); + + return g_string_new (ret->str); } -#if 0 static void gmyth_string_list_clear_element( GString *str_elem, void *data_aux ) { - if ( str_elem != NULL ) { - g_string_free( str_elem, TRUE ); - } + if ( str_elem != NULL ) { + g_string_free( str_elem, TRUE ); + } } -#endif /** Removes all strings from the string list. * @@ -375,11 +375,11 @@ void gmyth_string_list_clear_all ( GMythStringList *strlist ) { - if ( strlist != NULL && strlist->glist ) { - //g_list_foreach( strlist->glist, (GFunc)gmyth_string_list_clear_element, NULL ); - g_list_free (strlist->glist); - strlist->glist = NULL; - } + if ( strlist != NULL && strlist->glist ) { + g_list_foreach( strlist->glist, (GFunc)gmyth_string_list_clear_element, NULL ); + g_list_free (strlist->glist); + strlist->glist = NULL; + } } /** Retrieves the number of elements in the string list. @@ -390,8 +390,8 @@ gint gmyth_string_list_length ( GMythStringList *strlist ) { - if ( !(strlist != NULL && strlist->glist != NULL) ) - return 0; + if ( !(strlist != NULL && strlist->glist != NULL) ) + return 0; - return g_list_length (strlist->glist); + return g_list_length (strlist->glist); } diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_transcoder.c --- a/gmyth/src/gmyth_transcoder.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_transcoder.c Mon Mar 19 17:11:23 2007 +0000 @@ -97,8 +97,10 @@ GMythTranscoder *transcoder = GMYTH_TRANSCODER\ (g_object_new(GMYTH_TRANSCODER_TYPE, NULL)); - g_object_ref (backend_info); - transcoder->backend_info = backend_info; + if (backend_info != NULL) { + g_object_ref (backend_info); + transcoder->backend_info = backend_info; + } return transcoder; } @@ -214,8 +216,13 @@ gmyth_transcoder_start (GMythTranscoder* trans) { g_return_val_if_fail (trans != NULL, FALSE); + g_return_val_if_fail (trans->backend_info != NULL, FALSE); + g_return_val_if_fail (trans->filename != NULL, FALSE); if (trans->started == FALSE) { // not started yet + if (!gmyth_util_file_exists (trans->backend_info, trans->filename)) { + gmyth_debug ("File %s does not exist", trans->filename); + } trans->started = gmyth_jobqueue_add_job(trans, "JOB_TRANSCODE"); if (trans->started == FALSE) g_debug ("Error while starting GMythTranscoder to file: %s", trans->output_filename); @@ -230,7 +237,8 @@ gmyth_transcoder_pause (GMythTranscoder* trans) { g_return_val_if_fail (trans != NULL, FALSE); - + g_return_val_if_fail (trans->started == TRUE, FALSE); + return gmyth_jobqueue_change_cmd (trans, "PAUSE", "JOB_TRANSCODE"); } @@ -246,6 +254,9 @@ gmyth_transcoder_cancel (GMythTranscoder* trans) { g_return_val_if_fail (trans != NULL, FALSE); + g_return_val_if_fail (trans->started == TRUE, FALSE); + + trans->started = FALSE; return gmyth_jobqueue_change_cmd (trans, "STOP", "JOB_TRANSCODE"); } diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_uri.c --- a/gmyth/src/gmyth_uri.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_uri.c Mon Mar 19 17:11:23 2007 +0000 @@ -106,6 +106,12 @@ gmyth_uri->query = NULL; } + if ( gmyth_uri->uri != NULL ) { + g_string_free( gmyth_uri->uri, TRUE ); + gmyth_uri->uri = NULL; + } + + G_OBJECT_CLASS (gmyth_uri_parent_class)->dispose (object); } @@ -136,11 +142,11 @@ * @return a new instance of GMythURI. */ GMythURI * -gmyth_uri_new_with_value (const gchar *value) +gmyth_uri_new_with_value (const gchar *uri_str) { GMythURI *gmyth_uri = GMYTH_URI (g_object_new (GMYTH_URI_TYPE, NULL)); - gmyth_uri_parser_setup_and_new (gmyth_uri, value); + gmyth_uri_parser_setup_and_new (gmyth_uri, uri_str); return gmyth_uri; } @@ -226,7 +232,7 @@ */ uriLen = strlen(value); - uri->uri = g_string_new( value ); + uri->uri = g_string_new( g_strdup (value) ); currIdx = 0; diff -r 2127788267bd -r 60a60397ffdf gmyth/src/gmyth_util.c --- a/gmyth/src/gmyth_util.c Sat Mar 10 15:01:25 2007 +0000 +++ b/gmyth/src/gmyth_util.c Mon Mar 19 17:11:23 2007 +0000 @@ -430,6 +430,11 @@ GMythSocket *socket; gboolean res; + gmyth_debug ("Check if file %s exists", filename); + + g_return_val_if_fail (backend_info != NULL, FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + socket = gmyth_socket_new (); res = gmyth_socket_connect_to_backend (socket, backend_info->hostname, backend_info->port, TRUE); @@ -449,9 +454,8 @@ gmyth_socket_sendreceive_stringlist (socket, slist); res = (gmyth_string_list_get_int (slist, 0) == 1); - + g_object_unref (program); - g_object_unref (slist); gmyth_socket_close_connection (socket);