[svn r386] Put a mutex on the GMythFileTransfer send/receive transfer methods. Added timeout message to the LiveTV.
1.1 --- a/gmyth/src/gmyth_file_transfer.c Thu Mar 01 17:57:42 2007 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Thu Mar 01 20:03:52 2007 +0000
1.3 @@ -109,9 +109,9 @@
1.4
1.5 void gmyth_file_transfer_close( GMythFileTransfer *transfer );
1.6
1.7 -static gboolean myth_control_acquire_context( gboolean do_wait );
1.8 +static gboolean myth_control_acquire_context( GMythFileTransfer *transfer, gboolean do_wait );
1.9
1.10 -static gboolean myth_control_release_context( );
1.11 +static gboolean myth_control_release_context( GMythFileTransfer *transfer );
1.12
1.13 G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, G_TYPE_OBJECT)
1.14
1.15 @@ -290,6 +290,8 @@
1.16 gboolean ret = TRUE;
1.17
1.18 g_return_val_if_fail (transfer != NULL, FALSE );
1.19 +
1.20 + myth_control_acquire_context( transfer, TRUE );
1.21
1.22 base_str = g_string_new ("");
1.23
1.24 @@ -365,6 +367,8 @@
1.25
1.26 cleanup:
1.27
1.28 + myth_control_release_context( transfer );
1.29 +
1.30 if ( strlist != NULL )
1.31 g_object_unref( strlist );
1.32
1.33 @@ -404,6 +408,8 @@
1.34
1.35 g_return_val_if_fail (transfer->control_sock != NULL, FALSE);
1.36 g_return_val_if_fail (transfer->sock != NULL, FALSE);
1.37 +
1.38 + myth_control_acquire_context( transfer, TRUE );
1.39
1.40 strlist = gmyth_string_list_new();
1.41 query = g_string_new (GMYTHTV_QUERY_HEADER);
1.42 @@ -414,6 +420,8 @@
1.43
1.44 gmyth_socket_write_stringlist( transfer->control_sock, strlist );
1.45 gmyth_socket_read_stringlist( transfer->control_sock, strlist );
1.46 +
1.47 + myth_control_release_context( transfer );
1.48
1.49 g_string_free (query, TRUE);
1.50 g_object_unref (strlist);
1.51 @@ -428,6 +436,8 @@
1.52 GString *query;
1.53
1.54 g_return_if_fail (transfer->control_sock != NULL);
1.55 +
1.56 + myth_control_acquire_context( transfer, TRUE );
1.57
1.58 strlist = gmyth_string_list_new( );
1.59 query = g_string_new (GMYTHTV_QUERY_HEADER);
1.60 @@ -438,7 +448,7 @@
1.61
1.62 if ( gmyth_socket_sendreceive_stringlist(transfer->control_sock, strlist) <= 0 ) {
1.63 // fixme: time out???
1.64 - g_printerr( "Remote file timeout.\n" );
1.65 + gmyth_debug ( "Remote file timeout.\n" );
1.66 }
1.67
1.68 g_string_free (query, TRUE);
1.69 @@ -453,7 +463,9 @@
1.70 g_object_unref( transfer->control_sock );
1.71 transfer->control_sock = NULL;
1.72 }
1.73 -
1.74 +
1.75 + myth_control_release_context( transfer );
1.76 +
1.77 }
1.78
1.79 gint64
1.80 @@ -469,7 +481,7 @@
1.81 query = g_string_new (GMYTHTV_QUERY_HEADER);
1.82 g_string_append_printf (query, "%d", transfer->file_id);
1.83
1.84 - myth_control_acquire_context( TRUE );
1.85 + myth_control_acquire_context( transfer, TRUE );
1.86
1.87 gmyth_string_list_append_string( strlist, query );
1.88 gmyth_string_list_append_char_array( strlist, "SEEK" );
1.89 @@ -489,18 +501,18 @@
1.90 gmyth_debug ( "[%s] got reading position pointer from the streaming = %lld\n",
1.91 __FUNCTION__, retval );
1.92
1.93 - myth_control_release_context( );
1.94 + myth_control_release_context( transfer );
1.95
1.96 return retval;
1.97 }
1.98
1.99 static gboolean
1.100 -myth_control_acquire_context( gboolean do_wait )
1.101 +myth_control_acquire_context( GMythFileTransfer *transfer, gboolean do_wait )
1.102 {
1.103 gboolean ret = TRUE;
1.104 //guint max_iter = 50;
1.105
1.106 - //g_mutex_lock( mutex );
1.107 + g_mutex_lock( transfer->mutex );
1.108
1.109 //while ( !has_io_access )
1.110 // g_cond_wait( io_watcher_cond, mutex );
1.111 @@ -523,7 +535,7 @@
1.112 }
1.113
1.114 static gboolean
1.115 -myth_control_release_context( )
1.116 +myth_control_release_context( GMythFileTransfer *transfer )
1.117 {
1.118 gboolean ret = TRUE;
1.119
1.120 @@ -537,7 +549,7 @@
1.121
1.122 //g_cond_broadcast( io_watcher_cond );
1.123
1.124 - //g_mutex_unlock( mutex );
1.125 + g_mutex_unlock( transfer->mutex );
1.126
1.127 return ret;
1.128 }
1.129 @@ -591,7 +603,7 @@
1.130 /* send requests to the maximum number of REQUEST_BLOCK messages */
1.131 guint max_tries = 5;
1.132
1.133 - myth_control_acquire_context( TRUE );
1.134 + myth_control_acquire_context( transfer, TRUE );
1.135
1.136 while (total_read == 0 && --max_tries > 0) {
1.137 GMythStringList *strlist = gmyth_string_list_new();
1.138 @@ -676,7 +688,7 @@
1.139
1.140 } /* if */
1.141
1.142 - myth_control_release_context( );
1.143 + myth_control_release_context( transfer );
1.144 g_string_free (query, TRUE);
1.145
1.146 if ( error != NULL ) {
1.147 @@ -710,7 +722,6 @@
1.148 transfer->priv->livetv = livetv;
1.149 transfer->priv->do_next_program_chain = TRUE;
1.150
1.151 - //g_object_unref( transfer );
1.152 }
1.153
1.154 gboolean
1.155 @@ -721,19 +732,26 @@
1.156
1.157 g_return_val_if_fail (transfer->sock != NULL, FALSE);
1.158 g_return_val_if_fail (transfer->control_sock != NULL, FALSE);
1.159 -
1.160 -// if ( transfer->timeoutisfast == fast )
1.161 -// return;
1.162 +
1.163 + myth_control_acquire_context( transfer, TRUE );
1.164
1.165 strlist = gmyth_string_list_new();
1.166 gmyth_string_list_append_char_array( strlist, GMYTHTV_QUERY_HEADER );
1.167 gmyth_string_list_append_char_array( strlist, "SET_TIMEOUT" );
1.168 gmyth_string_list_append_int( strlist, fast );
1.169
1.170 - gmyth_socket_write_stringlist( transfer->control_sock, strlist );
1.171 - gmyth_socket_read_stringlist( transfer->control_sock, strlist );
1.172 + gint strlist_len = gmyth_socket_sendreceive_stringlist( transfer->control_sock,
1.173 + strlist );
1.174 +
1.175 + if ( strlist_len > 0 )
1.176 + gmyth_debug( "Yes, timeout was changed: %s.", gmyth_string_list_get_char_array( strlist, 0 ) );
1.177 + else
1.178 + gmyth_debug( "Timeout cannot be changed!" );
1.179 +
1.180 + myth_control_release_context( transfer );
1.181
1.182 -// transfer->timeoutisfast = fast;
1.183 + gmyth_debug ( "%s setting timeout flag of this file transfer = %s\n",
1.184 + strlist_len > 0 ? "Yes," : "NOT", fast ? "FAST" : "NOT FAST" );
1.185
1.186 return TRUE;
1.187 }
2.1 --- a/gmyth/src/gmyth_livetv.c Thu Mar 01 17:57:42 2007 +0000
2.2 +++ b/gmyth/src/gmyth_livetv.c Thu Mar 01 20:03:52 2007 +0000
2.3 @@ -399,7 +399,7 @@
2.4
2.5 while (wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
2.6 (gmyth_recorder_is_recording (livetv->recorder) == FALSE))
2.7 - g_usleep (50);
2.8 + g_usleep (800);
2.9
2.10 if ( channel != NULL )
2.11 {
2.12 @@ -421,7 +421,7 @@
2.13
2.14 } /* if - changes the channel number */
2.15
2.16 - sleep (8); /* FIXME: this is evil (tpm) */
2.17 + sleep (2); /* FIXME: this is evil (tpm) */
2.18 }
2.19
2.20 /* DEBUG message */