#1156: make the RPC callbacks a little more flexible to make thread issues easier on the mac client

This commit is contained in:
Charles Kerr 2008-08-14 02:12:29 +00:00
parent bbd05758a6
commit f4a5315ec4
3 changed files with 28 additions and 9 deletions

View 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

View File

@ -30,11 +30,15 @@
****
***/
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;

View 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,