Ignore:
Timestamp:
Mar 4, 2009, 7:52:57 PM (14 years ago)
Author:
charles
Message:

(trunk) libT and gtk+ parts for #1889: per-torrent vs. global speed limit confusion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r8014 r8021  
    110110
    111111void
    112 tr_torrentSetSpeedMode( tr_torrent *  tor,
    113                         tr_direction  dir,
    114                         tr_speedlimit mode )
    115 {
    116     assert( tor != NULL );
     112tr_torrentSetSpeedLimit( tr_torrent * tor, tr_direction dir, int KiB_sec )
     113{
     114    assert( tr_isTorrent( tor ) );
    117115    assert( tr_isDirection( dir ) );
    118     assert( mode==TR_SPEEDLIMIT_GLOBAL || mode==TR_SPEEDLIMIT_SINGLE || mode==TR_SPEEDLIMIT_UNLIMITED  );
    119 
    120     tor->speedLimitMode[dir] = mode;
    121 
    122     tr_bandwidthSetLimited( tor->bandwidth, dir, mode==TR_SPEEDLIMIT_SINGLE );
    123     tr_bandwidthHonorParentLimits( tor->bandwidth, dir, mode==TR_SPEEDLIMIT_GLOBAL );
    124 }
    125 
    126 tr_speedlimit
    127 tr_torrentGetSpeedMode( const tr_torrent * tor,
    128                         tr_direction       dir )
    129 {
    130     assert( tor != NULL );
     116
     117    tr_bandwidthSetDesiredSpeed( tor->bandwidth, dir, KiB_sec );
     118}
     119
     120int
     121tr_torrentGetSpeedLimit( const tr_torrent * tor, tr_direction dir )
     122{
     123    assert( tr_isTorrent( tor ) );
    131124    assert( tr_isDirection( dir ) );
    132125
    133     return tor->speedLimitMode[dir];
    134 }
    135 
    136 void
    137 tr_torrentSetSpeedLimit( tr_torrent * tor,
    138                          tr_direction dir,
    139                          int          desiredSpeed )
    140 {
    141     tr_bandwidthSetDesiredSpeed( tor->bandwidth, dir, desiredSpeed );
    142 }
    143 
    144 int
    145 tr_torrentGetSpeedLimit( const tr_torrent * tor,
    146                          tr_direction       dir )
    147 {
    148     assert( tr_isTorrent( tor ) );
    149 
    150126    return tr_bandwidthGetDesiredSpeed( tor->bandwidth, dir );
    151127}
     128
     129void
     130tr_torrentUseSpeedLimit( tr_torrent * tor, tr_direction dir, tr_bool do_use )
     131{
     132    assert( tr_isTorrent( tor ) );
     133    assert( tr_isDirection( dir ) );
     134
     135    tr_bandwidthSetLimited( tor->bandwidth, dir, do_use );
     136}
     137
     138tr_bool
     139tr_torrentIsUsingSpeedLimit( const tr_torrent * tor, tr_direction dir )
     140{
     141    assert( tr_isTorrent( tor ) );
     142    assert( tr_isDirection( dir ) );
     143
     144    return tr_bandwidthIsLimited( tor->bandwidth, dir );
     145}
     146
     147void
     148tr_torrentUseGlobalSpeedLimit( tr_torrent * tor, tr_direction dir, tr_bool do_use )
     149{
     150    assert( tr_isTorrent( tor ) );
     151    assert( tr_isDirection( dir ) );
     152
     153    tr_bandwidthHonorParentLimits( tor->bandwidth, dir, do_use );
     154}
     155
     156tr_bool
     157tr_torrentIsUsingGlobalSpeedLimit( const tr_torrent * tor, tr_direction dir )
     158{
     159    assert( tr_isTorrent( tor ) );
     160    assert( tr_isDirection( dir ) );
     161
     162    return tr_bandwidthAreParentLimitsHonored( tor->bandwidth, dir );
     163}
     164
     165/***
     166****
     167***/
    152168
    153169void
     
    193209                                  tr_direction        direction )
    194210{
    195     tr_bool isEnabled = FALSE;
    196 
    197     switch( tr_torrentGetSpeedMode( tor, direction ) )
    198     {
    199         case TR_SPEEDLIMIT_GLOBAL:
    200             isEnabled = !tr_sessionIsSpeedLimitEnabled( tor->session, direction )
    201                       || tr_sessionGetSpeedLimit( tor->session, direction ) > 0;
    202             break;
    203 
    204         case TR_SPEEDLIMIT_SINGLE:
    205             isEnabled = tr_torrentGetSpeedLimit( tor, direction ) > 0;
    206             break;
    207 
    208         case TR_SPEEDLIMIT_UNLIMITED:
    209             isEnabled = TRUE;
    210             break;
    211 
    212         default:
    213             assert( 0 && "unhandled speed mode" );
    214             break;
    215     }
    216 
    217     return isEnabled;
     211    tr_bool allowed = TRUE;
     212
     213    if( tr_torrentIsUsingSpeedLimit( tor, direction ) )
     214        if( tr_torrentGetSpeedLimit( tor, direction ) <= 0 )
     215            allowed = FALSE;
     216
     217    if( tr_torrentIsUsingGlobalSpeedLimit( tor, direction ) )
     218        if( tr_sessionIsSpeedLimitEnabled( tor->session, direction ) )
     219            if( tr_sessionGetSpeedLimit( tor->session, direction ) <= 0 )
     220                allowed = FALSE;
     221
     222    return allowed;
    218223}
    219224
Note: See TracChangeset for help on using the changeset viewer.