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