[svn r426] Put more DOxygen documentation.
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 && path_parts[0] != NULL
162 && strlen( path_parts[0] ) > 0 ? g_strstrip( g_strdup( g_strdelimit( path_parts[0], "/?", ' ' ) ) )
163 : gmyth_uri_get_path (uri) );
164 gmyth_backend_info_set_port ( backend_info, gmyth_uri_get_port (uri) );
166 g_object_unref (uri);
167 g_strfreev( path_parts );
173 gmyth_backend_info_set_hostname (GMythBackendInfo *backend_info, const gchar *hostname)
175 g_return_if_fail (backend_info != NULL);
177 if ( NULL == hostname || strlen(hostname) <= 0 ) {
178 gmyth_debug ( "Error trying to set a hostname equals to NULL." );
180 backend_info->hostname = g_strdup (hostname);
185 gmyth_backend_info_set_username (GMythBackendInfo *backend_info, const gchar *username)
187 g_return_if_fail (backend_info != NULL);
189 backend_info->username = g_strdup (username);
193 gmyth_backend_info_set_password (GMythBackendInfo *backend_info, const gchar *password)
195 g_return_if_fail (backend_info != NULL);
197 backend_info->password = g_strdup (password);
201 gmyth_backend_info_set_db_name (GMythBackendInfo *backend_info, const gchar *db_name)
203 g_return_if_fail (backend_info != NULL);
205 backend_info->db_name = g_strdup (db_name);
209 gmyth_backend_info_set_port (GMythBackendInfo *backend_info, const gint port )
211 g_return_if_fail (backend_info != NULL);
214 gmyth_debug ( "Error trying to set a port less than 0." );
216 backend_info->port = port;
221 gmyth_backend_info_set_status_port (GMythBackendInfo *backend_info, const gint port )
223 g_return_if_fail (backend_info != NULL);
226 gmyth_debug ( "Error trying to set the status port to less than zero." );
228 backend_info->status_port = port;
233 gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info)
235 g_return_val_if_fail (backend_info != NULL, NULL);
237 return backend_info->hostname;
241 gmyth_backend_info_get_username (GMythBackendInfo *backend_info)
243 g_return_val_if_fail (backend_info != NULL, NULL);
245 return backend_info->username;
249 gmyth_backend_info_get_password (GMythBackendInfo *backend_info)
251 g_return_val_if_fail (backend_info != NULL, NULL);
253 return backend_info->password;
257 gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info)
259 g_return_val_if_fail (backend_info != NULL, NULL);
261 return backend_info->db_name;
265 gmyth_backend_info_get_port (GMythBackendInfo *backend_info)
267 g_return_val_if_fail (backend_info != NULL, -1);
269 return backend_info->port;
273 * Creates a new instance of GMythURI, based on the GMythBackendInfo instance to the
274 * MythTV's backend server.
276 * @param backend_info The GMythBackendInfo instance.
278 * @return an instance of GMythURI, created from a GMythBackendInfo.
281 gmyth_backend_info_get_uri (GMythBackendInfo *backend_info)
283 GMythURI *uri = NULL;
284 gchar* uri_str = g_strdup_printf( "myth://%s:%s@%s:%d/?%s", backend_info->username, backend_info->password,
285 backend_info->hostname, backend_info->port, backend_info->db_name );
286 uri = gmyth_uri_new_with_value (uri_str);