Ignore:
Timestamp:
Dec 14, 2008, 11:21:11 AM (12 years ago)
Author:
charles
Message:

(trunk libT) more semantic cleanup: tr_handle->tr_session, int->tr_bool, int->tr_port

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r7368 r7385  
    6161
    6262tr_torrent*
    63 tr_torrentFindFromId( tr_handle * handle,
    64                       int         id )
     63tr_torrentFindFromId( tr_session * session, int id )
    6564{
    6665    tr_torrent * tor = NULL;
    6766
    68     while( ( tor = tr_torrentNext( handle, tor ) ) )
     67    while( ( tor = tr_torrentNext( session, tor ) ) )
    6968        if( tor->uniqueId == id )
    7069            return tor;
     
    7473
    7574tr_torrent*
    76 tr_torrentFindFromHashString( tr_handle *  handle,
    77                               const char * str )
     75tr_torrentFindFromHashString( tr_session *  session, const char * str )
    7876{
    7977    tr_torrent * tor = NULL;
    8078
    81     while( ( tor = tr_torrentNext( handle, tor ) ) )
     79    while( ( tor = tr_torrentNext( session, tor ) ) )
    8280        if( !strcmp( str, tor->info.hashString ) )
    8381            return tor;
     
    8785
    8886tr_bool
    89 tr_torrentExists( const tr_handle * handle,
    90                   const uint8_t *   torrentHash )
    91 {
    92     return tr_torrentFindFromHash( (tr_handle*)handle,
    93                                   torrentHash ) != NULL;
     87tr_torrentExists( const tr_session * session, const uint8_t *   torrentHash )
     88{
     89    return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL;
    9490}
    9591
    9692tr_torrent*
    97 tr_torrentFindFromHash( tr_handle *     handle,
    98                         const uint8_t * torrentHash )
     93tr_torrentFindFromHash( tr_session * session, const uint8_t * torrentHash )
    9994{
    10095    tr_torrent * tor = NULL;
    10196
    102     while( ( tor = tr_torrentNext( handle, tor ) ) )
     97    while( ( tor = tr_torrentNext( session, tor ) ) )
    10398        if( *tor->info.hash == *torrentHash )
    10499            if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
     
    109104
    110105tr_torrent*
    111 tr_torrentFindFromObfuscatedHash( tr_handle *     handle,
     106tr_torrentFindFromObfuscatedHash( tr_session * session,
    112107                                  const uint8_t * obfuscatedTorrentHash )
    113108{
    114109    tr_torrent * tor = NULL;
    115110
    116     while( ( tor = tr_torrentNext( handle, tor ) ) )
     111    while( ( tor = tr_torrentNext( session, tor ) ) )
    117112        if( !memcmp( tor->obfuscatedHash, obfuscatedTorrentHash,
    118113                     SHA_DIGEST_LENGTH ) )
     
    467462
    468463static void
    469 torrentRealInit( tr_handle *     h,
    470                  tr_torrent *    tor,
    471                  const tr_ctor * ctor )
     464torrentRealInit( tr_session      * session,
     465                 tr_torrent      * tor,
     466                 const tr_ctor   * ctor )
    472467{
    473468    int        doStart;
     
    477472    static int nextUniqueId = 1;
    478473
    479     tr_globalLock( h );
    480 
    481     tor->session   = h;
     474    tr_globalLock( session );
     475
     476    tor->session   = session;
    482477    tor->uniqueId = nextUniqueId++;
    483478
    484479    randomizeTiers( info );
    485480
    486     tor->bandwidth = tr_bandwidthNew( h, h->bandwidth );
     481    tor->bandwidth = tr_bandwidthNew( session, session->bandwidth );
    487482
    488483    tor->blockSize = getBlockSize( info->pieceSize );
     
    532527             NULL );
    533528
    534     tr_peerMgrAddTorrent( h->peerMgr, tor );
    535 
    536     assert( h->isPortSet );
    537 
     529    tr_peerMgrAddTorrent( session->peerMgr, tor );
     530
     531    assert( session->isPortSet );
    538532    assert( !tor->downloadedCur );
    539533    assert( !tor->uploadedCur );
     
    570564        tr_torrent * it = NULL;
    571565        tr_torrent * last = NULL;
    572         while( ( it = tr_torrentNext( h, it ) ) )
     566        while( ( it = tr_torrentNext( session, it ) ) )
    573567            last = it;
    574568
    575569        if( !last )
    576             h->torrentList = tor;
     570            session->torrentList = tor;
    577571        else
    578572            last->next = tor;
    579         ++h->torrentCount;
    580     }
    581 
    582     tr_globalUnlock( h );
     573        ++session->torrentCount;
     574    }
     575
     576    tr_globalUnlock( session );
    583577
    584578    /* maybe save our own copy of the metainfo */
     
    595589    }
    596590
    597     tr_metainfoMigrate( h, &tor->info );
     591    tr_metainfoMigrate( session, &tor->info );
    598592
    599593    if( doStart )
     
    602596
    603597int
    604 tr_torrentParse( const tr_handle * handle,
    605                  const tr_ctor ctor,
    606                  tr_info *        setmeInfo )
     598tr_torrentParse( const tr_session  * session,
     599                 const tr_ctor     * ctor,
     600                 tr_info           * setmeInfo )
    607601{
    608602    int             err = 0;
     
    618612        return TR_EINVALID;
    619613
    620     err = tr_metainfoParse( handle, setmeInfo, metainfo );
     614    err = tr_metainfoParse( session, setmeInfo, metainfo );
    621615    doFree = !err && ( setmeInfo == &tmp );
    622616
     
    624618        err = TR_EINVALID;
    625619
    626     if( !err && tr_torrentExists( handle, setmeInfo->hash ) )
     620    if( !err && tr_torrentExists( session, setmeInfo->hash ) )
    627621        err = TR_EDUPLICATE;
    628622
     
    634628
    635629tr_torrent *
    636 tr_torrentNew( tr_handle *     handle,
    637                const tr_ctor * ctor,
    638                int *          setmeError )
     630tr_torrentNew( tr_session     * session,
     631               const tr_ctor  * ctor,
     632               int            * setmeError )
    639633{
    640634    int          err;
     
    642636    tr_torrent * tor = NULL;
    643637
    644     err = tr_torrentParse( handle, ctor, &tmpInfo );
     638    err = tr_torrentParse( session, ctor, &tmpInfo );
    645639    if( !err )
    646640    {
    647641        tor = tr_new0( tr_torrent, 1 );
    648642        tor->info = tmpInfo;
    649         torrentRealInit( handle, tor, ctor );
     643        torrentRealInit( session, tor, ctor );
    650644    }
    651645    else if( setmeError )
     
    10491043{
    10501044    tr_torrent * t;
    1051     tr_handle *  h = tor->session;
     1045    tr_session *  session = tor->session;
    10521046    tr_info *    inf = &tor->info;
    10531047
     
    10551049    assert( !tor->isRunning );
    10561050
    1057     tr_globalLock( h );
    1058 
    1059     tr_peerMgrRemoveTorrent( h->peerMgr, tor->info.hash );
     1051    tr_globalLock( session );
     1052
     1053    tr_peerMgrRemoveTorrent( session->peerMgr, tor->info.hash );
    10601054
    10611055    tr_cpClose( tor->completion );
     
    10721066    tr_free( tor->peer_id );
    10731067
    1074     if( tor == h->torrentList )
    1075         h->torrentList = tor->next;
    1076     else for( t = h->torrentList; t != NULL; t = t->next )
    1077         {
    1078             if( t->next == tor )
    1079             {
    1080                 t->next = tor->next;
    1081                 break;
    1082             }
     1068    if( tor == session->torrentList )
     1069        session->torrentList = tor->next;
     1070    else for( t = session->torrentList; t != NULL; t = t->next ) {
     1071        if( t->next == tor ) {
     1072            t->next = tor->next;
     1073            break;
    10831074        }
    1084 
    1085     assert( h->torrentCount >= 1 );
    1086     h->torrentCount--;
     1075    }
     1076
     1077    assert( session->torrentCount >= 1 );
     1078    session->torrentCount--;
    10871079
    10881080    tr_bandwidthFree( tor->bandwidth );
     
    10911083    tr_free( tor );
    10921084
    1093     tr_globalUnlock( h );
     1085    tr_globalUnlock( session );
    10941086}
    10951087
     
    12491241    if( tor )
    12501242    {
    1251         tr_handle * handle = tor->session;
    1252         tr_globalLock( handle );
     1243        tr_session * session = tor->session;
     1244        tr_globalLock( session );
    12531245
    12541246        tr_torrentClearCompletenessCallback( tor );
    1255         tr_runInEventThread( handle, closeTorrent, tor );
    1256 
    1257         tr_globalUnlock( handle );
     1247        tr_runInEventThread( session, closeTorrent, tor );
     1248
     1249        tr_globalUnlock( session );
    12581250    }
    12591251}
Note: See TracChangeset for help on using the changeset viewer.