Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

gtask-connection-group.c

Go to the documentation of this file.
00001 #include <gtask/gtask-connection-group.h>
00002 
00003 #include <string.h>
00004 
00007 /* @{ */
00008 
00009 static gpointer parent_class = NULL;
00010 
00011 static void
00012 gtask_connection_group_class_init( GTaskConnectionGroupClass *klass );
00013 
00014 static void
00015 gtask_connection_group_init( GTaskConnectionGroup *group, gpointer g_class );
00016 
00017 static void
00018 gtask_connection_group_dispose( GObject *obj );
00019 
00020 static void
00021 gtask_connection_group_finalize( GObject *obj );
00022 
00032 GType gtask_connection_group_get_type( void ) {
00033     static GType type = 0;
00034 
00035     if( type == 0 ) {
00036         static const GTypeInfo info = {
00037             sizeof( GTaskConnectionGroupClass ),
00038             NULL,   /* base init */
00039             NULL,   /* base_finalize */
00040             (GClassInitFunc) gtask_connection_group_class_init, /* class_init */
00041             NULL,   /* class_finalize */
00042             NULL,   /* class_data */
00043             sizeof( GTaskConnectionGroup ),
00044             0,      /* n_preallocs */
00045             (GInstanceInitFunc) gtask_connection_group_init
00046         };
00047 
00048         type = g_type_register_static( G_TYPE_OBJECT,
00049                                        "GTaskConnectionGroup",
00050                                        &info,
00051                                        0 );
00052     }
00053 
00054     return type;
00055 }
00056 
00057 static void
00058 gtask_connection_group_class_init( GTaskConnectionGroupClass *klass ) {
00059     GObjectClass *gobject_class = G_OBJECT_CLASS( klass );
00060 
00061     parent_class = g_type_class_peek_parent( klass );
00062 
00063     gobject_class->dispose = gtask_connection_group_dispose;
00064     gobject_class->finalize = gtask_connection_group_finalize;
00065 }
00066 
00072 static void
00073 gtask_connection_group_init( GTaskConnectionGroup *group, gpointer g_class ) {
00074     GTaskConnectionGroupPrivate *private;
00075 
00076     private = g_new0( GTaskConnectionGroupPrivate, 1 );
00077 
00078     private->connection_list = NULL;
00079     private->dispose_has_run = FALSE;
00080 
00081     group->private = private;
00082 }
00083 
00084 static void
00085 gtask_connection_group_dispose( GObject *obj ) {
00086     GTaskConnectionGroup *group = GTASK_CONNECTION_GROUP( obj );
00087 
00088     if( group->private->dispose_has_run )
00089         return;
00090 
00091     g_slist_foreach( group->private->connection_list,
00092                      (GFunc) g_object_unref,
00093                      NULL );
00094 
00095     group->private->dispose_has_run = TRUE;
00096 
00097     if( G_OBJECT_CLASS( parent_class )->dispose )
00098         G_OBJECT_CLASS( parent_class )->dispose( obj );
00099 }
00100 
00101 static void
00102 gtask_connection_group_finalize( GObject *obj ) {
00103     GTaskConnectionGroup *group = GTASK_CONNECTION_GROUP( obj );
00104 
00105     g_slist_free( group->private->connection_list );
00106 
00107     g_free( group->private );
00108 
00109     if( G_OBJECT_CLASS( parent_class )->finalize )
00110         G_OBJECT_CLASS( parent_class )->finalize( obj );
00111 }
00112 
00120 GTaskConnectionGroup *
00121 gtask_connection_group_new( void ) {
00122     return g_object_new( GTASK_CONNECTION_GROUP_TYPE, NULL );
00123 }
00124 
00139 void
00140 gtask_connection_group_add_connection( GTaskConnectionGroup *group,
00141                                        GTaskConnection *conn )
00142 {
00143     GTaskConnectionGroupPrivate *private;
00144 
00145     g_return_if_fail( GTASK_IS_CONNECTION_GROUP( group ) );
00146     g_return_if_fail( GTASK_IS_CONNECTION( conn ) );
00147     g_return_if_fail( !group->private->dispose_has_run );
00148 
00149     g_object_ref( conn );
00150 
00151     private = group->private;
00152 
00153     private->connection_list = g_slist_append( private->connection_list, conn );
00154 }
00155 
00163 void
00164 gtask_connection_group_clear( GTaskConnectionGroup *group ) {
00165     GTaskConnectionGroupPrivate *private;
00166 
00167     g_return_if_fail( GTASK_IS_CONNECTION_GROUP( group ) );
00168     g_return_if_fail( !group->private->dispose_has_run );
00169 
00170     private = group->private;
00171 
00172     g_slist_foreach( private->connection_list,
00173                      (GFunc) g_object_unref,
00174                      NULL );
00175 
00176     g_slist_free( private->connection_list );
00177 
00178     private->connection_list = NULL;
00179 }
00180 
00191 GSList *
00192 gtask_connection_group_get_list( GTaskConnectionGroup *group ) {
00193     g_return_val_if_fail( GTASK_IS_CONNECTION_GROUP( group ), NULL );
00194     g_return_val_if_fail( !group->private->dispose_has_run, NULL );
00195 
00196     return group->private->connection_list;
00197 }
00198 
00208 GTaskConnection *
00209 gtask_connection_group_get_connection_by_name( GTaskConnectionGroup *group,
00210                                                const gchar *conn_name )
00211 {
00212     GSList          *list;
00213     GTaskConnection *conn = NULL;
00214 
00215     g_return_val_if_fail( GTASK_IS_CONNECTION_GROUP( group ), NULL );
00216     g_return_val_if_fail( conn_name != NULL, NULL );
00217     g_return_val_if_fail( !group->private->dispose_has_run, NULL );
00218 
00219     list = group->private->connection_list;
00220 
00221     while( list ) {
00222         GTaskConnection *t_conn = (GTaskConnection *) list->data;
00223         const gchar     *name = gtask_connection_get_name( t_conn );
00224 
00225         if( strcmp( name, conn_name ) == 0 ) {
00226             conn = t_conn;
00227             break;
00228         }
00229 
00230         list = g_slist_next( list );
00231     }
00232 
00233     return conn;
00234 }
00235 
00236 /* @} */

Generated on Mon Feb 2 21:26:14 2004 for libgtask by doxygen 1.3.4