From 094f76d9ca9e49e295aaa480678dcae1fd209d0d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Feb 2010 07:48:03 +0000 Subject: [PATCH] (trunk libT) #2846 "Priority Selection in `Add' Window" -- added RPC hooks for doing this via remote client --- doc/rpc-spec.txt | 27 ++++++++++++++------------- libtransmission/rpcimpl.c | 3 +++ libtransmission/torrent-ctor.c | 27 +++++++++++++++++++++++++++ libtransmission/torrent.c | 2 ++ libtransmission/transmission.h | 12 ++++++++++++ 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index 4d29dccd9..5ec649ef4 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -330,18 +330,19 @@ Request arguments: - key | value type & description - -------------------+------------------------------------------------- - "download-dir" | string path to download the torrent to - "filename" | string filename or URL of the .torrent file - "metainfo" | string base64-encoded .torrent content - "paused" | boolean if true, don't start the torrent - "peer-limit" | number maximum number of peers - "files-wanted" | array indices of file(s) to download - "files-unwanted" | array indices of file(s) to not download - "priority-high" | array indices of high-priority file(s) - "priority-low" | array indices of low-priority file(s) - "priority-normal" | array indices of normal-priority file(s) + key | value type & description + ---------------------+------------------------------------------------- + "download-dir" | string path to download the torrent to + "filename" | string filename or URL of the .torrent file + "metainfo" | string base64-encoded .torrent content + "paused" | boolean if true, don't start the torrent + "peer-limit" | number maximum number of peers + "bandwidthPriority" | number torrent's bandwidth tr_priority_t + "files-wanted" | array indices of file(s) to download + "files-unwanted" | array indices of file(s) to not download + "priority-high" | array indices of high-priority file(s) + "priority-low" | array indices of low-priority file(s) + "priority-normal" | array indices of normal-priority file(s) Either "filename" OR "metainfo" MUST be included. All other arguments are optional. @@ -576,4 +577,4 @@ ------+---------+-----------+----------------+------------------------------- 8 | 1.90 | yes | session-set | new arg "rename-partial-files" | | yes | session-get | new arg "rename-partial-files" - + | | yes | torrent-add | new arg "bandwidthPriority" diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 7ea9febb9..d5bfd3e0a 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -1061,6 +1061,9 @@ torrentAdd( tr_session * session, if( tr_bencDictFindInt( args_in, "peer-limit", &i ) ) tr_ctorSetPeerLimit( ctor, TR_FORCE, i ); + if( tr_bencDictFindInt( args_in, "bandwidthPriority", &i ) ) + tr_ctorSetBandwidthPriority( ctor, i ); + if( tr_bencDictFindList( args_in, "files-unwanted", &l ) ) { tr_file_index_t fileCount; tr_file_index_t * files = fileListFromList( l, &fileCount ); diff --git a/libtransmission/torrent-ctor.c b/libtransmission/torrent-ctor.c index 5db30e223..ce160cc9f 100644 --- a/libtransmission/torrent-ctor.c +++ b/libtransmission/torrent-ctor.c @@ -38,6 +38,7 @@ struct tr_ctor tr_bool saveInOurTorrentsDir; tr_bool doDelete; + tr_priority_t bandwidthPriority; tr_bool isSet_metainfo; tr_bool isSet_delete; tr_benc metainfo; @@ -425,12 +426,38 @@ tr_ctorGetSession( const tr_ctor * ctor ) **** ***/ +static tr_bool +isPriority( int i ) +{ + return (i==TR_PRI_LOW) || (i==TR_PRI_NORMAL) || (i==TR_PRI_HIGH); +} + +void +tr_ctorSetBandwidthPriority( tr_ctor * ctor, tr_priority_t priority ) +{ +fprintf( stderr, "in tr_ctorSetPriority with %d\n", (int)priority ); + if( isPriority( priority ) ) + ctor->bandwidthPriority = priority; +} + +tr_priority_t +tr_ctorGetBandwidthPriority( const tr_ctor * ctor ) +{ +fprintf( stderr, "got priority with %d\n", (int)ctor->bandwidthPriority ); + return ctor->bandwidthPriority; +} + +/*** +**** +***/ + tr_ctor* tr_ctorNew( const tr_session * session ) { tr_ctor * ctor = tr_new0( struct tr_ctor, 1 ); ctor->session = session; + ctor->bandwidthPriority = TR_PRI_NORMAL; tr_ctorSetPaused( ctor, TR_FALLBACK, FALSE ); if( session != NULL ) { tr_ctorSetPeerLimit( ctor, TR_FALLBACK, session->peerLimitPerTorrent ); diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 81241e367..1aab17ee9 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -634,6 +634,8 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor ) tor->bandwidth = tr_bandwidthNew( session, session->bandwidth ); + tor->bandwidth->priority = tr_ctorGetBandwidthPriority( ctor ); + tor->error = TR_STAT_OK; tr_peerMgrAddTorrent( session->peerMgr, tor ); diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 767b12fa2..2ff59f31c 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -339,6 +339,18 @@ void tr_sessionSetDownloadDir( tr_session * session, const char * downloadDir ); */ const char * tr_sessionGetDownloadDir( const tr_session * session ); + +/** + * @brief Set the torrent's bandwidth priority. + */ +void tr_ctorSetBandwidthPriority( tr_ctor * ctor, tr_priority_t priority ); + +/** + * @brief Get the torrent's bandwidth priority. + */ +tr_priority_t tr_ctorGetBandwidthPriority( const tr_ctor * ctor ); + + /** * @brief set the per-session incomplete download folder. *