Changeset 5908


Ignore:
Timestamp:
May 22, 2008, 8:44:41 PM (13 years ago)
Author:
charles
Message:

(libt) more janitorial work on cleaning up tr_session*() and tr_torrent*() functions: session stats, torrent count, and manual update.

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/beos/TRWindow.cpp

    r5880 r5908  
    121121
    122122TRWindow::~TRWindow() {
    123         const int MAX_EXIT_WAIT_SECS = 10;
    124         const time_t deadline = time(0) + MAX_EXIT_WAIT_SECS;
    125         while (tr_torrentCount(engine) && time(NULL) < deadline) {
    126                 snooze(100000);
    127         }
    128         /* XXX there's no way to make sure the torrent threads are running so this might crash */
    129123        tr_sessionClose(engine);
    130124        stop_watching(this);
  • trunk/cli/transmissioncli.c

    r5900 r5908  
    299299            else {
    300300                fprintf( stderr, "\rReceived SIGHUP: manual update scheduled\n" );
    301                 tr_manualUpdate( tor );
     301                tr_torrentManualUpdate( tor );
    302302            }
    303303        }
  • trunk/gtk/main.c

    r5906 r5908  
    10231023    TrTorrent * tor = NULL;
    10241024    gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
    1025     tr_manualUpdate( tr_torrent_handle( tor ) );
     1025    tr_torrentManualUpdate( tr_torrent_handle( tor ) );
    10261026    g_object_unref( G_OBJECT( tor ) );
    10271027}
  • trunk/gtk/stats.c

    r5666 r5908  
    5858    struct stat_ui * ui = gdata;
    5959    tr_session_stats one, all;
    60     tr_getSessionStats( tr_core_handle( ui->core ), &one );
    61     tr_getCumulativeSessionStats( tr_core_handle( ui->core ), &all );
     60    tr_sessionGetStats( tr_core_handle( ui->core ), &one );
     61    tr_sessionGetCumulativeStats( tr_core_handle( ui->core ), &all );
    6262
    6363    setLabel( ui->one_up_lb, tr_strlsize( buf, one.uploadedBytes, sizeof(buf) ) );
     
    8585    {
    8686        tr_handle * handle = tr_core_handle( ui->core );
    87         tr_clearSessionStats( handle );
     87        tr_sessionClearStats( handle );
    8888        updateStats( ui );
    8989    }
  • trunk/gtk/tr-window.c

    r5673 r5908  
    615615    pch = pref_string_get( PREF_KEY_STATUSBAR_STATS );
    616616    if( !strcmp( pch, "session-ratio" ) ) {
    617         tr_getSessionStats( handle, &stats );
     617        tr_sessionGetStats( handle, &stats );
    618618        tr_strlratio( ratio, stats.ratio, sizeof( ratio ) );
    619619        g_snprintf( buf, sizeof(buf), _("Ratio: %s"), ratio );
    620620    } else if( !strcmp( pch, "session-transfer" ) ) {
    621         tr_getSessionStats( handle, &stats );
     621        tr_sessionGetStats( handle, &stats );
    622622        tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
    623623        tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
     
    627627        g_snprintf( buf, sizeof( buf ), Q_( "size|Down: %1$s, Up: %2$s" ), down, up );
    628628    } else if( !strcmp( pch, "total-transfer" ) ) {
    629         tr_getCumulativeSessionStats( handle, &stats );
     629        tr_sessionGetCumulativeStats( handle, &stats );
    630630        tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
    631631        tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
     
    635635        g_snprintf( buf, sizeof( buf ), Q_( "size|Down: %1$s, Up: %2$s" ), down, up );
    636636    } else { /* default is total-ratio */
    637         tr_getCumulativeSessionStats( handle, &stats );
     637        tr_sessionGetCumulativeStats( handle, &stats );
    638638        tr_strlratio( ratio, stats.ratio, sizeof( ratio ) );
    639639        g_snprintf( buf, sizeof(buf), _("Ratio: %s"), ratio );
  • trunk/libtransmission/rpc.c

    r5906 r5908  
    8181    {
    8282        tr_torrent * tor = NULL;
    83         const int n = tr_torrentCount( handle );
     83        const int n = tr_sessionCountTorrents( handle );
    8484        torrents = tr_new0( tr_torrent*, n );
    8585        while(( tor = tr_torrentNext( handle, tor )))
  • trunk/libtransmission/session.c

    r5900 r5908  
    398398
    399399int
    400 tr_torrentCount( const tr_handle * h )
     400tr_sessionCountTorrents( const tr_handle * h )
    401401{
    402402    return h->torrentCount;
  • trunk/libtransmission/stats.c

    r5843 r5908  
    104104{
    105105    tr_session_stats cumulative;
    106     tr_getCumulativeSessionStats( handle, &cumulative );
     106    tr_sessionGetCumulativeStats( handle, &cumulative );
    107107    saveCumulativeStats( handle, &cumulative );
    108108
     
    146146
    147147void
    148 tr_getSessionStats( const tr_handle   * handle,
     148tr_sessionGetStats( const tr_handle   * handle,
    149149                    tr_session_stats  * setme )
    150150{
     
    156156
    157157void
    158 tr_getCumulativeSessionStats( const tr_handle   * handle,
     158tr_sessionGetCumulativeStats( const tr_handle   * handle,
    159159                              tr_session_stats  * setme )
    160160{
    161161    tr_session_stats current;
    162     tr_getSessionStats( handle, &current );
     162    tr_sessionGetStats( handle, &current );
    163163    addStats( setme, &getStats(handle)->old, &current );
    164164}
    165165
    166166void
    167 tr_clearSessionStats( tr_handle * handle )
     167tr_sessionClearStats( tr_handle * handle )
    168168{
    169169    tr_session_stats zero;
  • trunk/libtransmission/torrent.c

    r5902 r5908  
    615615
    616616static void
    617 tr_manualUpdateImpl( void * vtor )
     617tr_torrentManualUpdateImpl( void * vtor )
    618618{
    619619    tr_torrent * tor = vtor;
     
    622622}
    623623void
    624 tr_manualUpdate( tr_torrent * tor )
    625 {
    626     tr_runInEventThread( tor->handle, tr_manualUpdateImpl, tor );
     624tr_torrentManualUpdate( tr_torrent * tor )
     625{
     626    tr_runInEventThread( tor->handle, tr_torrentManualUpdateImpl, tor );
    627627}
    628628int
  • trunk/libtransmission/transmission.h

    r5906 r5908  
    5353typedef uint64_t tr_block_index_t;
    5454
    55 enum
    56 {
    57     TR_PEER_FROM_INCOMING  = 0,  /* connections made to the listening port */
    58     TR_PEER_FROM_TRACKER   = 1,  /* peers received from a tracker */
    59     TR_PEER_FROM_CACHE     = 2,  /* peers read from the peer cache */
    60     TR_PEER_FROM_PEX       = 3,  /* peers discovered via PEX */
    61     TR_PEER_FROM__MAX
    62 };
    63 
    64 /***********************************************************************
    65  * tr_sessionInit
    66  ***********************************************************************
    67  * Initializes and returns an opaque libtransmission handle
    68  * to be passed to functions below. The tag argument is a short string
    69  * unique to the program invoking tr_sessionInit(), it is currently used
    70  * as part of saved torrent files' names to prevent one frontend from
    71  * deleting a torrent used by another. The following tags are used:
    72  *   beos cli daemon gtk macosx wx
    73  **********************************************************************/
     55const char* tr_getDefaultConfigDir( void );
    7456
    7557typedef struct tr_handle tr_handle;
    76 
    77 const char* tr_getDefaultConfigDir( void );
     58typedef struct tr_torrent tr_torrent;
     59typedef struct tr_ctor tr_ctor;
     60
     61/**
     62 * @addtogroup tr_session Session
     63 *
     64 * A libtransmission session is created by calling either tr_sessionInitFull()
     65 * or tr_sessionInit().  libtransmission creates a thread for itself so that
     66 * it can operate independently of the caller's event loop.  The session will
     67 * continue until tr_sessionClose() is called.
     68 *
     69 * @{
     70 */
    7871
    7972#define TR_DEFAULT_CONFIG_DIR                  tr_getDefaultConfigDir()
     
    8982#define TR_DEFAULT_RPC_ACL                     "+127.0.0.1"
    9083
     84/**
     85 * Create and return a Transmission session handle.
     86 *
     87 * @param configDir the config directory where libtransmission config
     88 *                  subdirectories will be found, such as "torrents",
     89 *                  "resume", and "blocklists".
     90 *                  TR_DEFAULT_CONFIG_DIR can be used as a default.
     91 * @param downloadDir the default directory to save torrents that are added.
     92 *                    This can be changed per-session with tr_sessionSetDownloadDir()
     93 *                    and per-torrent with tr_ctorSetDownloadDir().
     94 * @param tag currently only used for locating legacy versions of
     95 *            fastresume files.  valid tags: beos, cli, daemon, gtk, macos, wx
     96 * @param isPexEnabled whether or not PEX is allowed for non-private torrents.
     97 *                     This can be changed per-session  with tr_sessionSetPexEnabled().
     98 *                     TR_DEFAULT_PEX_ENABLED can be used as a default.
     99 * @param isPortForwardingEnabled If true, libtransmission will attempt to find a local
     100 *                                UPnP-enabled or NATPMP-enabled router and forward a
     101 *                                port from there to the local machine.  This is so that
     102 *                                remote peers can initiate connections with us.
     103 *                                TR_DEFAULT_PORT_FORWARDING_ENABLED can be used as a default.
     104 * @param publicPort Port number to open for listening to incoming peer connections.
     105 *                   TR_DEFAULT_PORT can be used as a default.
     106 * @param encryptionMode must be one of TR_PLAINTEXT_PREFERRED,
     107 *                       TR_ENCRYPTION_PREFERRED, or TR_ENCRYPTION_REQUIRED.
     108 * @param isUploadLimitEnabled If true, libtransmission will limit the entire
     109 *                             session's upload speed based on `uploadLimit'.
     110 * @param uploadLimit The speed limit to use for the entire session when
     111 *                    isUploadLimitEnabled is true.
     112 * @param isDownloadLimitEnabled If true, libtransmission will limit the entire
     113 *                               session's download speed based on `downloadLimit'.
     114 * @param downloadLimit The speed limit to use for the entire session when
     115 *                      isDownloadLimitEnabled is true.
     116 * @param peerLimit The maximum number of peer connections allowed in a session.
     117 *                  TR_DEFAULT_GLOBAL_PEER_LIMIT can be used as a default.
     118 *
     119 * @see TR_DEFAULT_PEER_SOCKET_TOS
     120 * @see TR_DEFAULT_BLOCKLIST_ENABLED
     121 * @see TR_DEFAULT_RPC_ENABLED
     122 * @see TR_DEFAULT_RPC_PORT
     123 * @see TR_DEFAULT_RPC_ACL
     124 */
    91125tr_handle * tr_sessionInitFull( const char * configDir,
    92126                                const char * downloadDir,
     
    100134                                int          isDownloadLimitEnabled,
    101135                                int          downloadLimit,
    102                                 int          globalPeerLimit,
     136                                int          peerLimit,
    103137                                int          messageLevel,
    104138                                int          isMessageQueueingEnabled,
     
    121155void tr_sessionClose( tr_handle * );
    122156
     157/**
     158 * Set the per-session default download folder for torrents that haven't been added yet.
     159 * @see tr_sessionInitFull()
     160 * @see tr_ctorSetDownloadDir()
     161 */
    123162void tr_sessionSetDownloadDir( tr_handle *, const char * downloadDir );
    124163
     
    190229
    191230/* stats from the current session. */
    192 void tr_getSessionStats( const tr_handle   * handle,
     231void tr_sessionGetStats( const tr_handle   * handle,
    193232                         tr_session_stats  * setme );
    194233
    195234/* stats from the current and past sessions. */
    196 void tr_getCumulativeSessionStats( const tr_handle   * handle,
     235void tr_sessionGetCumulativeStats( const tr_handle   * handle,
    197236                                   tr_session_stats  * setme );
    198237
    199 void tr_clearSessionStats( tr_handle * handle );
     238void tr_sessionClearStats( tr_handle * handle );
    200239
    201240/**
     
    253292tr_port_forwarding tr_sessionGetPortForwarding( const tr_handle * );
    254293
    255 
    256 //ccccccc
     294int tr_sessionCountTorrents( const tr_handle * h );
     295
     296void tr_sessionSetSpeedLimitEnabled( tr_handle   * session,
     297                                     int           up_or_down,
     298                                     int           isEnabled );
     299
     300enum { TR_UP, TR_DOWN };
     301
     302int tr_sessionIsSpeedLimitEnabled( const tr_handle   * session,
     303                                   int                 up_or_down );
     304
     305void tr_sessionSetSpeedLimit( tr_handle   * session,
     306                              int           up_or_down,
     307                              int           KiB_sec );
     308
     309int tr_sessionGetSpeedLimit( const tr_handle   * session,
     310                             int                 up_or_down );
     311
     312void tr_sessionSetPeerLimit( tr_handle * handle,
     313                             uint16_t    maxGlobalPeers );
     314
     315uint16_t tr_sessionGetPeerLimit( const tr_handle * handle );
     316
     317/**
     318 *  Load all the torrents in tr_getTorrentDir().
     319 *  This can be used at startup to kickstart all the torrents
     320 *  from the previous session.
     321 */
     322tr_torrent ** tr_sessionLoadTorrents ( tr_handle  * h,
     323                                       tr_ctor    * ctor,
     324                                       int        * setmeCount );
     325
     326
     327
     328
     329/** @} */
     330
    257331
    258332/**
     
    280354    uint8_t level;
    281355
     356    /* The line number in the source file where this message originated */
     357    int line;
     358
    282359    /* Time the message was generated */
    283360    time_t when;
     
    294371    const char * file;
    295372
    296     /* The line number in the source file where this message originated */
    297     int line;
    298 
    299373    /* linked list of messages */
    300374    struct tr_msg_list * next;
     
    307381void tr_freeMessageList( tr_msg_list * freeme );
    308382
    309 
    310 /***********************************************************************
    311 ***
    312 ***  TORRENTS
    313 **/
    314 
    315 typedef struct tr_torrent tr_torrent;
    316 
    317 int tr_torrentCount( const tr_handle * h );
    318 
    319 /**
    320  * Iterate through the torrents.
    321  * Pass in in a NULL pointer to get the first torrent.
    322  */
    323 tr_torrent* tr_torrentNext( tr_handle *, tr_torrent * );
    324 
    325 /***********************************************************************
    326 *** Speed Limits
    327 **/
    328 
    329 enum { TR_UP, TR_DOWN };
    330 
    331 typedef enum
    332 {
    333     TR_SPEEDLIMIT_GLOBAL,    /* only follow the overall speed limit */
    334     TR_SPEEDLIMIT_SINGLE,    /* only follow the per-torrent limit */
    335     TR_SPEEDLIMIT_UNLIMITED  /* no limits at all */
    336 }
    337 tr_speedlimit;
    338 
    339 void tr_torrentSetSpeedMode( tr_torrent   * tor,
    340                              int            up_or_down,
    341                              tr_speedlimit  mode );
    342 
    343 tr_speedlimit tr_torrentGetSpeedMode( const tr_torrent  * tor,
    344                                       int                 up_or_down);
    345 
    346 void tr_torrentSetSpeedLimit( tr_torrent   * tor,
    347                               int            up_or_down,
    348                               int            KiB_sec );
    349 
    350 int tr_torrentGetSpeedLimit( const tr_torrent  * tor,
    351                              int                 up_or_down );
    352 
    353 void tr_sessionSetSpeedLimitEnabled( tr_handle   * session,
    354                                      int           up_or_down,
    355                                      int           isEnabled );
    356 
    357 int tr_sessionIsSpeedLimitEnabled( const tr_handle   * session,
    358                                    int                 up_or_down );
    359 
    360 void tr_sessionSetSpeedLimit( tr_handle   * session,
    361                               int           up_or_down,
    362                               int           KiB_sec );
    363 
    364 int tr_sessionGetSpeedLimit( const tr_handle   * session,
    365                              int                 up_or_down );
    366 
    367 
    368 /***********************************************************************
    369 ***  Peer Limits
    370 **/
    371 
    372 void tr_torrentSetPeerLimit( tr_torrent  * tor,
    373                              uint16_t      peerLimit );
    374 
    375 uint16_t tr_torrentGetPeerLimit( const tr_torrent  * tor );
    376 
    377 void tr_sessionSetPeerLimit( tr_handle * handle,
    378                              uint16_t    maxGlobalPeers );
    379 
    380 uint16_t tr_sessionGetPeerLimit( const tr_handle * handle );
    381 
    382 
     383/** @addtogroup Blocklists
     384    @{ */
     385 
    383386/**
    384387 * Specify a range of IPs for Transmission to block.
     
    414417int tr_blocklistHasAddress( tr_handle             * handle,
    415418                            const struct in_addr  * addr);
     419
     420/** @} */
     421
     422
     423
     424/***********************************************************************
     425***
     426***  TORRENTS
     427**/
     428
     429/** @addtogroup tr_torrent Torrents
     430    @{ */
     431
     432/**
     433 * Iterate through the torrents.
     434 * Pass in in a NULL pointer to get the first torrent.
     435 */
     436tr_torrent* tr_torrentNext( tr_handle *, tr_torrent * );
     437
     438/***********************************************************************
     439*** Speed Limits
     440**/
     441
     442typedef enum
     443{
     444    TR_SPEEDLIMIT_GLOBAL,    /* only follow the overall speed limit */
     445    TR_SPEEDLIMIT_SINGLE,    /* only follow the per-torrent limit */
     446    TR_SPEEDLIMIT_UNLIMITED  /* no limits at all */
     447}
     448tr_speedlimit;
     449
     450void tr_torrentSetSpeedMode( tr_torrent   * tor,
     451                             int            up_or_down,
     452                             tr_speedlimit  mode );
     453
     454tr_speedlimit tr_torrentGetSpeedMode( const tr_torrent  * tor,
     455                                      int                 up_or_down);
     456
     457void tr_torrentSetSpeedLimit( tr_torrent   * tor,
     458                              int            up_or_down,
     459                              int            KiB_sec );
     460
     461int tr_torrentGetSpeedLimit( const tr_torrent  * tor,
     462                             int                 up_or_down );
     463
     464
     465/***********************************************************************
     466***  Peer Limits
     467**/
     468
     469void tr_torrentSetPeerLimit( tr_torrent  * tor,
     470                             uint16_t      peerLimit );
     471
     472uint16_t tr_torrentGetPeerLimit( const tr_torrent  * tor );
    416473
    417474
     
    499556tr_ctorMode;
    500557
    501 typedef struct tr_ctor tr_ctor;
    502558struct tr_benc;
    503559
     
    526582                                         uint16_t         peerLimit  );
    527583
     584/**
     585 * Set the download folder for the torrent being added with this ctor.
     586 * @see tr_ctorSetDownloadDir()
     587 * @see tr_sessionInitFull()
     588 */
    528589void     tr_ctorSetDownloadDir         ( tr_ctor        * ctor,
    529590                                         tr_ctorMode      mode,
     
    592653
    593654
    594 /**
    595  *  Load all the torrents in tr_getTorrentDir().
    596  *  This can be used at startup to kickstart all the torrents
    597  *  from the previous session.
    598  */
    599 tr_torrent ** tr_sessionLoadTorrents ( tr_handle  * h,
    600                                        tr_ctor    * ctor,
    601                                        int        * setmeCount );
    602 
    603 
    604 
    605655const tr_info * tr_torrentInfo( const tr_torrent * );
    606656
     
    674724 * Trackers usually set an announce interval of 15 or 30 minutes.
    675725 * Users can send one-time announce requests that override this
    676  * interval by calling tr_manualUpdate().
    677  *
    678  * The wait interval for tr_manualUpdate() is much smaller.
     726 * interval by calling tr_torrentManualUpdate().
     727 *
     728 * The wait interval for tr_torrentManualUpdate() is much smaller.
    679729 * You can test whether or not a manual update is possible
    680730 * (for example, to desensitize the button) by calling
     
    682732 */
    683733
    684 void tr_manualUpdate( tr_torrent * );
     734void tr_torrentManualUpdate( tr_torrent * );
    685735
    686736int tr_torrentCanManualUpdate( const tr_torrent * );
     
    891941     * This value is ~(time_t)0 if the tracker returned a serious error.
    892942     * Otherwise, the value is a valid time.
    893      * @see tr_manualUpdate( tr_torrent * );
     943     * @see tr_torrentManualUpdate( tr_torrent * );
    894944     * @see tr_torrentCanManualUpdate( const tr_torrent * ); */
    895945    time_t nextManualAnnounceTime;
     
    897947
    898948tr_torrent_status tr_torrentGetStatus( tr_torrent * );
     949
     950enum
     951{
     952    TR_PEER_FROM_INCOMING  = 0,  /* connections made to the listening port */
     953    TR_PEER_FROM_TRACKER   = 1,  /* peers received from a tracker */
     954    TR_PEER_FROM_CACHE     = 2,  /* peers read from the peer cache */
     955    TR_PEER_FROM_PEX       = 3,  /* peers discovered via PEX */
     956    TR_PEER_FROM__MAX
     957};
    899958
    900959struct tr_stat
     
    10221081};
    10231082
     1083/** @} */
    10241084
    10251085#ifdef __TRANSMISSION__
  • trunk/macosx/Controller.m

    r5907 r5908  
    14541454                    tr_session_stats stats;
    14551455                    if (total)
    1456                         tr_getCumulativeSessionStats(fLib, &stats);
     1456                        tr_sessionGetCumulativeStats(fLib, &stats);
    14571457                    else
    1458                         tr_getSessionStats(fLib, &stats);
     1458                        tr_sessionGetStats(fLib, &stats);
    14591459                   
    14601460                    statusString = [NSString stringWithFormat: @"%@: %@", NSLocalizedString(@"Ratio", "status bar -> status label"),
     
    14671467                    tr_session_stats stats;
    14681468                    if (total)
    1469                         tr_getCumulativeSessionStats(fLib, &stats);
     1469                        tr_sessionGetCumulativeStats(fLib, &stats);
    14701470                    else
    1471                         tr_getSessionStats(fLib, &stats);
     1471                        tr_sessionGetStats(fLib, &stats);
    14721472                   
    14731473                    statusString = [NSString stringWithFormat: @"%@: %@  %@: %@",
  • trunk/macosx/StatsWindowController.m

    r5671 r5908  
    164164{
    165165    tr_session_stats statsAll, statsSession;
    166     tr_getCumulativeSessionStats(fLib, &statsAll);
    167     tr_getSessionStats(fLib, &statsSession);
     166    tr_sessionGetCumulativeStats(fLib, &statsAll);
     167    tr_sessionGetStats(fLib, &statsSession);
    168168   
    169169    [fUploadedField setStringValue: [NSString stringForFileSize: statsSession.uploadedBytes]];
     
    203203- (void) performResetStats
    204204{
    205     tr_clearSessionStats(fLib);
     205    tr_sessionClearStats(fLib);
    206206    [self updateStats];
    207207}
  • trunk/macosx/Torrent.m

    r5907 r5908  
    335335- (void) manualAnnounce
    336336{
    337     tr_manualUpdate(fHandle);
     337    tr_torrentManualUpdate(fHandle);
    338338}
    339339
     
    16311631    fResumeOnWake = NO;
    16321632   
    1633     fOrderValue = orderValue ? [orderValue intValue] : tr_torrentCount(lib) - 1;
     1633    fOrderValue = orderValue ? [orderValue intValue] : tr_sessionCountTorrents(lib) - 1;
    16341634    fGroupValue = groupValue ? [groupValue intValue] : -1;
    16351635   
  • trunk/wx/xmission.cc

    r5880 r5908  
    456456{
    457457    if( myExitTime ) {
    458         if ( !tr_torrentCount(handle) ||  myExitTime<time(0) ) {
     458        if ( !tr_sessionCountTorrents(handle) ||  myExitTime<time(0) ) {
    459459            delete myTrayIcon;
    460460            myTrayIcon = 0;
Note: See TracChangeset for help on using the changeset viewer.