gmyth/src/gmyth_common.c
author renatofilho
Thu Jun 14 20:40:47 2007 +0100 (2007-06-14)
branchtrunk
changeset 754 cb885ee44618
parent 750 312d6bc514f3
permissions -rw-r--r--
[svn r760] changed code style to Kernel Normal Form style with tabsize=4
     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  * @author Rosfran Borges <rosfran.borges@indt.org.br>
    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 /** 
    40 * Frees the memory allocated to the GMythChannelInfo objects inside list.
    41 * The list memory is also released by g_list_free(). If LIST is NULL it
    42 * simply returns.
    43 * 
    44 * @param list the GList containing a list of GMythChannelInfo to free.
    45 */
    46 void
    47 gmyth_free_channel_list(GList * list)
    48 {
    49     g_return_if_fail(list != NULL);
    50 
    51     g_list_foreach(list, free_channel_data, NULL);
    52     g_list_free(list);
    53 }
    54 
    55 /** 
    56  * Frees the memory allocated to the GMythProgramInfo objects inside list.
    57  * The list memory is also released by g_list_free(). If list is NULL it
    58  * simply returns.
    59  * 
    60  * @param list the GList containing a list of GMythProgramInfo to free.
    61  */
    62 void
    63 gmyth_free_program_list(GList * list)
    64 {
    65     g_return_if_fail(list != NULL);
    66 
    67     g_list_foreach(list, free_program_data, NULL);
    68     g_list_free(list);
    69 }
    70 
    71 void
    72 gmyth_channel_info_free(GMythChannelInfo * channel)
    73 {
    74     g_return_if_fail(channel != NULL);
    75 
    76     if (channel->channel_num)
    77         g_string_free(channel->channel_num, TRUE);
    78 
    79     if (channel->channel_name)
    80         g_string_free(channel->channel_name, TRUE);
    81 
    82     if (channel->channel_icon)
    83         g_string_free(channel->channel_icon, TRUE);
    84 
    85     g_free(channel);
    86 }
    87 
    88 /**
    89  * Prints the channel info to the standard output. The gmyth debug must be enabled.
    90  * @param channel_info the GMythChannelInfo instance
    91  */
    92 void
    93 gmyth_channel_info_print(GMythChannelInfo * channel_info)
    94 {
    95 #ifdef GMYTH_USE_DEBUG
    96     if (channel_info != NULL) {
    97         g_return_if_fail(channel_info->channel_name != NULL);
    98         g_return_if_fail(channel_info->channel_num != NULL);
    99 
   100         gmyth_debug("ChannelInfo (Name, Num, ID) = (%s, %s, %d)",
   101                     channel_info->channel_name->str,
   102                     channel_info->channel_num->str,
   103                     channel_info->channel_ID);
   104 
   105     }
   106 #endif
   107 }
   108 
   109 /**
   110  * Prints the program info to the standard output. The gmyth debug must be enabled.
   111  * @param channel_info the GMythProgramInfo instance
   112  */
   113 void
   114 gmyth_program_info_print(GMythProgramInfo * program_info)
   115 {
   116 #ifdef GMYTH_USE_DEBUG
   117     g_return_if_fail(program_info);
   118 
   119     gmyth_debug("ProgramInfo\n\tTitle = %s\n\t"
   120                 "Description = %s\n\t"
   121                 "Start time= %s\t"
   122                 "End time = %s\n"
   123                 "Path name = %s\n"
   124                 "File size = %lld\n",
   125                 program_info->title ? program_info->title->str : "NULL",
   126                 program_info->description ? program_info->description->
   127                 str : "NULL",
   128                 gmyth_util_time_to_string_from_time_val(program_info->
   129                                                         startts),
   130                 gmyth_util_time_to_string_from_time_val(program_info->
   131                                                         endts),
   132                 program_info->pathname ? program_info->pathname->
   133                 str : "NULL", program_info->filesize);
   134 #endif
   135 }
   136 
   137 static void
   138 free_channel_data(gpointer data, gpointer user_data)
   139 {
   140     /*
   141      * Frees the GMythChannelInfo structure 
   142      */
   143     GMythChannelInfo *channel = (GMythChannelInfo *) data;
   144 
   145     gmyth_channel_info_free(channel);
   146 }
   147 
   148 static void
   149 free_program_data(gpointer data, gpointer user_data)
   150 {
   151     g_return_if_fail(data != NULL);
   152 
   153     g_object_unref((GMythProgramInfo *) data);
   154 }