[svn r468] Function to free the remotely allocated TV tuner.
4 * @file gmyth/gmyth_backend_info.c
6 * @brief <p> This component represents all the MythTV backend server
7 * configuration information.
9 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
10 * @author Hallyson Melo <hallyson.melo@indt.org.br>
11 * @author Rosfran Borges <rosfran.borges@indt.org.br>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "gmyth_backendinfo.h"
35 #include "gmyth_uri.h"
36 #include "gmyth_debug.h"
38 static void gmyth_backend_info_class_init (GMythBackendInfoClass *klass);
39 static void gmyth_backend_info_init (GMythBackendInfo *object);
41 static void gmyth_backend_info_dispose (GObject *object);
42 static void gmyth_backend_info_finalize (GObject *object);
44 G_DEFINE_TYPE(GMythBackendInfo, gmyth_backend_info, G_TYPE_OBJECT)
47 gmyth_backend_info_class_init (GMythBackendInfoClass *klass)
49 GObjectClass *gobject_class;
51 gobject_class = (GObjectClass *) klass;
53 gobject_class->dispose = gmyth_backend_info_dispose;
54 gobject_class->finalize = gmyth_backend_info_finalize;
58 gmyth_backend_info_init (GMythBackendInfo *backend_info)
60 backend_info->hostname = NULL;
61 backend_info->username = NULL;
62 backend_info->password = NULL;
63 backend_info->db_name = NULL;
64 backend_info->port = -1;
65 backend_info->status_port = -1;
69 gmyth_backend_info_dispose (GObject *object)
71 GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (object);
73 g_free (backend_info->hostname);
74 g_free (backend_info->username);
75 g_free (backend_info->password);
76 g_free (backend_info->db_name);
78 backend_info->hostname = NULL;
79 backend_info->username = NULL;
80 backend_info->password = NULL;
81 backend_info->db_name = NULL;
82 backend_info->port = -1;
83 backend_info->status_port = -1;
85 G_OBJECT_CLASS (gmyth_backend_info_parent_class)->dispose (object);
89 gmyth_backend_info_finalize (GObject *object)
91 g_signal_handlers_destroy (object);
93 G_OBJECT_CLASS (gmyth_backend_info_parent_class)->finalize (object);
97 * Creates a new instance of GMythBackendInfo.
99 * @return a new instance of GMythBackendInfo.
102 gmyth_backend_info_new ()
104 GMythBackendInfo *backend_info =
105 GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
111 * Creates a new instance of GMythBackendInfo, based on a given set of
112 * configuration parameters.
114 * @param hostname The hostname to the MythTV backend server.
115 * @param username The user name to the MythTV backend MySQL server.
116 * @param password The password to the user of the MythTV backend MySQL server.
117 * @param db_name The database name of the MythTV backend, stored on the MySQL server.
118 * @param port The port number of the MythTV backend server (commonly is 6543).
120 * @return a new instance of GMythBackendInfo.
123 gmyth_backend_info_new_full (const gchar *hostname, const gchar *username,
124 const gchar *password, const gchar *db_name, gint port)
126 GMythBackendInfo *backend_info =
127 GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
129 gmyth_backend_info_set_hostname (backend_info, hostname);
130 gmyth_backend_info_set_username (backend_info, username);
131 gmyth_backend_info_set_password (backend_info, password);
132 gmyth_backend_info_set_db_name (backend_info, db_name);
133 gmyth_backend_info_set_port (backend_info, port);
139 * Creates a new instance of GMythBackendInfo, based on the
140 * MythTV's backend server URI string.
142 * @param uri_str The URI string pointing to the MythTV backend server.
144 * @return a new instance of GMythBackendInfo.
147 gmyth_backend_info_new_with_uri ( const gchar *uri_str )
149 GMythBackendInfo *backend_info =
150 GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
152 GMythURI *uri = gmyth_uri_new_with_value( uri_str );
154 gchar** path_parts = g_strsplit( gmyth_uri_get_path (uri), "&", -1 );
156 gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri) );
157 gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user (uri) );
158 gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password (uri) );
160 /* gets the path info to database name, from the URI, and removes the trash chars */
161 gmyth_backend_info_set_db_name (backend_info, path_parts != NULL &&
162 strlen( path_parts[0] ) > 0 ?
163 g_strstrip( g_strdelimit( path_parts[0], "/?", ' ' ) )
164 : gmyth_uri_get_path (uri) );
166 gmyth_backend_info_set_port ( backend_info, gmyth_uri_get_port (uri) );
168 g_object_unref (uri);
169 g_strfreev( path_parts );
175 gmyth_backend_info_set_hostname (GMythBackendInfo *backend_info, const gchar *hostname)
177 g_return_if_fail (backend_info != NULL);
179 if ( NULL == hostname || strlen(hostname) <= 0 ) {
180 gmyth_debug ( "Error trying to set a hostname equals to NULL." );
182 backend_info->hostname = g_strdup (hostname);
187 gmyth_backend_info_set_username (GMythBackendInfo *backend_info, const gchar *username)
189 g_return_if_fail (backend_info != NULL);
191 backend_info->username = g_strdup (username);
195 gmyth_backend_info_set_password (GMythBackendInfo *backend_info, const gchar *password)
197 g_return_if_fail (backend_info != NULL);
199 backend_info->password = g_strdup (password);
203 gmyth_backend_info_set_db_name (GMythBackendInfo *backend_info, const gchar *db_name)
205 g_return_if_fail (backend_info != NULL);
207 backend_info->db_name = g_strdup (db_name);
211 gmyth_backend_info_set_port (GMythBackendInfo *backend_info, const gint port )
213 g_return_if_fail (backend_info != NULL);
216 gmyth_debug ( "Error trying to set a port less than 0." );
218 backend_info->port = port;
223 gmyth_backend_info_set_status_port (GMythBackendInfo *backend_info, const gint port )
225 g_return_if_fail (backend_info != NULL);
228 gmyth_debug ( "Error trying to set the status port to less than zero." );
230 backend_info->status_port = port;
235 gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info)
237 g_return_val_if_fail (backend_info != NULL, NULL);
239 return backend_info->hostname;
243 gmyth_backend_info_get_username (GMythBackendInfo *backend_info)
245 g_return_val_if_fail (backend_info != NULL, NULL);
247 return backend_info->username;
251 gmyth_backend_info_get_password (GMythBackendInfo *backend_info)
253 g_return_val_if_fail (backend_info != NULL, NULL);
255 return backend_info->password;
259 gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info)
261 g_return_val_if_fail (backend_info != NULL, NULL);
263 return backend_info->db_name;
267 gmyth_backend_info_get_port (GMythBackendInfo *backend_info)
269 g_return_val_if_fail (backend_info != NULL, -1);
271 return backend_info->port;
275 * Creates a new instance of GMythURI, based on the GMythBackendInfo instance to the
276 * MythTV's backend server.
278 * @param backend_info The GMythBackendInfo instance.
280 * @return an instance of GMythURI, created from a GMythBackendInfo.
283 gmyth_backend_info_get_uri (GMythBackendInfo *backend_info)
285 GMythURI *uri = NULL;
286 gchar* uri_str = g_strdup_printf( "myth://%s:%s@%s:%d/?%s", backend_info->username, backend_info->password,
287 backend_info->hostname, backend_info->port, backend_info->db_name );
288 uri = gmyth_uri_new_with_value (uri_str);