# HG changeset patch # User renatofilho # Date 1165269641 0 # Node ID 653d06bca8262b3d3aff8afff43e0a8eda2f269c # Parent 08b70ec67aa45e0cc16353646cd4155adb84eb81 [svn r188] bug fix diff -r 08b70ec67aa4 -r 653d06bca826 gmyth/src/Makefile.am --- a/gmyth/src/Makefile.am Mon Dec 04 20:43:16 2006 +0000 +++ b/gmyth/src/Makefile.am Mon Dec 04 22:00:41 2006 +0000 @@ -41,6 +41,7 @@ $(pkgincludedir) libgmyth_include_HEADERS = \ + gmyth.h \ gmyth_common.h \ gmyth_debug.h \ gmyth_epg.h \ diff -r 08b70ec67aa4 -r 653d06bca826 gmyth/src/gmyth.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/src/gmyth.h Mon Dec 04 22:00:41 2006 +0000 @@ -0,0 +1,49 @@ +/** + * GMyth Library + * + * @file gmyth/gmyth.h + * + * + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia. + * @author Renato Filho + * + *//* + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + + +#ifndef _GMYTH_H_ +#define _GMYTH_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* _GMYTH_H_ */ diff -r 08b70ec67aa4 -r 653d06bca826 gmyth/src/gmyth_backendinfo.c --- a/gmyth/src/gmyth_backendinfo.c Mon Dec 04 20:43:16 2006 +0000 +++ b/gmyth/src/gmyth_backendinfo.c Mon Dec 04 22:00:41 2006 +0000 @@ -55,7 +55,6 @@ backend_info->password = NULL; backend_info->db_name = NULL; backend_info->port = -1; - backend_info->path = NULL; } static void @@ -67,14 +66,12 @@ g_free (backend_info->username); g_free (backend_info->password); g_free (backend_info->db_name); - g_free (backend_info->path); backend_info->hostname = NULL; backend_info->username = NULL; backend_info->password = NULL; backend_info->db_name = NULL; backend_info->port = -1; - backend_info->path = NULL; G_OBJECT_CLASS (gmyth_backend_info_parent_class)->dispose (object); } @@ -122,24 +119,21 @@ GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL)); - gmyth_debug ("XXX %s %d\n", __FUNCTION__, __LINE__); + gmyth_debug ("XXX %s %d\n", __FUNCTION__, __LINE__); GMythURI* uri = gmyth_uri_new_with_value( uri_str ); - gmyth_debug ("XXX %s %d\n", __FUNCTION__, __LINE__); + gmyth_debug ("XXX %s %d\n", __FUNCTION__, __LINE__); gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri ) ); - gmyth_debug ("%s\n", gmyth_uri_get_host (uri )); + gmyth_debug ("%s\n", gmyth_uri_get_host (uri )); gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( uri ) ); - gmyth_debug ("%s\n", gmyth_uri_get_user( uri )); + gmyth_debug ("%s\n", gmyth_uri_get_user( uri )); gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password( uri ) ); - gmyth_debug ("%s\n", gmyth_uri_get_password( uri )); + gmyth_debug ("%s\n", gmyth_uri_get_password( uri )); gmyth_backend_info_set_db_name (backend_info, strlen( gmyth_uri_get_fragment( uri ) ) > 0 ? gmyth_uri_get_fragment( uri ) : gmyth_uri_get_query( uri ) ); gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port( uri ) ); - gmyth_debug ("%s\n", gmyth_backend_info_get_db_name(backend_info) ); + gmyth_debug ("%s\n", gmyth_backend_info_get_db_name(backend_info) ); - gmyth_backend_info_set_path (backend_info, gmyth_uri_get_path( uri ) ); - gmyth_debug ("%s\n", gmyth_backend_info_get_path(backend_info) ); - return backend_info; } @@ -183,14 +177,6 @@ backend_info->port = port; } -void -gmyth_backend_info_set_path (GMythBackendInfo *backend_info, const gchar *path) -{ - g_return_if_fail (backend_info != NULL); - - backend_info->path = g_strdup (path); -} - gchar* gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info) { @@ -231,10 +217,3 @@ return backend_info->port; } -gchar* -gmyth_backend_info_get_path (GMythBackendInfo *backend_info) -{ - g_return_val_if_fail (backend_info != NULL, NULL); - - return backend_info->path; -} diff -r 08b70ec67aa4 -r 653d06bca826 gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Mon Dec 04 20:43:16 2006 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Mon Dec 04 22:00:41 2006 +0000 @@ -146,12 +146,43 @@ static void gmyth_file_transfer_dispose (GObject *object) { + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (object); + + g_free (transfer->filename); + transfer->filename = NULL; + + if (transfer->backend_info != NULL) { + g_object_unref (transfer->backend_info); + transfer->backend_info = NULL; + } + + if (transfer->control_sock != NULL) { + g_object_unref (transfer->control_sock); + transfer->control_sock = NULL; + } + + if (transfer->event_sock != NULL) { + g_object_unref (transfer->event_sock); + transfer->event_sock = NULL; + } + + if (transfer->sock != NULL) { + g_object_unref (transfer->sock); + transfer->sock = NULL; + } + + if (transfer->monitor != NULL) { + g_object_unref (transfer->monitor); + transfer->monitor = NULL; + } + G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->dispose (object); } static void gmyth_file_transfer_finalize (GObject *object) { + g_signal_handlers_destroy (object); G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->finalize (object); @@ -164,51 +195,40 @@ GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); transfer->backend_info = (GMythBackendInfo *)backend_info; + g_object_ref (transfer->backend_info); return transfer; } GMythFileTransfer* -gmyth_file_transfer_new_with_uri ( const gchar* uri_str ) +gmyth_file_transfer_new_with_uri (const gchar* uri_str) { GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); - - transfer->uri = gmyth_uri_new_with_value (uri_str); - transfer->hostname = g_string_new( gmyth_uri_get_host(transfer->uri) ); - transfer->port = gmyth_uri_get_port( transfer->uri ); + GMythURI *uri = gmyth_uri_new_with_value (uri_str); + transfer->backend_info = gmyth_backend_info_new_full (gmyth_uri_get_host(uri), + NULL, NULL, NULL, gmyth_uri_get_port (uri)); + + g_object_unref (uri); return transfer; } gboolean -gmyth_file_transfer_open ( GMythFileTransfer *transfer, const gchar* filename ) +gmyth_file_transfer_open (GMythFileTransfer *transfer, const gchar* filename) { gboolean ret = TRUE; g_return_val_if_fail( transfer != NULL, FALSE ); - if ( filename != NULL ) + if (filename != NULL) { - transfer->filename = filename; - gmyth_backend_info_set_path ( transfer->backend_info, filename ); + transfer->filename = g_strdup (filename); } - if ( transfer->backend_info != NULL ) - { - //transfer->uri = gmyth_backend_info_full_uri( ) - transfer->hostname = g_string_new ( gmyth_backend_info_get_hostname(transfer->backend_info) ); - transfer->port = gmyth_backend_info_get_port (transfer->backend_info); - } - - if ( transfer->uri ) - gmyth_debug ("[%s] URI: %s\n", __FUNCTION__, transfer->uri->uri->str); - - gmyth_debug ("hostname: %s, port %d\n", transfer->hostname->str, transfer->port); - /* configure the control socket */ if (transfer->control_sock == NULL) { if (!gmyth_connect_to_backend (transfer)) { - gmyth_debug( "Connection to backend failed (Control Socket).\n" ); + gmyth_debug ("Connection to backend failed (Control Socket).\n"); ret = FALSE; } } else { @@ -246,7 +266,7 @@ // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version if (!gmyth_socket_connect_to_backend (transfer->control_sock, - transfer->hostname->str, transfer->port, TRUE)) { + transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) { g_object_unref (transfer->control_sock); transfer->control_sock = NULL; @@ -260,7 +280,7 @@ } transfer->sock = gmyth_socket_new (); - gmyth_socket_connect (transfer->sock, transfer->hostname->str, transfer->port); + gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port); strlist = gmyth_string_list_new(); hostname = gmyth_socket_get_local_hostname(); @@ -295,7 +315,7 @@ transfer->monitor = gmyth_monitor_handler_new ( ); - ret = gmyth_monitor_handler_open ( transfer->monitor, transfer->hostname->str, transfer->port ); + ret = gmyth_monitor_handler_open (transfer->monitor, transfer->backend_info->hostname, transfer->backend_info->port ); if ( ret == TRUE ) { diff -r 08b70ec67aa4 -r 653d06bca826 gmyth/src/gmyth_file_transfer.h --- a/gmyth/src/gmyth_file_transfer.h Mon Dec 04 20:43:16 2006 +0000 +++ b/gmyth/src/gmyth_file_transfer.h Mon Dec 04 22:00:41 2006 +0000 @@ -73,9 +73,6 @@ GObject parent; /* Myth URI structure */ - GMythURI *uri; - GString* hostname; - gint port; gchar* filename; GMythBackendInfo *backend_info; @@ -91,31 +88,24 @@ gint64 readposition; guint64 filesize; - gint file_id; }; -GType gmyth_file_transfer_get_type (void); - -GMythFileTransfer* gmyth_file_transfer_new ( const GMythBackendInfo *backend_info ); - -GMythFileTransfer* gmyth_file_transfer_new_with_uri ( const gchar* uri_str ); - -gboolean gmyth_file_transfer_open ( GMythFileTransfer *transfer, - const gchar* filename ); - -void gmyth_file_transfer_close (GMythFileTransfer *transfer); - -gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer); - -gint gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, - gint size, gboolean read_unlimited); - -gint64 gmyth_file_transfer_seek(GMythFileTransfer *transfer, guint64 pos, gint whence); - -gboolean gmyth_file_transfer_settimeout( GMythFileTransfer *transfer, gboolean fast); - -guint64 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer); +GType gmyth_file_transfer_get_type (void); +GMythFileTransfer *gmyth_file_transfer_new (const GMythBackendInfo *backend_info); +gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer, + const gchar* filename); +void gmyth_file_transfer_close (GMythFileTransfer *transfer); +gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer); +gint gmyth_file_transfer_read (GMythFileTransfer *transfer, + GByteArray *data, + gint size, + gboolean read_unlimited); +gint64 gmyth_file_transfer_seek (GMythFileTransfer *transfer, + guint64 pos, + gint whence); +gboolean gmyth_file_transfer_settimeout (GMythFileTransfer *transfer, gboolean fast); +guint64 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer); #define G_END_DECLS diff -r 08b70ec67aa4 -r 653d06bca826 gmyth/src/gmyth_monitor_handler.c --- a/gmyth/src/gmyth_monitor_handler.c Mon Dec 04 20:43:16 2006 +0000 +++ b/gmyth/src/gmyth_monitor_handler.c Mon Dec 04 22:00:41 2006 +0000 @@ -79,8 +79,6 @@ GMYTH_RINGBUFFER_TYPE }; -static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT; - static gboolean* myth_control_sock_listener( GIOChannel *io_channel ); //static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, // gpointer data ); @@ -89,8 +87,6 @@ static GCond* io_watcher_cond = NULL; -static GMainContext* io_watcher_context = NULL; - static void gmyth_monitor_handler_class_init (GMythMonitorHandlerClass *klass); static void gmyth_monitor_handler_init (GMythMonitorHandler *object); @@ -101,10 +97,6 @@ void gmyth_monitor_handler_close( GMythMonitorHandler *monitor ); -static gboolean myth_control_acquire_context( gboolean do_wait ); - -static gboolean myth_control_release_context( ); - G_DEFINE_TYPE(GMythMonitorHandler, gmyth_monitor_handler, G_TYPE_OBJECT) static void @@ -316,49 +308,13 @@ gboolean gmyth_monitor_handler_start (GMythMonitorHandler *monitor) { - gboolean ret = TRUE; - - if (!g_thread_supported ()) g_thread_init (NULL); - - monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_listener, + monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_listener, monitor->event_sock->sd_io_ch, TRUE, NULL ); -/* - io_watcher_context = g_main_context_default(); - //GMainLoop *loop = g_main_loop_new( NULL, TRUE ); - - GSource *source; - - if ( monitor->event_sock->sd_io_ch != NULL ) { - source = g_io_create_watch( monitor->event_sock->sd_io_ch, G_IO_IN ); - //monitor->event_sock->sd_io_ch - } else { - ret = FALSE; - goto cleanup; - } - - g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL ); - - g_source_attach( source, io_watcher_context ); - - if (source==NULL) { - gmyth_debug( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ ); - goto cleanup; - } - */ - - gmyth_debug ( "[%s]\tOK! Starting listener on the MONITOR event socket...\n", __FUNCTION__ ); - - //g_main_loop_run( loop ); - -cleanup: - //if ( source != NULL ) - // g_source_unref( source ); + gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n", + __FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) ); - gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n", - __FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) ); - - return ret; + return TRUE; } void @@ -377,55 +333,3 @@ } -static gboolean -myth_control_acquire_context( gboolean do_wait ) -{ - - gboolean ret = TRUE; - //guint max_iter = 50; - - //g_mutex_lock( mutex ); - - //while ( !has_io_access ) - // g_cond_wait( io_watcher_cond, mutex ); - - //has_io_access = FALSE; - - //myth_control_acquire_context (FALSE); - - /* - if ( do_wait ) { - while ( --max_iter > 0 && !g_main_context_wait( io_watcher_context, io_watcher_cond, mutex ) ) - ret = FALSE; - } else if ( !g_main_context_acquire( io_watcher_context ) ) - ret = FALSE; - */ - - //g_static_mutex_lock( &st_mutex ); - - return ret; - -} - -static gboolean -myth_control_release_context( ) -{ - - gboolean ret = TRUE; - - //g_static_mutex_unlock( &st_mutex ); - - //g_main_context_release( io_watcher_context ); - - //g_main_context_wakeup( io_watcher_context ); - - //has_io_access = TRUE; - - //g_cond_broadcast( io_watcher_cond ); - - //g_mutex_unlock( mutex ); - - return ret; - -} -