branches/gmyth-0.1b/src/gmyth_common.c
author rosfran
Fri Feb 02 22:46:13 2007 +0000 (2007-02-02)
branchtrunk
changeset 325 b6b5f2dc831d
permissions -rw-r--r--
[svn r327] Changes due the API change on LiveTV.
     1 /**
     2  * GMyth Library
     3  *
     4  * @file gmyth/gmyth_common.c
     5  * 
     6  * @brief <p> This file contains basic common functions for the gmyth library.
     7  *
     8  * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     9  * @author Leonardo Sobral Cunha <leonardo.cunha@indt.org.br>
    10  *
    11  *//*
    12  * 
    13  * This program is free software; you can redistribute it and/or modify
    14  * it under the terms of the GNU Lesser General Public License as published by
    15  * the Free Software Foundation; either version 2 of the License, or
    16  * (at your option) any later version.
    17  *
    18  * This program is distributed in the hope that it will be useful,
    19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21  * GNU General Public License for more details.
    22  *
    23  * You should have received a copy of the GNU Lesser General Public License
    24  * along with this program; if not, write to the Free Software
    25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    26  */
    27 
    28 #ifdef HAVE_CONFIG_H
    29 #include "config.h"
    30 #endif
    31 
    32 #include "gmyth_common.h"
    33 #include "gmyth_debug.h"
    34 #include "gmyth_util.h"
    35 
    36 static void free_channel_data(gpointer data, gpointer user_data);
    37 static void free_program_data(gpointer data, gpointer user_data);
    38 
    39 /** Frees the memory allocated to the GMythChannelInfo objects inside list.
    40  * The list memory is also released by g_list_free(). If LIST is NULL it
    41  * simply returns.
    42  * 
    43  * @param list the GList containing a list of GMythChannelInfo to free.
    44  */
    45 void 
    46 gmyth_free_channel_list(GList *list) 
    47 {
    48 	if (list == NULL) {
    49 		g_warning ("%s received null GList as parameter", __FUNCTION__);
    50 		return;
    51 	}
    52 	
    53 	g_list_foreach (list, free_channel_data, NULL);
    54 	
    55 	g_list_free (list);
    56 }
    57 
    58 /** Frees the memory allocated to the GMythProgramInfo objects inside list.
    59  * The list memory is also released by g_list_free(). If list is NULL it
    60  * simply returns.
    61  * 
    62  * @param list the GList containing a list of GMythProgramInfo to free.
    63  */
    64 void
    65 gmyth_free_program_list(GList *list)
    66 {
    67 	if (list == NULL) {
    68 		g_warning ("%s received null GList as parameter", __FUNCTION__);
    69 		return;
    70 	}
    71 	
    72 	g_list_foreach (list, free_program_data, NULL);
    73 	
    74 	g_list_free (list);
    75 }
    76 
    77 void 
    78 gmyth_channel_info_print(GMythChannelInfo *channel_info)
    79 {
    80 	if ( channel_info != NULL )
    81 	{
    82     gmyth_debug("ChannelInfo (Name, Num, ID) = (%s, %s, %d)\n", 
    83              channel_info->channel_name->str, channel_info->channel_num->str, 
    84              channel_info->channel_ID);
    85 	}
    86 }
    87 
    88 void 
    89 gmyth_program_info_print(GMythProgramInfo *program_info)
    90 {
    91 	
    92 	if ( program_info != NULL ) {
    93 		
    94 	  gmyth_debug( "ProgramInfo\n\tTitle = %s\n\t"
    95 	           "Description = %s\n\t"
    96 	           "Start time= %s\t"
    97 	           "End time = %s\n"
    98 	           "Path name = %s\n"
    99 	           "File size = %lld\n"
   100 	           , program_info->title->str,
   101 	           program_info->description->str, 
   102 	           gmyth_util_time_to_string_from_time_val(program_info->startts),
   103 	           gmyth_util_time_to_string_from_time_val(program_info->endts), 
   104 	           program_info->pathname->str,
   105 	           program_info->filesize );
   106 	           
   107 	}
   108 	
   109 }
   110 
   111 static void 
   112 free_channel_data(gpointer data, gpointer user_data)
   113 {
   114     if(data)
   115         g_free((GMythChannelInfo*) data);
   116 }
   117 
   118 static void
   119 free_program_data(gpointer data, gpointer user_data)
   120 {
   121     if(data)
   122         g_object_unref((GMythProgramInfo*) data);
   123 }
   124