Changeset 8130


Ignore:
Timestamp:
Apr 4, 2009, 2:17:39 AM (13 years ago)
Author:
livings124
Message:

libT support for #1679 Schedule Speed Limit mode based on days, not just time

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/rpc-spec.txt

    r8129 r8130  
    361361   "alt-speed-time-enabled"   | 'boolean'  true means the scheduled on/off times are used
    362362   "alt-speed-time-end"       | number     when to turn off alt speeds (units: same)
     363   "alt-speed-time-day"       | number     what day(s) to turn on alt speeds (look at tr_sched_day)
    363364   "alt-speed-up"             | number     max global upload speed (in K/s)
    364365   "blocklist-enabled"        | 'boolean'  true means enabled
  • trunk/libtransmission/rpcimpl.c

    r8129 r8130  
    10181018    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i ) )
    10191019        tr_sessionSetAltSpeedEnd( session, i );
     1020    if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &i ) )
     1021        tr_sessionSetAltSpeedDay( session, i );
    10201022    if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal ) )
    10211023        tr_sessionUseAltSpeedTime( session, boolVal );
     
    11281130    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, tr_sessionGetAltSpeedBegin(s) );
    11291131    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END,tr_sessionGetAltSpeedEnd(s) );
     1132    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY,tr_sessionGetAltSpeedDay(s) );
    11301133    tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime(s) );
    11311134    tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) );
  • trunk/libtransmission/session.c

    r8128 r8130  
    210210isAltTime( const tr_session * s )
    211211{
    212     tr_bool is;
    213     int minutes;
     212    int minutes, day;
     213    tr_bool withinTime;
    214214    struct tm tm;
    215215    const time_t now = time( NULL );
    216216    const int begin = s->altSpeedTimeBegin;
    217217    const int end = s->altSpeedTimeEnd;
     218    const tr_bool toNextDay = begin > end;
    218219
    219220    tr_localtime_r( &now, &tm );
    220221    minutes = tm.tm_hour*60 + tm.tm_min;
    221 
    222     if( begin <= end )
    223         is = ( begin <= minutes ) && ( minutes < end );
     222    day = tm.tm_wday;
     223   
     224    if( !toNextDay )
     225        withinTime = ( begin <= minutes ) && ( minutes < end );
    224226    else /* goes past midnight */
    225         is = ( begin <= minutes ) || ( minutes < end );
    226 
    227     return is;
     227        withinTime = ( begin <= minutes ) || ( minutes < end );
     228   
     229    if( !withinTime )
     230        return FALSE;
     231   
     232    if( toNextDay && (minutes < end) )
     233        day = (day - 1) % 7;
     234   
     235    if( s->altSpeedTimeDay == TR_SCHED_ALL )
     236        return TRUE;
     237    else if( s->altSpeedTimeDay == TR_SCHED_WEEKDAY )
     238        return (day != 0) && day != 6;
     239    else if( s->altSpeedTimeDay == TR_SCHED_WEEKEND )
     240        return (day == 0) || (day == 6);
     241    else
     242        return day == s->altSpeedTimeDay;
    228243}
    229244
     
    284299    tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED,   FALSE );
    285300    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END,       1020 ); /* 5pm */
     301    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY,       TR_SCHED_ALL );
    286302    tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED,                   100 );
    287303    tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED,           FALSE );
     
    338354    tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED,   tr_sessionUsesAltSpeedTime( s ) );
    339355    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END,       tr_sessionGetAltSpeedEnd( s ) );
     356    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY,       tr_sessionGetAltSpeedDay( s ) );
    340357    tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED,                   tr_sessionGetSpeedLimit( s, TR_UP ) );
    341358    tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED,           tr_sessionIsSpeedLimited( s, TR_UP ) );
     
    607624    session->peerPort = session->isPortRandom ? getRandomPort( session ) : j;
    608625    session->shared = tr_sharedInit( session, boolVal, session->peerPort );
    609     session->isPortSet = session->isPortRandom || j>0;
     626    session->isPortSet = session->peerPort > 0;
    610627
    611628    /**
     
    653670    assert( found );
    654671    session->altSpeedTimeEnd = i;
     672   
     673    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &i );
     674    assert( found );
     675    session->altSpeedTimeDay = i;
    655676
    656677    found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal );
     
    964985        const time_t now = time( NULL );
    965986        struct tm tm;
    966         int currentMinute;
     987        int currentMinute, day;
     988        tr_bool isBeginTime, isEndTime, isDay;
    967989        tr_localtime_r( &now, &tm );
    968990        currentMinute = tm.tm_hour*60 + tm.tm_min;
    969 
    970         if( currentMinute == session->altSpeedTimeBegin )
     991        day = tm.tm_wday;
     992       
     993        isBeginTime = currentMinute == session->altSpeedTimeBegin;
     994        isEndTime = currentMinute == session->altSpeedTimeEnd;
     995        if( isBeginTime || isEndTime )
    971996        {
    972             useAltSpeed( session, TRUE, FALSE );
    973         }
    974         else if( currentMinute == session->altSpeedTimeEnd )
    975         {
    976             useAltSpeed( session, FALSE, FALSE );
     997            /* if looking at the end date, look at the next day if end time is before begin time */
     998            if( isEndTime && !isBeginTime && session->altSpeedTimeEnd < session->altSpeedTimeBegin )
     999                day = (day - 1) % 7;
     1000           
     1001            if( session->altSpeedTimeDay == TR_SCHED_ALL )
     1002                isDay = TRUE;
     1003            else if( session->altSpeedTimeDay == TR_SCHED_WEEKDAY )
     1004                isDay = (day != 0) && (day != 6);
     1005            else if( session->altSpeedTimeDay == TR_SCHED_WEEKEND )
     1006                isDay = (day == 0) || (day == 6);
     1007            else
     1008                isDay = day == session->altSpeedTimeDay;
     1009
     1010            if( isDay )
     1011                useAltSpeed( session, isBeginTime, FALSE );
    9771012        }
    9781013    }
     
    11271162
    11281163    return s->altSpeedTimeEnd;
     1164}
     1165
     1166void
     1167tr_sessionSetAltSpeedDay( tr_session * s, tr_sched_day day )
     1168{
     1169    assert( tr_isSession( s ) );
     1170
     1171    if( s->altSpeedTimeDay != day )
     1172    {
     1173        s->altSpeedTimeDay = day;
     1174
     1175        if( tr_sessionUsesAltSpeedTime( s ) )
     1176            useAltSpeed( s, isAltTime( s ), TRUE );
     1177    }
     1178}
     1179
     1180tr_sched_day
     1181tr_sessionGetAltSpeedDay( const tr_session * s )
     1182{
     1183    assert( tr_isSession( s ) );
     1184
     1185    return s->altSpeedTimeDay;
    11291186}
    11301187
  • trunk/libtransmission/session.h

    r8118 r8130  
    7878    int                          altSpeedTimeBegin;
    7979    int                          altSpeedTimeEnd;
     80    tr_sched_day                 altSpeedTimeDay;
    8081    tr_bool                      altSpeedTimeEnabled;
    8182    tr_bool                      altSpeedChangedByUser;
  • trunk/libtransmission/transmission.h

    r8127 r8130  
    167167#define TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED     "alt-speed-time-enabled"
    168168#define TR_PREFS_KEY_ALT_SPEED_TIME_END         "alt-speed-time-end"
     169#define TR_PREFS_KEY_ALT_SPEED_TIME_DAY         "alt-speed-time-day"
    169170#define TR_PREFS_KEY_BLOCKLIST_ENABLED          "blocklist-enabled"
    170171#define TR_PREFS_KEY_DOWNLOAD_DIR               "download-dir"
     
    603604int      tr_sessionGetAltSpeedEnd     ( const tr_session * );
    604605
     606typedef enum
     607{
     608    TR_SCHED_SUN = 0, //specific days correspond to stuct tm's tm_wday
     609    TR_SCHED_MON,
     610    TR_SCHED_TUES,
     611    TR_SCHED_WED,
     612    TR_SCHED_THURS,
     613    TR_SCHED_FRI,
     614    TR_SCHED_SAT,
     615    TR_SCHED_WEEKDAY,
     616    TR_SCHED_WEEKEND,
     617    TR_SCHED_ALL
     618}
     619tr_sched_day;
     620
     621void     tr_sessionSetAltSpeedDay     ( tr_session *, tr_sched_day day );
     622tr_sched_day tr_sessionGetAltSpeedDay ( const tr_session * );
     623
    605624typedef void ( tr_altSpeedFunc )      ( tr_session *, tr_bool active, tr_bool userDriven, void * );
    606625void     tr_sessionClearAltSpeedFunc  ( tr_session * );
Note: See TracChangeset for help on using the changeset viewer.