gmyth/src/gmyth_backendinfo.c
author rosfran
Tue Apr 03 19:39:23 2007 +0100 (2007-04-03)
branchtrunk
changeset 486 56b98fd15019
parent 446 d260ed30f4de
child 529 dfa28b22a36c
permissions -rw-r--r--
[svn r491] Solve bug with the --enable-debug on configure.ac; reversed changes in the GMythBackendInfo object; procedure to close the Recorder in not mandatory.
melunko@117
     1
/**
melunko@117
     2
 * GMyth Library
melunko@117
     3
 *
melunko@117
     4
 * @file gmyth/gmyth_backend_info.c
melunko@117
     5
 * 
rosfran@420
     6
 * @brief <p> This component represents all the MythTV backend server
rosfran@420
     7
 * 						configuration information.
rosfran@420
     8
 *
melunko@117
     9
 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
melunko@117
    10
 * @author Hallyson Melo <hallyson.melo@indt.org.br>
rosfran@420
    11
 * @author Rosfran Borges <rosfran.borges@indt.org.br>
melunko@117
    12
 *
melunko@117
    13
 *//*
melunko@117
    14
 * 
melunko@117
    15
 * This program is free software; you can redistribute it and/or modify
melunko@117
    16
 * it under the terms of the GNU Lesser General Public License as published by
melunko@117
    17
 * the Free Software Foundation; either version 2 of the License, or
melunko@117
    18
 * (at your option) any later version.
melunko@117
    19
 *
melunko@117
    20
 * This program is distributed in the hope that it will be useful,
melunko@117
    21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
melunko@117
    22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
melunko@117
    23
 * GNU General Public License for more details.
melunko@117
    24
 *
melunko@117
    25
 * You should have received a copy of the GNU Lesser General Public License
melunko@117
    26
 * along with this program; if not, write to the Free Software
melunko@117
    27
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
melunko@117
    28
 */
leo_sobral@213
    29
 
leo_sobral@213
    30
#ifdef HAVE_CONFIG_H
leo_sobral@213
    31
#include "config.h"
leo_sobral@213
    32
#endif
melunko@117
    33
melunko@117
    34
#include "gmyth_backendinfo.h"
rosfran@119
    35
#include "gmyth_uri.h"
renatofilho@131
    36
#include "gmyth_debug.h"
melunko@117
    37
melunko@117
    38
static void gmyth_backend_info_class_init  (GMythBackendInfoClass *klass);
melunko@117
    39
static void gmyth_backend_info_init        (GMythBackendInfo *object);
melunko@117
    40
melunko@117
    41
static void gmyth_backend_info_dispose  (GObject *object);
melunko@117
    42
static void gmyth_backend_info_finalize (GObject *object);
melunko@117
    43
melunko@117
    44
G_DEFINE_TYPE(GMythBackendInfo, gmyth_backend_info, G_TYPE_OBJECT)
melunko@117
    45
    
melunko@117
    46
static void
melunko@117
    47
gmyth_backend_info_class_init (GMythBackendInfoClass *klass)
melunko@117
    48
{
melunko@117
    49
    GObjectClass *gobject_class;
melunko@117
    50
melunko@117
    51
    gobject_class = (GObjectClass *) klass;
melunko@117
    52
melunko@117
    53
    gobject_class->dispose  = gmyth_backend_info_dispose;
melunko@117
    54
    gobject_class->finalize = gmyth_backend_info_finalize;	
melunko@117
    55
}
melunko@117
    56
melunko@117
    57
static void
melunko@117
    58
gmyth_backend_info_init (GMythBackendInfo *backend_info)
melunko@117
    59
{
melunko@117
    60
    backend_info->hostname = NULL;
melunko@117
    61
    backend_info->username = NULL;
rosfran@178
    62
    backend_info->password = NULL;    
melunko@117
    63
    backend_info->db_name  = NULL;
melunko@117
    64
    backend_info->port = -1;
melunko@412
    65
    backend_info->status_port = -1;
melunko@117
    66
}
melunko@117
    67
melunko@117
    68
static void
melunko@117
    69
gmyth_backend_info_dispose  (GObject *object)
melunko@117
    70
{
melunko@117
    71
    GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (object);
melunko@117
    72
melunko@117
    73
    g_free (backend_info->hostname);
melunko@117
    74
    g_free (backend_info->username);
melunko@117
    75
    g_free (backend_info->password);
melunko@117
    76
    g_free (backend_info->db_name);
melunko@117
    77
melunko@117
    78
    backend_info->hostname = NULL;
melunko@117
    79
    backend_info->username = NULL;
melunko@117
    80
    backend_info->password = NULL;
melunko@117
    81
    backend_info->db_name  = NULL;
melunko@117
    82
    backend_info->port = -1;
melunko@412
    83
    backend_info->status_port = -1;
melunko@117
    84
melunko@117
    85
    G_OBJECT_CLASS (gmyth_backend_info_parent_class)->dispose (object);
melunko@117
    86
}
melunko@117
    87
melunko@117
    88
static void
melunko@117
    89
gmyth_backend_info_finalize (GObject *object)
melunko@117
    90
{
melunko@117
    91
    g_signal_handlers_destroy (object);
melunko@117
    92
melunko@117
    93
    G_OBJECT_CLASS (gmyth_backend_info_parent_class)->finalize (object);
melunko@117
    94
}
melunko@117
    95
rosfran@421
    96
/** 
rosfran@421
    97
 * Creates a new instance of GMythBackendInfo.
melunko@117
    98
 * 
melunko@117
    99
 * @return a new instance of GMythBackendInfo.
melunko@117
   100
 */
melunko@117
   101
GMythBackendInfo*
melunko@117
   102
gmyth_backend_info_new ()
melunko@117
   103
{
melunko@117
   104
    GMythBackendInfo *backend_info = 
melunko@117
   105
        GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
melunko@117
   106
    
melunko@117
   107
    return backend_info;
melunko@117
   108
}
melunko@117
   109
rosfran@421
   110
/** 
rosfran@421
   111
 * Creates a new instance of GMythBackendInfo, based on a given set of 
rosfran@421
   112
 * configuration parameters.
rosfran@421
   113
 * 
rosfran@421
   114
 * @param hostname The hostname to the MythTV backend server.
rosfran@421
   115
 * @param username The user name to the MythTV backend MySQL server.
rosfran@421
   116
 * @param password The password to the user of the MythTV backend MySQL server.
rosfran@421
   117
 * @param db_name The database name of the MythTV backend, stored on the MySQL server.
rosfran@421
   118
 * @param port The port number of the MythTV backend server (commonly is 6543).
rosfran@421
   119
 * 
rosfran@421
   120
 * @return a new instance of GMythBackendInfo.
rosfran@421
   121
 */
melunko@117
   122
GMythBackendInfo*
rosfran@178
   123
gmyth_backend_info_new_full (const gchar *hostname, const gchar *username,
rosfran@178
   124
	const gchar *password, const gchar *db_name, gint port)
melunko@117
   125
{
melunko@117
   126
    GMythBackendInfo *backend_info = 
melunko@117
   127
        GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
rosfran@242
   128
melunko@117
   129
    gmyth_backend_info_set_hostname (backend_info, hostname);
melunko@117
   130
    gmyth_backend_info_set_username (backend_info, username);
melunko@117
   131
    gmyth_backend_info_set_password (backend_info, password);
melunko@117
   132
    gmyth_backend_info_set_db_name (backend_info, db_name);
melunko@117
   133
    gmyth_backend_info_set_port (backend_info, port);
melunko@117
   134
melunko@117
   135
    return backend_info;
melunko@117
   136
}
melunko@117
   137
rosfran@421
   138
/** 
rosfran@421
   139
 * Creates a new instance of GMythBackendInfo, based on the 
rosfran@421
   140
 * MythTV's backend server URI string.
rosfran@421
   141
 * 
rosfran@421
   142
 * @param uri_str The URI string pointing to the MythTV backend server.
rosfran@421
   143
 * 
rosfran@421
   144
 * @return a new instance of GMythBackendInfo.
rosfran@421
   145
 */
rosfran@119
   146
GMythBackendInfo*
rosfran@123
   147
gmyth_backend_info_new_with_uri ( const gchar *uri_str )
rosfran@119
   148
{
rosfran@119
   149
    GMythBackendInfo *backend_info = 
rosfran@119
   150
        GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
rosfran@119
   151
        
melunko@412
   152
    GMythURI *uri = gmyth_uri_new_with_value( uri_str );
rosfran@119
   153
    
melunko@412
   154
    gchar** path_parts = g_strsplit( gmyth_uri_get_path (uri), "&", -1 );
rosfran@280
   155
    
melunko@412
   156
    gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri) );
melunko@412
   157
    gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user (uri) );
melunko@412
   158
    gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password (uri) );
melunko@412
   159
rosfran@280
   160
    /* gets the path info to database name, from the URI, and removes the trash chars */
leo_sobral@446
   161
    gmyth_backend_info_set_db_name (backend_info, path_parts != NULL && 
leo_sobral@446
   162
                                    strlen( path_parts[0] ) > 0 ? 
leo_sobral@446
   163
                                        g_strstrip( g_strdelimit( path_parts[0], "/?", ' ' ) )
leo_sobral@446
   164
                						: gmyth_uri_get_path (uri) );
leo_sobral@446
   165
melunko@412
   166
    gmyth_backend_info_set_port ( backend_info, gmyth_uri_get_port (uri) );
rosfran@280
   167
    
melunko@412
   168
    g_object_unref (uri);
rosfran@280
   169
    g_strfreev( path_parts );
rosfran@178
   170
		
rosfran@119
   171
    return backend_info;
rosfran@119
   172
}
rosfran@119
   173
melunko@117
   174
void
rosfran@178
   175
gmyth_backend_info_set_hostname (GMythBackendInfo *backend_info, const gchar *hostname)
melunko@117
   176
{
melunko@117
   177
    g_return_if_fail (backend_info != NULL);
rosfran@242
   178
    
melunko@412
   179
    if ( NULL == hostname || strlen(hostname) <= 0 ) { 
melunko@412
   180
        gmyth_debug ( "Error trying to set a hostname equals to NULL." );
rosfran@242
   181
    } else {    	
melunko@412
   182
        backend_info->hostname = g_strdup (hostname);
rosfran@242
   183
    }
melunko@117
   184
}
melunko@117
   185
melunko@117
   186
void
rosfran@178
   187
gmyth_backend_info_set_username (GMythBackendInfo *backend_info, const gchar *username)
melunko@117
   188
{
melunko@117
   189
    g_return_if_fail (backend_info != NULL);
melunko@117
   190
melunko@117
   191
    backend_info->username = g_strdup (username);
melunko@117
   192
}
melunko@117
   193
melunko@117
   194
void
rosfran@178
   195
gmyth_backend_info_set_password (GMythBackendInfo *backend_info, const gchar *password)
melunko@117
   196
{
melunko@117
   197
    g_return_if_fail (backend_info != NULL);
melunko@117
   198
melunko@117
   199
    backend_info->password = g_strdup (password);
melunko@117
   200
}
melunko@117
   201
melunko@117
   202
void
rosfran@178
   203
gmyth_backend_info_set_db_name (GMythBackendInfo *backend_info, const gchar *db_name)
melunko@117
   204
{
melunko@117
   205
    g_return_if_fail (backend_info != NULL);
melunko@117
   206
melunko@117
   207
    backend_info->db_name = g_strdup (db_name);
melunko@117
   208
}
melunko@117
   209
rosfran@119
   210
void
rosfran@486
   211
gmyth_backend_info_set_port (GMythBackendInfo *backend_info, gint port )
rosfran@119
   212
{
rosfran@119
   213
    g_return_if_fail (backend_info != NULL);
rosfran@119
   214
melunko@412
   215
    if ( port <= 0 ) { 
melunko@412
   216
        gmyth_debug ( "Error trying to set a port less than 0." );
rosfran@242
   217
    } else {    	
melunko@412
   218
        backend_info->port = port;
rosfran@242
   219
    }
rosfran@119
   220
}
rosfran@119
   221
morphbr@352
   222
void
rosfran@486
   223
gmyth_backend_info_set_status_port (GMythBackendInfo *backend_info, gint port )
morphbr@352
   224
{
morphbr@352
   225
    g_return_if_fail (backend_info != NULL);
morphbr@352
   226
melunko@412
   227
    if ( port <= 0 ) { 
melunko@412
   228
        gmyth_debug ( "Error trying to set the status port to less than zero." );
morphbr@352
   229
    } else {    	
melunko@412
   230
        backend_info->status_port = port;
morphbr@352
   231
    }
morphbr@352
   232
}
morphbr@352
   233
renatofilho@189
   234
const gchar*
melunko@117
   235
gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info)
melunko@117
   236
{
melunko@117
   237
    g_return_val_if_fail (backend_info != NULL, NULL);
melunko@117
   238
melunko@117
   239
    return backend_info->hostname;
melunko@117
   240
}
melunko@117
   241
renatofilho@189
   242
const gchar*
melunko@117
   243
gmyth_backend_info_get_username (GMythBackendInfo *backend_info)
melunko@117
   244
{
melunko@117
   245
    g_return_val_if_fail (backend_info != NULL, NULL);
melunko@117
   246
melunko@117
   247
    return backend_info->username;
melunko@117
   248
}
melunko@117
   249
renatofilho@189
   250
const gchar*
melunko@117
   251
gmyth_backend_info_get_password (GMythBackendInfo *backend_info)
melunko@117
   252
{
melunko@117
   253
    g_return_val_if_fail (backend_info != NULL, NULL);
melunko@117
   254
melunko@117
   255
    return backend_info->password;
melunko@117
   256
}
melunko@117
   257
renatofilho@189
   258
const gchar*
melunko@117
   259
gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info)
melunko@117
   260
{
melunko@117
   261
    g_return_val_if_fail (backend_info != NULL, NULL);
melunko@117
   262
melunko@117
   263
    return backend_info->db_name;
melunko@117
   264
}
melunko@117
   265
melunko@117
   266
gint
melunko@117
   267
gmyth_backend_info_get_port (GMythBackendInfo *backend_info)
melunko@117
   268
{
melunko@117
   269
    g_return_val_if_fail (backend_info != NULL, -1);
melunko@117
   270
melunko@117
   271
    return backend_info->port;
melunko@117
   272
}
rosfran@178
   273
rosfran@421
   274
/** 
rosfran@421
   275
 * Creates a new instance of GMythURI, based on the GMythBackendInfo instance to the 
rosfran@421
   276
 * MythTV's backend server.
rosfran@421
   277
 * 
rosfran@421
   278
 * @param backend_info The GMythBackendInfo instance.
rosfran@421
   279
 * 
rosfran@421
   280
 * @return an instance of GMythURI, created from a GMythBackendInfo.
rosfran@421
   281
 */
melunko@412
   282
GMythURI*
rosfran@307
   283
gmyth_backend_info_get_uri (GMythBackendInfo *backend_info)
rosfran@307
   284
{
melunko@412
   285
    GMythURI *uri = NULL;
melunko@412
   286
    gchar* uri_str = g_strdup_printf( "myth://%s:%s@%s:%d/?%s", backend_info->username, backend_info->password,
melunko@412
   287
                                           backend_info->hostname, backend_info->port, backend_info->db_name );
melunko@412
   288
    uri = gmyth_uri_new_with_value (uri_str);
melunko@412
   289
melunko@412
   290
    g_free (uri_str);
melunko@412
   291
    	
melunko@412
   292
    return uri;	
rosfran@307
   293
}
rosfran@307
   294
rosfran@307
   295