#3686 "add rpc command to cleanly shutdown daemon" -- added for libT, tr-daemon, tr-gtk, tr-remote, and the rpc spec

This commit is contained in:
Jordan Lee 2011-01-15 18:12:45 +00:00
parent 8cd66ba851
commit a433b0c4cc
7 changed files with 60 additions and 4 deletions

View File

@ -329,6 +329,17 @@ pumpLogMessages( FILE * logfile )
tr_freeMessageList( list );
}
static tr_rpc_callback_status
on_rpc_callback( tr_session * session UNUSED,
tr_rpc_callback_type type,
struct tr_torrent * tor UNUSED,
void * user_data UNUSED )
{
if( type == TR_RPC_SESSION_CLOSE )
closing = TRUE;
return TR_RPC_OK;
}
int
main( int argc, char ** argv )
{
@ -483,6 +494,7 @@ main( int argc, char ** argv )
tr_formatter_size_init( DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR );
tr_formatter_speed_init( SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR );
mySession = tr_sessionInit( "daemon", configDir, TRUE, &settings );
tr_sessionSetRPCCallback( mySession, on_rpc_callback, NULL );
tr_ninf( NULL, "Using settings from \"%s\"", configDir );
tr_sessionSaveSettings( mySession, configDir, &settings );

View File

@ -241,7 +241,7 @@ static tr_option opts[] =
{ 'e', "cache", "Set the maximum size of the session's memory cache (in " MEM_M_STR ")", "e", 1, "<size>" },
{ 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL },
{ 850, "exit", "Tell the transmission session to shut down", NULL, 0, NULL },
{ 940, "files", "List the current torrent(s)' files", "f", 0, NULL },
{ 'g', "get", "Mark files for download", "g", 1, "<files>" },
{ 'G', "no-get", "Mark files for not downloading", "G", 1, "<files>" },
@ -341,8 +341,9 @@ enum
MODE_SESSION_SET = (1<<9),
MODE_SESSION_GET = (1<<10),
MODE_SESSION_STATS = (1<<11),
MODE_BLOCKLIST_UPDATE = (1<<12),
MODE_PORT_TEST = (1<<13)
MODE_SESSION_CLOSE = (1<<12),
MODE_BLOCKLIST_UPDATE = (1<<13),
MODE_PORT_TEST = (1<<14)
};
static int
@ -445,6 +446,9 @@ getOptMode( int val )
case 'w': /* download-dir */
return MODE_SESSION_SET | MODE_TORRENT_ADD;
case 850: /* session-close */
return MODE_SESSION_CLOSE;
case 963: /* blocklist-update */
return MODE_BLOCKLIST_UPDATE;
@ -2181,6 +2185,14 @@ processArgs( const char * rpcurl, int argc, const char ** argv )
tr_free( path );
break;
}
case 850:
{
tr_benc * top = tr_new0( tr_benc, 1 );
tr_bencInitDict( top, 1 );
tr_bencDictAddStr( top, "method", "session-close" );
status |= flush( rpcurl, &top );
break;
}
case 963:
{
tr_benc * top = tr_new0( tr_benc, 1 );

View File

@ -23,6 +23,7 @@ and
.Op Fl d Ar number | Fl D
.Op Fl e Ar size
.Op Fl er | ep | et
.Op Fl -exit
.Op Fl f
.Op Fl g Ar files
.Op Fl G Ar files
@ -134,6 +135,8 @@ Encrypt all peer connections.
Prefer encrypted peer connections.
.It Fl et Fl -encryption-tolerated
Prefer unencrypted peer connections.
.It Fl -exit
Tell the Transmission to initiate a shutdown.
.It Fl f Fl -files
Get a file list for the current torrent(s)
.It Fl g Fl -get Ar all | file-index | files

View File

@ -526,6 +526,14 @@
Request arguments: none
Response arguments: a bool, "port-is-open"
4.5. Session shutdown
This method tells the transmission session to shut down.
Method-name: "session-close"
Request arguments: none
Response arguments: none
5.0. Protocol Versions
The following changes have been made to the RPC interface:
@ -645,3 +653,4 @@
| | yes | session-set | new arg "blocklist-url"
------+---------+-----------+----------------+-------------------------------
12 | 2.20 | yes | session-get | new arg "download-dir-free-space"
| | yes | session-close | new method

View File

@ -481,6 +481,10 @@ onRPCChanged( tr_session * session,
switch( type )
{
case TR_RPC_SESSION_CLOSE:
gtr_action_activate( "quit" );
break;
case TR_RPC_TORRENT_ADDED:
tr_core_add_torrent( cbdata->core, tr_torrent_new_preexisting( tor ), TRUE );
break;

View File

@ -1624,6 +1624,20 @@ sessionGet( tr_session * s,
****
***/
static const char*
sessionClose( tr_session * session,
tr_benc * args_in UNUSED,
tr_benc * args_out UNUSED,
struct tr_rpc_idle_data * idle_data UNUSED )
{
notify( session, TR_RPC_SESSION_CLOSE, NULL );
return NULL;
}
/***
****
***/
typedef const char* ( *handler )( tr_session*, tr_benc*, tr_benc*, struct tr_rpc_idle_data * );
static struct method
@ -1636,6 +1650,7 @@ methods[] =
{
{ "port-test", FALSE, portTest },
{ "blocklist-update", FALSE, blocklistUpdate },
{ "session-close", TRUE, sessionClose },
{ "session-get", TRUE, sessionGet },
{ "session-set", TRUE, sessionSet },
{ "session-stats", TRUE, sessionStats },

View File

@ -498,7 +498,8 @@ typedef enum
TR_RPC_TORRENT_REMOVING,
TR_RPC_TORRENT_CHANGED, /* catch-all for the "torrent-set" rpc method */
TR_RPC_TORRENT_MOVED,
TR_RPC_SESSION_CHANGED
TR_RPC_SESSION_CHANGED,
TR_RPC_SESSION_CLOSE
}
tr_rpc_callback_type;