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