[svn r193] Merged with Coxinhas' fixes.
1.1 --- a/gmyth/src/gmyth_file_transfer.c Mon Dec 04 22:29:39 2006 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Mon Dec 04 23:07:36 2006 +0000
1.3 @@ -84,10 +84,6 @@
1.4
1.5 //static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT;
1.6
1.7 -static GMutex* mutex = NULL;
1.8 -
1.9 -static GCond* io_watcher_cond = NULL;
1.10 -
1.11 static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass);
1.12 static void gmyth_file_transfer_init (GMythFileTransfer *object);
1.13
1.14 @@ -120,60 +116,49 @@
1.15 {
1.16 g_return_if_fail( transfer != NULL );
1.17
1.18 - //transfer->card_id = num;
1.19 - //transfer->rec_id = -1;
1.20 - //transfer->recordernum = num;
1.21 -
1.22 transfer->readposition = 0;
1.23 transfer->filesize = GMYTHTV_FILE_SIZE;
1.24 - //transfer->timeoutisfast = FALSE;
1.25 -
1.26 - //transfer->userreadahead = GMYTHTV_USER_READ_AHEAD;
1.27 - //transfer->retries = GMYTHTV_RETRIES;
1.28
1.29 transfer->control_sock = NULL;
1.30 transfer->sock = NULL;
1.31
1.32 transfer->monitor = NULL;
1.33 -
1.34 - /* it is used for signalizing the event socket consumer thread */
1.35 - io_watcher_cond = g_cond_new();
1.36 -
1.37 - /* mutex to control access to the event socket consumer thread */
1.38 - mutex = g_mutex_new();
1.39 +
1.40 }
1.41
1.42 static void
1.43 gmyth_file_transfer_dispose (GObject *object)
1.44 {
1.45 - GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (object);
1.46 -
1.47 - g_free (transfer->filename);
1.48 - transfer->filename = NULL;
1.49 -
1.50 - if (transfer->backend_info != NULL) {
1.51 - g_object_unref (transfer->backend_info);
1.52 - transfer->backend_info = NULL;
1.53 + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (object);
1.54 +
1.55 + if ( transfer->control_sock != NULL )
1.56 + {
1.57 + g_object_unref( transfer->control_sock );
1.58 + transfer->control_sock = NULL;
1.59 + }
1.60 +
1.61 + if ( transfer->sock != NULL )
1.62 + {
1.63 + g_object_unref( transfer->sock );
1.64 + transfer->sock = NULL;
1.65 }
1.66 -
1.67 - if (transfer->control_sock != NULL) {
1.68 - g_object_unref (transfer->control_sock);
1.69 - transfer->control_sock = NULL;
1.70 +
1.71 + if ( transfer->monitor != NULL )
1.72 + {
1.73 + g_object_unref( transfer->monitor );
1.74 + transfer->monitor = NULL;
1.75 }
1.76 -
1.77 - if (transfer->event_sock != NULL) {
1.78 - g_object_unref (transfer->event_sock);
1.79 - transfer->event_sock = NULL;
1.80 +
1.81 + if ( transfer->event_sock != NULL )
1.82 + {
1.83 + g_object_unref( transfer->event_sock );
1.84 + transfer->event_sock = NULL;
1.85 }
1.86 -
1.87 - if (transfer->sock != NULL) {
1.88 - g_object_unref (transfer->sock);
1.89 - transfer->sock = NULL;
1.90 - }
1.91 -
1.92 - if (transfer->monitor != NULL) {
1.93 - g_object_unref (transfer->monitor);
1.94 - transfer->monitor = NULL;
1.95 +
1.96 + if ( transfer->filename != NULL )
1.97 + {
1.98 + g_free( transfer->filename );
1.99 + transfer->filename = NULL;
1.100 }
1.101
1.102 G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->dispose (object);
1.103 @@ -248,8 +233,6 @@
1.104 gboolean ret = TRUE;
1.105
1.106 g_return_val_if_fail (transfer != NULL, FALSE );
1.107 - g_return_val_if_fail (transfer->hostname != NULL, FALSE);
1.108 - g_return_val_if_fail (transfer->port > 0, FALSE);
1.109
1.110 base_str = g_string_new ("");
1.111
2.1 --- a/gmyth/src/gmyth_monitor_handler.c Mon Dec 04 22:29:39 2006 +0000
2.2 +++ b/gmyth/src/gmyth_monitor_handler.c Mon Dec 04 23:07:36 2006 +0000
2.3 @@ -70,6 +70,8 @@
2.4 #define GMYTHTV_ENABLE_DEBUG 1
2.5 #endif
2.6
2.7 +GMainContext *io_watcher_context = NULL;
2.8 +
2.9 GThread *monitor_th = NULL;
2.10
2.11 enum myth_sock_types {
2.12 @@ -79,9 +81,9 @@
2.13 GMYTH_RINGBUFFER_TYPE
2.14 };
2.15
2.16 -static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
2.17 -//static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition,
2.18 -// gpointer data );
2.19 +//static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
2.20 +static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition,
2.21 + gpointer data );
2.22
2.23 static GMutex* mutex = NULL;
2.24
2.25 @@ -132,6 +134,46 @@
2.26 static void
2.27 gmyth_monitor_handler_dispose (GObject *object)
2.28 {
2.29 +
2.30 + GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER (object);
2.31 +
2.32 + if ( monitor->event_sock != NULL )
2.33 + {
2.34 + g_object_unref( monitor->event_sock );
2.35 + monitor->event_sock = NULL;
2.36 + }
2.37 +
2.38 + if ( monitor->hostname != NULL )
2.39 + {
2.40 + g_free( monitor->hostname );
2.41 + monitor->hostname = NULL;
2.42 + }
2.43 +
2.44 + if ( monitor->backend_msgs != NULL )
2.45 + {
2.46 + g_hash_table_unref( monitor->backend_msgs );
2.47 + monitor->backend_msgs = NULL;
2.48 + }
2.49 +
2.50 + if ( mutex != NULL )
2.51 + {
2.52 + g_mutex_free( mutex );
2.53 + mutex = NULL;
2.54 + }
2.55 +
2.56 + if ( io_watcher_cond != NULL )
2.57 + {
2.58 + g_cond_free( io_watcher_cond );
2.59 + io_watcher_cond = NULL;
2.60 + }
2.61 +
2.62 + if ( monitor_th != NULL )
2.63 + {
2.64 + g_thread_join( monitor_th );
2.65 + g_object_unref( monitor_th );
2.66 + monitor_th = NULL;
2.67 + }
2.68 +
2.69 G_OBJECT_CLASS (gmyth_monitor_handler_parent_class)->dispose (object);
2.70 }
2.71
2.72 @@ -182,39 +224,36 @@
2.73
2.74 }
2.75
2.76 -static gboolean*
2.77 -//myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
2.78 -myth_control_sock_listener( GIOChannel *io_channel )
2.79 +static gboolean
2.80 +myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
2.81 +//myth_control_sock_listener( GIOChannel *io_channel )
2.82 {
2.83
2.84 GIOStatus io_status;
2.85 GError *error = NULL;
2.86 GIOCondition io_cond;
2.87 - GIOCondition condition;
2.88 + //GIOCondition condition;
2.89 gchar *trash = NULL;
2.90 GByteArray *byte_array = NULL;
2.91 guint recv = 0;
2.92 - gboolean* ret = g_new0( gboolean, 1 );
2.93 - //gboolean ret = TRUE;
2.94 + //gboolean* ret = g_new0( gboolean, 1 );
2.95 + gboolean ret = TRUE;
2.96 gsize len = 0;
2.97
2.98 //GMythMonitorHandler *monitor = (GMythMonitorHandler*)data;
2.99
2.100 - *ret = TRUE;
2.101 //myth_control_acquire_context (TRUE);
2.102
2.103 if ( io_channel == NULL ) {
2.104 g_debug ("Monitor socket is NULL!\n");
2.105 - *ret = FALSE;
2.106 + ret = FALSE;
2.107 goto clean_up;
2.108 }
2.109 gmyth_debug ("Listening on Monitor socket...!\n");
2.110
2.111 - while (TRUE) {
2.112 + //while (TRUE) {
2.113
2.114 - condition = g_io_channel_get_buffer_condition( io_channel );
2.115 -
2.116 - //myth_control_acquire_context (TRUE);
2.117 + //condition = g_io_channel_get_buffer_condition( io_channel );
2.118
2.119 //while ( !has_io_access )
2.120 // g_cond_wait( io_watcher_cond, mutex );
2.121 @@ -223,7 +262,7 @@
2.122
2.123 if (condition & G_IO_HUP) {
2.124 gmyth_debug ("Read end of pipe died!\n");
2.125 - *ret = FALSE;
2.126 + ret = FALSE;
2.127 //goto clean_up;
2.128 }
2.129
2.130 @@ -251,7 +290,7 @@
2.131 io_cond = g_io_channel_get_buffer_condition( io_channel );
2.132
2.133 } while ( ( io_cond & G_IO_IN ) != 0 );
2.134 - gmyth_debug ("\n[%s]\tEVENT: Read %d bytes: %s\n\n", __FUNCTION__, recv, byte_array != NULL && byte_array->data != NULL ? (gchar*)byte_array->data : "[no event data]" );
2.135 + gmyth_debug ("\n\n\n[%s]\tEVENT: Read %d bytes: %s\n\n\n", __FUNCTION__, recv, byte_array != NULL && byte_array->data != NULL ? (gchar*)byte_array->data : "[no event data]" );
2.136 }
2.137
2.138 if ( byte_array != NULL ) {
2.139 @@ -261,11 +300,10 @@
2.140
2.141 g_usleep( 300 );
2.142
2.143 - }
2.144 - //ret = g_io_channel_read_chars ( source, &msg, &len, NULL, &err);
2.145 + //}
2.146 if ( io_status == G_IO_STATUS_ERROR ) {
2.147 gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" );
2.148 - *ret = FALSE;
2.149 + ret = FALSE;
2.150 goto clean_up;
2.151 }
2.152
2.153 @@ -305,14 +343,71 @@
2.154 return ret;
2.155 }
2.156
2.157 +static gboolean*
2.158 +myth_control_sock_setup( GIOChannel *channel )
2.159 +{
2.160 + gboolean *ret = g_new0( gboolean, 1 );
2.161 +
2.162 + *ret = TRUE;
2.163 +
2.164 + io_watcher_context = g_main_context_default();
2.165 + //GMainLoop *loop = g_main_loop_new( io_watcher_context, TRUE );
2.166 +
2.167 + GSource *source;
2.168 +
2.169 + if ( channel != NULL ) {
2.170 + source = g_io_create_watch( channel, G_IO_IN | G_IO_HUP );
2.171 + } else {
2.172 + *ret = FALSE;
2.173 + goto cleanup;
2.174 + }
2.175 +
2.176 + g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL );
2.177 +
2.178 + g_source_attach( source, io_watcher_context );
2.179 +
2.180 + if (source==NULL) {
2.181 + gmyth_debug( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
2.182 + *ret = FALSE;
2.183 + goto cleanup;
2.184 + }
2.185 +
2.186 + //g_main_loop_run( loop );
2.187 +
2.188 +cleanup:
2.189 + //if ( source != NULL )
2.190 + // g_source_unref( source );
2.191 +
2.192 + return ret;
2.193 +
2.194 +}
2.195 +
2.196 gboolean
2.197 gmyth_monitor_handler_start (GMythMonitorHandler *monitor)
2.198 {
2.199 - monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_listener,
2.200 + gboolean *ret = g_new0( gboolean, 1 );
2.201 + *ret = TRUE;
2.202 +
2.203 + if (!g_thread_supported ()) g_thread_init (NULL);
2.204 +
2.205 + monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_setup,
2.206 monitor->event_sock->sd_io_ch, TRUE, NULL );
2.207 +
2.208 + if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
2.209 + {
2.210 + gmyth_debug ( "\n[%s]\tERROR! Coudn't start listener on the MONITOR event socket...[thread location = %p]\n",
2.211 + __FUNCTION__, g_thread_self( ) );
2.212 + } else {
2.213 + gmyth_debug ( "\n[%s]\tOK! Starting listener on the MONITOR event socket...[thread location = %p]\n",
2.214 + __FUNCTION__, g_thread_self( ) );
2.215 + }
2.216
2.217 - gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n",
2.218 - __FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) );
2.219 +cleanup:
2.220 + //if ( source != NULL )
2.221 + // g_source_unref( source );
2.222 +
2.223 + gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n",
2.224 + __FUNCTION__, ( *ret == TRUE ? "YES" : "NO" ) );
2.225
2.226 return TRUE;
2.227 }