return FALSE;
}
-static void
+static tr_rpc_callback_status
onRPCChanged( tr_handle * handle UNUSED,
tr_rpc_callback_type type,
struct tr_torrent * tor,
data->tor = type == TR_RPC_TORRENT_REMOVING ? NULL : tor;
data->cbdata = cbdata;
g_idle_add( onRPCIdle, data );
+ return TR_RPC_OK;
}
int
****
***/
-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;
}
/***
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;
}
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,