gmyth/src/gmyth_common.c
author renatofilho
Tue Aug 07 16:00:49 2007 +0100 (2007-08-07)
branchtrunk
changeset 797 7563dc4ed8d5
parent 750 312d6bc514f3
permissions -rw-r--r--
[svn r803] copyright fixed
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
 *
renatofilho@754
    12
 * 
renatofilho@754
    13
 * This program is free software; you can redistribute it and/or modify
renatofilho@754
    14
 * it under the terms of the GNU Lesser General Public License as published by
renatofilho@754
    15
 * the Free Software Foundation; either version 2 of the License, or
renatofilho@754
    16
 * (at your option) any later version.
renatofilho@754
    17
 *
renatofilho@754
    18
 * This program is distributed in the hope that it will be useful,
renatofilho@754
    19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
renatofilho@754
    20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
renatofilho@754
    21
 * GNU General Public License for more details.
renatofilho@754
    22
 *
renatofilho@754
    23
 * You should have received a copy of the GNU Lesser General Public License
renatofilho@754
    24
 * along with this program; if not, write to the Free Software
renatofilho@754
    25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
renatofilho@754
    26
 */
leo_sobral@1
    27
leo_sobral@213
    28
#ifdef HAVE_CONFIG_H
leo_sobral@213
    29
#include "config.h"
leo_sobral@213
    30
#endif
leo_sobral@213
    31
leo_sobral@1
    32
#include "gmyth_common.h"
renatofilho@131
    33
#include "gmyth_debug.h"
rosfran@219
    34
#include "gmyth_util.h"
leo_sobral@1
    35
renatofilho@754
    36
static void     free_channel_data(gpointer data, gpointer user_data);
renatofilho@754
    37
static void     free_program_data(gpointer data, gpointer user_data);
leo_sobral@1
    38
renatofilho@754
    39
/** 
renatofilho@754
    40
* Frees the memory allocated to the GMythChannelInfo objects inside list.
renatofilho@754
    41
* The list memory is also released by g_list_free(). If LIST is NULL it
renatofilho@754
    42
* simply returns.
renatofilho@754
    43
* 
renatofilho@754
    44
* @param list the GList containing a list of GMythChannelInfo to free.
renatofilho@754
    45
*/
rosfran@698
    46
void
renatofilho@750
    47
gmyth_free_channel_list(GList * list)
leo_sobral@1
    48
{
renatofilho@754
    49
    g_return_if_fail(list != NULL);
rosfran@698
    50
renatofilho@754
    51
    g_list_foreach(list, free_channel_data, NULL);
renatofilho@754
    52
    g_list_free(list);
leo_sobral@1
    53
}
leo_sobral@1
    54
melunko@412
    55
/** 
melunko@412
    56
 * Frees the memory allocated to the GMythProgramInfo objects inside list.
leo_sobral@1
    57
 * The list memory is also released by g_list_free(). If list is NULL it
leo_sobral@1
    58
 * simply returns.
leo_sobral@1
    59
 * 
leo_sobral@1
    60
 * @param list the GList containing a list of GMythProgramInfo to free.
leo_sobral@1
    61
 */
leo_sobral@1
    62
void
renatofilho@750
    63
gmyth_free_program_list(GList * list)
leo_sobral@1
    64
{
renatofilho@754
    65
    g_return_if_fail(list != NULL);
rosfran@698
    66
renatofilho@754
    67
    g_list_foreach(list, free_program_data, NULL);
renatofilho@754
    68
    g_list_free(list);
leo_sobral@1
    69
}
leo_sobral@1
    70
melunko@583
    71
void
renatofilho@750
    72
gmyth_channel_info_free(GMythChannelInfo * channel)
melunko@583
    73
{
renatofilho@754
    74
    g_return_if_fail(channel != NULL);
melunko@583
    75
renatofilho@754
    76
    if (channel->channel_num)
renatofilho@754
    77
        g_string_free(channel->channel_num, TRUE);
melunko@583
    78
renatofilho@754
    79
    if (channel->channel_name)
renatofilho@754
    80
        g_string_free(channel->channel_name, TRUE);
melunko@583
    81
renatofilho@754
    82
    if (channel->channel_icon)
renatofilho@754
    83
        g_string_free(channel->channel_icon, TRUE);
melunko@583
    84
renatofilho@754
    85
    g_free(channel);
melunko@583
    86
}
melunko@583
    87
melunko@412
    88
/**
melunko@412
    89
 * Prints the channel info to the standard output. The gmyth debug must be enabled.
melunko@412
    90
 * @param channel_info the GMythChannelInfo instance
melunko@412
    91
 */
rosfran@698
    92
void
renatofilho@750
    93
gmyth_channel_info_print(GMythChannelInfo * channel_info)
leo_sobral@49
    94
{
melunko@576
    95
#ifdef GMYTH_USE_DEBUG
renatofilho@754
    96
    if (channel_info != NULL) {
renatofilho@754
    97
        g_return_if_fail(channel_info->channel_name != NULL);
renatofilho@754
    98
        g_return_if_fail(channel_info->channel_num != NULL);
melunko@590
    99
renatofilho@754
   100
        gmyth_debug("ChannelInfo (Name, Num, ID) = (%s, %s, %d)",
renatofilho@754
   101
                    channel_info->channel_name->str,
renatofilho@754
   102
                    channel_info->channel_num->str,
renatofilho@754
   103
                    channel_info->channel_ID);
melunko@590
   104
renatofilho@754
   105
    }
melunko@576
   106
#endif
leo_sobral@49
   107
}
leo_sobral@49
   108
melunko@412
   109
/**
melunko@412
   110
 * Prints the program info to the standard output. The gmyth debug must be enabled.
melunko@412
   111
 * @param channel_info the GMythProgramInfo instance
melunko@412
   112
 */
rosfran@698
   113
void
renatofilho@750
   114
gmyth_program_info_print(GMythProgramInfo * program_info)
leo_sobral@49
   115
{
melunko@576
   116
#ifdef GMYTH_USE_DEBUG
renatofilho@754
   117
    g_return_if_fail(program_info);
melunko@412
   118
renatofilho@754
   119
    gmyth_debug("ProgramInfo\n\tTitle = %s\n\t"
renatofilho@754
   120
                "Description = %s\n\t"
renatofilho@754
   121
                "Start time= %s\t"
renatofilho@754
   122
                "End time = %s\n"
renatofilho@754
   123
                "Path name = %s\n"
renatofilho@754
   124
                "File size = %lld\n",
renatofilho@754
   125
                program_info->title ? program_info->title->str : "NULL",
renatofilho@754
   126
                program_info->description ? program_info->description->
renatofilho@754
   127
                str : "NULL",
renatofilho@754
   128
                gmyth_util_time_to_string_from_time_val(program_info->
renatofilho@754
   129
                                                        startts),
renatofilho@754
   130
                gmyth_util_time_to_string_from_time_val(program_info->
renatofilho@754
   131
                                                        endts),
renatofilho@754
   132
                program_info->pathname ? program_info->pathname->
renatofilho@754
   133
                str : "NULL", program_info->filesize);
melunko@576
   134
#endif
leo_sobral@49
   135
}
leo_sobral@1
   136
rosfran@698
   137
static void
renatofilho@750
   138
free_channel_data(gpointer data, gpointer user_data)
leo_sobral@1
   139
{
renatofilho@754
   140
    /*
renatofilho@754
   141
     * Frees the GMythChannelInfo structure 
renatofilho@754
   142
     */
renatofilho@754
   143
    GMythChannelInfo *channel = (GMythChannelInfo *) data;
melunko@583
   144
renatofilho@754
   145
    gmyth_channel_info_free(channel);
leo_sobral@1
   146
}
leo_sobral@1
   147
leo_sobral@1
   148
static void
renatofilho@750
   149
free_program_data(gpointer data, gpointer user_data)
leo_sobral@1
   150
{
renatofilho@754
   151
    g_return_if_fail(data != NULL);
melunko@412
   152
renatofilho@754
   153
    g_object_unref((GMythProgramInfo *) data);
leo_sobral@1
   154
}