gmyth/src/gmyth_recprofile.c
author rosfran
Tue Mar 27 21:31:34 2007 +0100 (2007-03-27)
branchtrunk
changeset 463 771f91aa9d5d
parent 385 ab93678082df
child 698 9019388af980
permissions -rw-r--r--
[svn r468] Function to free the remotely allocated TV tuner.
     1 /**
     2  * GMyth Library
     3  * 
     4  * @file gmyth/gmyth_recprofile.c
     5  * 
     6  * @brief <p> This file contains the recprofile class.
     7  *
     8  * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
     9  * @author Artur Duque de Souza <artur.souza@indt.org.br>
    10  *
    11  */
    12 /*
    13  * 
    14  * This program is free software; you can redistribute it and/or modify
    15  * it under the terms of the GNU Lesser General Public License as published by
    16  * the Free Software Foundation; either version 2 of the License, or
    17  * (at your option) any later version.
    18  *
    19  * This program is distributed in the hope that it will be useful,
    20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    22  * GNU General Public License for more details.
    23  *
    24  * You should have received a copy of the GNU Lesser General Public License
    25  * along with this program; if not, write to the Free Software
    26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    27  */
    28 
    29  
    30 #ifdef HAVE_CONFIG_H
    31 #include "config.h"
    32 #endif
    33 
    34 #include <stdlib.h>
    35 #include <string.h>
    36 #include <assert.h>
    37 
    38 #include "gmyth_recprofile.h"
    39 #include "gmyth_util.h"
    40 #include "gmyth_debug.h"
    41 #include "gmyth_http.h"
    42 
    43 static void gmyth_recprofile_class_init          (GMythRecProfileClass *klass);
    44 static void gmyth_recprofile_init                (GMythRecProfile *object);
    45 
    46 static void gmyth_recprofile_dispose  (GObject *object);
    47 static void gmyth_recprofile_finalize (GObject *object);
    48 
    49 G_DEFINE_TYPE(GMythRecProfile, gmyth_recprofile, G_TYPE_OBJECT)
    50 
    51 static void
    52 gmyth_recprofile_class_init (GMythRecProfileClass *klass)
    53 {
    54     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
    55     gobject_class->dispose  = gmyth_recprofile_dispose;
    56     gobject_class->finalize = gmyth_recprofile_finalize;
    57 }
    58 
    59 static void
    60 gmyth_recprofile_init (GMythRecProfile *recprofile)
    61 {
    62 }
    63 
    64 static void
    65 gmyth_recprofile_dispose (GObject *object)
    66 {
    67     GMythRecProfile *recprofile = GMYTH_RECPROFILE(object);
    68 
    69     if (recprofile->name)
    70         g_free(recprofile->name);
    71 
    72     if (recprofile->group)
    73         g_free(recprofile->group);
    74 
    75     if (recprofile->vcodec)
    76         g_free(recprofile->vcodec);
    77 
    78     if (recprofile->acodec)
    79         g_free(recprofile->acodec);
    80 
    81     if (recprofile->options)
    82         g_free(recprofile->options);
    83 
    84     G_OBJECT_CLASS (gmyth_recprofile_parent_class)->dispose (object);
    85 }
    86 
    87 static void
    88 gmyth_recprofile_finalize (GObject *object)
    89 {
    90     g_signal_handlers_destroy (object);
    91     G_OBJECT_CLASS (gmyth_recprofile_parent_class)->finalize (object);
    92 }
    93 
    94 /**
    95  * Creates a new instance of GMythRecProfile.
    96  * 
    97  * @return a new instance of GMythRecProfile.
    98  **/
    99 GMythRecProfile*
   100 gmyth_recprofile_new (void)
   101 {
   102     GMythRecProfile *recprofile = GMYTH_RECPROFILE\
   103                             (g_object_new(GMYTH_RECPROFILE_TYPE, NULL));
   104 
   105     recprofile->id = 0;
   106     recprofile->name = NULL;
   107     recprofile->group = NULL;
   108     recprofile->vcodec = NULL;
   109     recprofile->acodec = NULL;
   110     recprofile->options = NULL;
   111 
   112     return recprofile;
   113 }
   114 
   115 
   116 /**
   117  *
   118  * gmyth_recprofile_get_profile_list
   119  * @brief get profile list from the backend
   120  * @param backend_info GMythBackendInfo*
   121  * @return GSList
   122  *
   123  **/
   124 GSList* gmyth_recprofile_get_profile_list (GMythBackendInfo *backend_info)
   125 {
   126     return gmyth_http_retrieve_rec_profiles(backend_info, "Transcoders");
   127 }
   128 
   129 /**
   130  *
   131  * gmyth_recprofile_create_profile
   132  * @brief get profile list from the backend
   133  * @param backend_info GMythBackendInfo*
   134  * @param profile GMythRecProfile*
   135  * @return gint representing the result
   136  *
   137  **/
   138 gint gmyth_recprofile_create_profile (GMythBackendInfo *backend_info,
   139                                       GMythRecProfile* profile)
   140 {
   141     return gmyth_http_create_rec_profile (backend_info, profile);
   142 }
   143 
   144 /**
   145  *
   146  * gmyth_recprofile_del_profile
   147  * @brief del profile from the backend
   148  * @param backend_info GMythBackendInfo*
   149  * @param id profile's id
   150  * @return gint representing the result
   151  *
   152  **/
   153 gint gmyth_recprofile_del_profile_list (GMythBackendInfo *backend_info,
   154                                         gint id)
   155 {
   156     return gmyth_http_del_rec_profile(backend_info, id);
   157 }
   158 
   159 /**
   160  *
   161  * gmyth_recprofile_set_id
   162  * @brief set recprofile's id
   163  * @param rec GMythRecProfile*
   164  * @param id profile's id
   165  * @return gint representing the result
   166  *
   167  **/
   168 gint gmyth_recprofile_set_id (GMythRecProfile* rec, gint id)
   169 {
   170     rec->id = id;
   171     return 0;
   172 }
   173 
   174 /**
   175  *
   176  * gmyth_recprofile_set
   177  * @brief set recprofile's property
   178  * @param rec GMythRecProfile*
   179  * @param member the member you want to modify
   180  * @param value the value
   181  * @return gint representing the result
   182  *
   183  **/
   184 gint gmyth_recprofile_set (GMythRecProfile* rec, 
   185                            gchar* member, gchar* value)
   186 {
   187     int ret = 0;
   188     if (value != NULL)
   189     {
   190         if (g_ascii_strcasecmp(member, "name") == 0)
   191             rec->name = g_strndup(value, strlen(value));
   192         else
   193         if (g_ascii_strcasecmp(member, "group") == 0)
   194             rec->group = g_strndup(value, strlen(value));
   195         else
   196         if (g_ascii_strcasecmp(member, "vcodec") == 0)
   197             rec->vcodec = g_strndup(value, strlen(value));
   198         else
   199         if (g_ascii_strcasecmp(member, "acodec") == 0)
   200             rec->acodec = g_strndup(value, strlen(value));
   201         else
   202             ret = -1;
   203     }
   204     else 
   205         ret = -1;
   206 
   207     return ret;
   208 }
   209 
   210 /**
   211  *
   212  * gmyth_recprofile_set_name
   213  * @brief set recprofile's name
   214  * @param rec GMythRecProfile*
   215  * @param name profile's name
   216  * @return gint representing the result
   217  *
   218  **/
   219 gint gmyth_recprofile_set_name (GMythRecProfile* rec, gchar* name)
   220 {
   221     return gmyth_recprofile_set(rec, "name", name);
   222 }
   223 
   224 /**
   225  *
   226  * gmyth_recprofile_set_group
   227  * @brief set recprofile's group
   228  * @param rec GMythRecProfile*
   229  * @param group profile's group
   230  * @return gint representing the result
   231  *
   232  **/
   233 gint gmyth_recprofile_set_group (GMythRecProfile* rec, gchar* group)
   234 {
   235     return gmyth_recprofile_set(rec, "group", group);
   236 }
   237 
   238 /**
   239  *
   240  * gmyth_recprofile_set_vcodec
   241  * @brief set recprofile's vcodec
   242  * @param rec GMythRecProfile*
   243  * @param vcodec profile's vcodec
   244  * @return gint representing the result
   245  *
   246  **/
   247 gint gmyth_recprofile_set_vcodec (GMythRecProfile* rec, gchar* vcodec)
   248 {
   249     return gmyth_recprofile_set(rec, "vcodec", vcodec);
   250 }
   251 
   252 /**
   253  *
   254  * gmyth_recprofile_set_acodec
   255  * @brief set recprofile's acodec
   256  * @param rec GMythRecProfile*
   257  * @param acodec profile's acodec
   258  * @return gint representing the result
   259  *
   260  **/
   261 gint gmyth_recprofile_set_acodec (GMythRecProfile* rec, gchar* acodec)
   262 {
   263     return gmyth_recprofile_set(rec, "acodec", acodec);
   264 }
   265