gmyth/src/gmyth_backendinfo.c
author rosfran
Wed Jan 10 22:47:28 2007 +0000 (2007-01-10)
branchtrunk
changeset 259 4644bd396464
parent 248 0f6b44cf56bb
child 261 2c550e80c419
permissions -rw-r--r--
[svn r260] Fixes references over libraries, such as the gmyth-0.1.
     1 
     2 /**
     3  * GMyth Library
     4  *
     5  * @file gmyth/gmyth_backend_info.c
     6  * 
     7  * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     8  * @author Hallyson Melo <hallyson.melo@indt.org.br>
     9  *
    10  *//*
    11  * 
    12  * This program is free software; you can redistribute it and/or modify
    13  * it under the terms of the GNU Lesser General Public License as published by
    14  * the Free Software Foundation; either version 2 of the License, or
    15  * (at your option) any later version.
    16  *
    17  * This program is distributed in the hope that it will be useful,
    18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  * GNU General Public License for more details.
    21  *
    22  * You should have received a copy of the GNU Lesser General Public License
    23  * along with this program; if not, write to the Free Software
    24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    25  */
    26  
    27 #ifdef HAVE_CONFIG_H
    28 #include "config.h"
    29 #endif
    30 
    31 #include "gmyth_backendinfo.h"
    32 #include "gmyth_uri.h"
    33 #include "gmyth_debug.h"
    34 
    35 static void gmyth_backend_info_class_init  (GMythBackendInfoClass *klass);
    36 static void gmyth_backend_info_init        (GMythBackendInfo *object);
    37 
    38 static void gmyth_backend_info_dispose  (GObject *object);
    39 static void gmyth_backend_info_finalize (GObject *object);
    40 
    41 G_DEFINE_TYPE(GMythBackendInfo, gmyth_backend_info, G_TYPE_OBJECT)
    42     
    43 static void
    44 gmyth_backend_info_class_init (GMythBackendInfoClass *klass)
    45 {
    46     GObjectClass *gobject_class;
    47 
    48     gobject_class = (GObjectClass *) klass;
    49 
    50     gobject_class->dispose  = gmyth_backend_info_dispose;
    51     gobject_class->finalize = gmyth_backend_info_finalize;	
    52 }
    53 
    54 static void
    55 gmyth_backend_info_init (GMythBackendInfo *backend_info)
    56 {
    57     backend_info->hostname = NULL;
    58     backend_info->username = NULL;
    59     backend_info->password = NULL;    
    60     backend_info->db_name  = NULL;
    61     backend_info->port = -1;
    62 }
    63 
    64 static void
    65 gmyth_backend_info_dispose  (GObject *object)
    66 {
    67     GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (object);
    68 
    69     g_free (backend_info->hostname);
    70     g_free (backend_info->username);
    71     g_free (backend_info->password);
    72     g_free (backend_info->db_name);
    73 
    74     backend_info->hostname = NULL;
    75     backend_info->username = NULL;
    76     backend_info->password = NULL;
    77     backend_info->db_name  = NULL;
    78     backend_info->port = -1;
    79 
    80     G_OBJECT_CLASS (gmyth_backend_info_parent_class)->dispose (object);
    81 }
    82 
    83 static void
    84 gmyth_backend_info_finalize (GObject *object)
    85 {
    86     g_signal_handlers_destroy (object);
    87 
    88     G_OBJECT_CLASS (gmyth_backend_info_parent_class)->finalize (object);
    89 }
    90 
    91 /** Creates a new instance of GMythBackendInfo.
    92  * 
    93  * @return a new instance of GMythBackendInfo.
    94  */
    95 GMythBackendInfo*
    96 gmyth_backend_info_new ()
    97 {
    98     GMythBackendInfo *backend_info = 
    99         GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
   100     
   101     return backend_info;
   102 }
   103 
   104 GMythBackendInfo*
   105 gmyth_backend_info_new_full (const gchar *hostname, const gchar *username,
   106 	const gchar *password, const gchar *db_name, gint port)
   107 {
   108     GMythBackendInfo *backend_info = 
   109         GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
   110 
   111     gmyth_backend_info_set_hostname (backend_info, hostname);
   112     gmyth_backend_info_set_username (backend_info, username);
   113     gmyth_backend_info_set_password (backend_info, password);
   114     gmyth_backend_info_set_db_name (backend_info, db_name);
   115     gmyth_backend_info_set_port (backend_info, port);
   116 
   117     return backend_info;
   118 }
   119 
   120 GMythBackendInfo*
   121 gmyth_backend_info_new_with_uri ( const gchar *uri_str )
   122 {
   123     GMythBackendInfo *backend_info = 
   124         GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
   125         
   126     GMythURI* uri = gmyth_uri_new_with_value( uri_str );
   127     
   128     gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri ) );
   129     gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( uri ) );
   130     gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password( uri ) );
   131     gmyth_backend_info_set_db_name (backend_info, strlen( gmyth_uri_get_fragment( uri ) ) > 0 
   132     				? gmyth_uri_get_fragment( uri ) : gmyth_uri_get_query( uri ) );
   133     gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port( uri ) );
   134 		
   135     return backend_info;
   136 }
   137 
   138 void
   139 gmyth_backend_info_set_hostname (GMythBackendInfo *backend_info, const gchar *hostname)
   140 {
   141     g_return_if_fail (backend_info != NULL);
   142     
   143     if ( NULL == hostname || strlen(hostname) <= 0 )
   144     { 
   145 	gmyth_debug ( "Error trying to set a hostname equals to NULL (it doesn't using UPnP)." );
   146     } else {    	
   147     	backend_info->hostname = g_strdup (hostname);
   148     }
   149 }
   150 
   151 void
   152 gmyth_backend_info_set_username (GMythBackendInfo *backend_info, const gchar *username)
   153 {
   154     g_return_if_fail (backend_info != NULL);
   155 
   156     backend_info->username = g_strdup (username);
   157 }
   158 
   159 void
   160 gmyth_backend_info_set_password (GMythBackendInfo *backend_info, const gchar *password)
   161 {
   162     g_return_if_fail (backend_info != NULL);
   163 
   164     backend_info->password = g_strdup (password);
   165 }
   166 
   167 void
   168 gmyth_backend_info_set_db_name (GMythBackendInfo *backend_info, const gchar *db_name)
   169 {
   170     g_return_if_fail (backend_info != NULL);
   171 
   172     backend_info->db_name = g_strdup (db_name);
   173 }
   174 
   175 void
   176 gmyth_backend_info_set_port (GMythBackendInfo *backend_info, const gint port )
   177 {
   178     g_return_if_fail (backend_info != NULL);
   179 
   180     if ( port <= 0 )
   181     { 
   182         gmyth_debug ( "Error trying to set a hostname equals to NULL (it doesn't using UPnP)." );
   183     } else {    	
   184     	backend_info->port = port;
   185     }
   186 }
   187 
   188 const gchar*
   189 gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info)
   190 {
   191     g_return_val_if_fail (backend_info != NULL, NULL);
   192 
   193     return backend_info->hostname;
   194 }
   195 
   196 const gchar*
   197 gmyth_backend_info_get_username (GMythBackendInfo *backend_info)
   198 {
   199     g_return_val_if_fail (backend_info != NULL, NULL);
   200 
   201     return backend_info->username;
   202 }
   203 
   204 const gchar*
   205 gmyth_backend_info_get_password (GMythBackendInfo *backend_info)
   206 {
   207     g_return_val_if_fail (backend_info != NULL, NULL);
   208 
   209     return backend_info->password;
   210 }
   211 
   212 const gchar*
   213 gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info)
   214 {
   215     g_return_val_if_fail (backend_info != NULL, NULL);
   216 
   217     return backend_info->db_name;
   218 }
   219 
   220 gint
   221 gmyth_backend_info_get_port (GMythBackendInfo *backend_info)
   222 {
   223     g_return_val_if_fail (backend_info != NULL, -1);
   224 
   225     return backend_info->port;
   226 }
   227