]> granicus.if.org Git - transmission/commitdiff
#1156: make the RPC callbacks a little more flexible to make thread issues easier...
authorCharles Kerr <charles@transmissionbt.com>
Thu, 14 Aug 2008 02:12:29 +0000 (02:12 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 14 Aug 2008 02:12:29 +0000 (02:12 +0000)
gtk/main.c
libtransmission/rpc.c
libtransmission/transmission.h

index 5dec78b9f3252ba48e2f446c523162a19ebfd0fe..105a9ef271f3c327f4df2e4dda7f735323319f41 100644 (file)
@@ -316,7 +316,7 @@ onRPCIdle( void * vdata )
     return FALSE;
 }
 
-static void
+static tr_rpc_callback_status
 onRPCChanged( tr_handle            * handle UNUSED,
               tr_rpc_callback_type   type,
               struct tr_torrent    * tor,
@@ -331,6 +331,7 @@ onRPCChanged( tr_handle            * handle UNUSED,
     data->tor = type == TR_RPC_TORRENT_REMOVING ? NULL : tor;
     data->cbdata = cbdata;
     g_idle_add( onRPCIdle, data );
+    return TR_RPC_OK;
 }
 
 int
index 39c5e45fca03f1a8ffb88e5ebab03e037a730828..b5357cebfd2f891d39b22c4caafd39c79d4e1730 100644 (file)
 ****
 ***/
 
-static void
+static tr_rpc_callback_status
 notify( tr_handle * session, int type, tr_torrent * tor )
 {
+    tr_rpc_callback_status status = 0;
+
     if( session->rpc_func )
-        session->rpc_func( session, type, tor, session->rpc_func_user_data );
+        status = session->rpc_func( session, type, tor, session->rpc_func_user_data );
+
+    return status;
 }
 
 /***
@@ -129,8 +133,9 @@ torrentRemove( tr_handle * h, tr_benc * args_in, tr_benc * args_out UNUSED )
     for( i=0; i<torrentCount; ++i )
     {
         tr_torrent * tor = torrents[i];
-        notify( h, TR_RPC_TORRENT_REMOVING, tor );
-        tr_torrentRemove( tor );
+        const tr_rpc_callback_status status = notify( h, TR_RPC_TORRENT_REMOVING, tor );
+        if( ! ( status & TR_RPC_NOREMOVE ) )
+            tr_torrentRemove( tor );
     }
     tr_free( torrents );
     return NULL;
index 1ef3cfc5bbddf632acb70ef3d1289d559a8523b6..7a591a2f878b19daed938811485aad0dfd5f0ab2 100644 (file)
@@ -421,10 +421,23 @@ typedef enum
 }
 tr_rpc_callback_type;
 
-typedef void ( *tr_rpc_func )( tr_session           * handle,
-                               tr_rpc_callback_type   type,
-                               struct tr_torrent    * tor_or_null,
-                               void                 * user_data );
+typedef enum
+{
+    /* no special handling is needed by the caller */
+    TR_RPC_OK            = 0,
+
+    /* indicates to the caller that the client will take care of
+     * removing the torrent itself.  For example the client may
+     * need to keep the torrent alive long enough to cleanly close
+     * some resources in another thread. */
+    TR_RPC_NOREMOVE   = (1<<1)
+}
+tr_rpc_callback_status;
+
+typedef tr_rpc_callback_status ( *tr_rpc_func )( tr_session           * handle,
+                                                 tr_rpc_callback_type   type,
+                                                 struct tr_torrent    * tor_or_null,
+                                                 void                 * user_data );
 
 void tr_sessionSetRPCCallback( tr_session   * handle,
                                tr_rpc_func    func,