branches/gmyth-0.1b/src/gmyth_common.c
branchtrunk
changeset 360 6d5596b9eb95
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/branches/gmyth-0.1b/src/gmyth_common.c	Wed Feb 14 21:28:49 2007 +0000
     1.3 @@ -0,0 +1,124 @@
     1.4 +/**
     1.5 + * GMyth Library
     1.6 + *
     1.7 + * @file gmyth/gmyth_common.c
     1.8 + * 
     1.9 + * @brief <p> This file contains basic common functions for the gmyth library.
    1.10 + *
    1.11 + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    1.12 + * @author Leonardo Sobral Cunha <leonardo.cunha@indt.org.br>
    1.13 + *
    1.14 + *//*
    1.15 + * 
    1.16 + * This program is free software; you can redistribute it and/or modify
    1.17 + * it under the terms of the GNU Lesser General Public License as published by
    1.18 + * the Free Software Foundation; either version 2 of the License, or
    1.19 + * (at your option) any later version.
    1.20 + *
    1.21 + * This program is distributed in the hope that it will be useful,
    1.22 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.23 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.24 + * GNU General Public License for more details.
    1.25 + *
    1.26 + * You should have received a copy of the GNU Lesser General Public License
    1.27 + * along with this program; if not, write to the Free Software
    1.28 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.29 + */
    1.30 +
    1.31 +#ifdef HAVE_CONFIG_H
    1.32 +#include "config.h"
    1.33 +#endif
    1.34 +
    1.35 +#include "gmyth_common.h"
    1.36 +#include "gmyth_debug.h"
    1.37 +#include "gmyth_util.h"
    1.38 +
    1.39 +static void free_channel_data(gpointer data, gpointer user_data);
    1.40 +static void free_program_data(gpointer data, gpointer user_data);
    1.41 +
    1.42 +/** Frees the memory allocated to the GMythChannelInfo objects inside list.
    1.43 + * The list memory is also released by g_list_free(). If LIST is NULL it
    1.44 + * simply returns.
    1.45 + * 
    1.46 + * @param list the GList containing a list of GMythChannelInfo to free.
    1.47 + */
    1.48 +void 
    1.49 +gmyth_free_channel_list(GList *list) 
    1.50 +{
    1.51 +	if (list == NULL) {
    1.52 +		g_warning ("%s received null GList as parameter", __FUNCTION__);
    1.53 +		return;
    1.54 +	}
    1.55 +	
    1.56 +	g_list_foreach (list, free_channel_data, NULL);
    1.57 +	
    1.58 +	g_list_free (list);
    1.59 +}
    1.60 +
    1.61 +/** Frees the memory allocated to the GMythProgramInfo objects inside list.
    1.62 + * The list memory is also released by g_list_free(). If list is NULL it
    1.63 + * simply returns.
    1.64 + * 
    1.65 + * @param list the GList containing a list of GMythProgramInfo to free.
    1.66 + */
    1.67 +void
    1.68 +gmyth_free_program_list(GList *list)
    1.69 +{
    1.70 +	if (list == NULL) {
    1.71 +		g_warning ("%s received null GList as parameter", __FUNCTION__);
    1.72 +		return;
    1.73 +	}
    1.74 +	
    1.75 +	g_list_foreach (list, free_program_data, NULL);
    1.76 +	
    1.77 +	g_list_free (list);
    1.78 +}
    1.79 +
    1.80 +void 
    1.81 +gmyth_channel_info_print(GMythChannelInfo *channel_info)
    1.82 +{
    1.83 +	if ( channel_info != NULL )
    1.84 +	{
    1.85 +    gmyth_debug("ChannelInfo (Name, Num, ID) = (%s, %s, %d)\n", 
    1.86 +             channel_info->channel_name->str, channel_info->channel_num->str, 
    1.87 +             channel_info->channel_ID);
    1.88 +	}
    1.89 +}
    1.90 +
    1.91 +void 
    1.92 +gmyth_program_info_print(GMythProgramInfo *program_info)
    1.93 +{
    1.94 +	
    1.95 +	if ( program_info != NULL ) {
    1.96 +		
    1.97 +	  gmyth_debug( "ProgramInfo\n\tTitle = %s\n\t"
    1.98 +	           "Description = %s\n\t"
    1.99 +	           "Start time= %s\t"
   1.100 +	           "End time = %s\n"
   1.101 +	           "Path name = %s\n"
   1.102 +	           "File size = %lld\n"
   1.103 +	           , program_info->title->str,
   1.104 +	           program_info->description->str, 
   1.105 +	           gmyth_util_time_to_string_from_time_val(program_info->startts),
   1.106 +	           gmyth_util_time_to_string_from_time_val(program_info->endts), 
   1.107 +	           program_info->pathname->str,
   1.108 +	           program_info->filesize );
   1.109 +	           
   1.110 +	}
   1.111 +	
   1.112 +}
   1.113 +
   1.114 +static void 
   1.115 +free_channel_data(gpointer data, gpointer user_data)
   1.116 +{
   1.117 +    if(data)
   1.118 +        g_free((GMythChannelInfo*) data);
   1.119 +}
   1.120 +
   1.121 +static void
   1.122 +free_program_data(gpointer data, gpointer user_data)
   1.123 +{
   1.124 +    if(data)
   1.125 +        g_object_unref((GMythProgramInfo*) data);
   1.126 +}
   1.127 +