Changeset 10366


Ignore:
Timestamp:
Mar 12, 2010, 7:35:28 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #3026 "speed limit mode not honoring limits on other days" -- fixed regression caused by r10352 reported by m1b.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r10352 r10366  
    525525}
    526526
    527 static void turtleCheckClock( tr_session * session, struct tr_turtle_info * t, tr_bool byUser );
     527static void turtleCheckClock( tr_session * s, struct tr_turtle_info * t );
    528528
    529529static void
     
    549549    /* tr_session things to do once per second */
    550550    tr_timeUpdate( tv.tv_sec );
    551     turtleCheckClock( session, &session->turtle, FALSE );
     551    if( session->turtle.isClockEnabled )
     552        turtleCheckClock( session, &session->turtle );
    552553}
    553554
     
    11431144
    11441145static void
    1145 useAltSpeed( tr_session * s, struct tr_turtle_info * t, tr_bool enabled, tr_bool byUser )
     1146useAltSpeed( tr_session * s, struct tr_turtle_info * t,
     1147             tr_bool enabled, tr_bool byUser )
    11461148{
    11471149    assert( tr_isSession( s ) );
     
    11581160}
    11591161
    1160 static tr_bool
    1161 testTurtleTime( const struct tr_turtle_info * t )
    1162 {
     1162/**
     1163 * @param enabled whether turtle should be on/off according to the scheduler
     1164 * @param changed whether that's different from the previous minute
     1165 */
     1166static void
     1167testTurtleTime( const struct tr_turtle_info * t,
     1168                tr_bool * enabled,
     1169                tr_bool * changed )
     1170{
     1171    tr_bool e;
    11631172    struct tm tm;
    11641173    size_t minute_of_the_week;
     
    11701179                       + tm.tm_hour * MINUTES_PER_HOUR
    11711180                       + tm.tm_min;
    1172 
    11731181    if( minute_of_the_week >= MINUTES_PER_WEEK ) /* leap minutes? */
    11741182        minute_of_the_week = MINUTES_PER_WEEK - 1;
    11751183
    1176     return tr_bitfieldHasFast( &t->minutes, minute_of_the_week );
    1177 }
    1178 
    1179 static void
    1180 turtleCheckClock( tr_session * session, struct tr_turtle_info * t, tr_bool byUser )
    1181 {
    1182     if( t->isClockEnabled )
    1183     {
    1184         const tr_bool hit = testTurtleTime( t );
    1185 
    1186         if( hit != t->isEnabled )
    1187         {
    1188             tr_inf( "Time to turn %s turtle mode!", (hit?"on":"off") );
    1189             useAltSpeed( session, t, hit, byUser );
    1190         }
     1184    e = tr_bitfieldHasFast( &t->minutes, minute_of_the_week );
     1185    if( enabled != NULL )
     1186        *enabled = e;
     1187
     1188    if( changed != NULL )
     1189    {
     1190        const size_t prev = minute_of_the_week > 0 ? minute_of_the_week - 1
     1191                                                   : MINUTES_PER_WEEK - 1;
     1192        *changed = e != tr_bitfieldHasFast( &t->minutes, prev );
     1193    }
     1194}
     1195
     1196static void
     1197turtleCheckClock( tr_session * s, struct tr_turtle_info * t )
     1198{
     1199    tr_bool enabled;
     1200    tr_bool changed;
     1201
     1202    assert( t->isClockEnabled );
     1203
     1204    testTurtleTime( t, &enabled, &changed );
     1205
     1206    if( changed )
     1207    {
     1208        tr_inf( "Time to turn %s turtle mode!", (enabled?"on":"off") );
     1209        useAltSpeed( s, t, enabled, FALSE );
    11911210    }
    11921211}
     
    12051224
    12061225    if( turtle->isClockEnabled )
    1207         turtle->isEnabled = testTurtleTime( turtle );
     1226        testTurtleTime( turtle, &turtle->isEnabled, NULL );
    12081227
    12091228    altSpeedToggled( session );
     
    12891308
    12901309    if( t->isClockEnabled )
    1291         useAltSpeed( s, t, testTurtleTime( t ), TRUE );
     1310    {
     1311        tr_bool enabled, changed;
     1312        testTurtleTime( t, &enabled, &changed );
     1313        useAltSpeed( s, t, enabled, TRUE );
     1314    }
    12921315}
    12931316
  • trunk/libtransmission/session.h

    r10352 r10366  
    4343struct tr_fdInfo;
    4444
    45 /**
    46  * How clock mode works:
    47  *
    48  * ._nextChangeAt, ._nextChangeValue and ._nextChangeAllowed are private fields
    49  * that are derived from .days, .beginMinute, .endMinute and the current time.
    50  * They're rebuilt when either (a) the user changes the clock settings or
    51  * (b) when the time at ._nextChangeAt is reached.
    52  *
    53  * When ._nextChangeAt is reached, if .isClockEnabled and ._nextChangeAllowed
    54  * are both true, then turtle mode's flag is set to ._nextChangeValue.
    55  */
    5645struct tr_turtle_info
    5746{
     
    8473    tr_bool changedByUser;
    8574
     75    /* bitfield of all the minutes in a week.
     76     * Each bit's value indicates whether the scheduler wants turtle
     77     * limits on or off at that given minute in the week. */
    8678    tr_bitfield minutes;
    8779};
Note: See TracChangeset for help on using the changeset viewer.