Changeset 3220


Ignore:
Timestamp:
Sep 28, 2007, 2:51:34 PM (15 years ago)
Author:
charles
Message:

add a callback to notify clients when a torrent's state changes

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/internal.h

    r3170 r3220  
    158158    uint64_t                   activityDate;
    159159
    160     uint8_t                    hasChangedState;
     160    tr_torrent_status_func   * status_func;
     161    void                     * status_func_user_data;
    161162
    162163    unsigned int               runStatusToSaveIsSet : 1;
  • trunk/libtransmission/torrent.c

    r3201 r3220  
    305305
    306306    tor->handle   = h;
    307     tor->hasChangedState = -1;
    308307    tor->pexDisabled = 0;
    309308
     
    693692}
    694693
    695 static int tr_didStateChangeTo ( tr_torrent * tor, int status )
    696 {
    697     int ret;
    698 
    699     tr_torrentLock( tor );
    700     if (( ret = tor->hasChangedState == status ))
    701         tor->hasChangedState = -1;
    702     tr_torrentUnlock( tor );
    703 
    704     return ret;
    705 }
    706 
    707 int tr_getIncomplete( tr_torrent * tor )
    708 {
    709     return tr_didStateChangeTo( tor, TR_CP_INCOMPLETE );
    710 }
    711 int tr_getDone( tr_torrent * tor )
    712 {
    713     return tr_didStateChangeTo( tor, TR_CP_DONE );
    714 }
    715 int tr_getComplete( tr_torrent * tor )
    716 {
    717     return tr_didStateChangeTo( tor, TR_CP_COMPLETE );
    718 }
    719 
    720694void
    721695tr_manualUpdate( tr_torrent * tor )
     
    11181092}
    11191093
     1094/**
     1095***  Completeness
     1096**/
     1097
     1098static void
     1099fireStatusChange( tr_torrent * tor, cp_status_t status )
     1100{
     1101    assert( tor != NULL );
     1102    assert( status==TR_CP_INCOMPLETE || status==TR_CP_DONE || status==TR_CP_COMPLETE );
     1103
     1104    if( tor->status_func != NULL )
     1105        (tor->status_func)( tor, status, tor->status_func_user_data );
     1106}
     1107
     1108void
     1109tr_torrentSetStatusCallback( tr_torrent             * tor,
     1110                             tr_torrent_status_func   func,
     1111                             void                   * user_data )
     1112{
     1113    assert( tor != NULL );
     1114    tor->status_func = func;
     1115    tor->status_func_user_data = user_data;
     1116}
     1117
     1118void
     1119tr_torrentClearStatusCallback( tr_torrent * torrent )
     1120{
     1121    tr_torrentSetStatusCallback( torrent, NULL, NULL );
     1122}
     1123
    11201124void
    11211125tr_torrentRecheckCompleteness( tr_torrent * tor )
     
    11281132    if( cpStatus != tor->cpStatus ) {
    11291133        tor->cpStatus = cpStatus;
    1130         tor->hasChangedState = tor->cpStatus;  /* tell the client... */
     1134        fireStatusChange( tor, cpStatus );
    11311135        if( (cpStatus == TR_CP_COMPLETE) /* ...and if we're complete */
    11321136            && tor->downloadedCur ) {        /* and it just happened */
  • trunk/libtransmission/transmission.h

    r3201 r3220  
    444444void tr_torrentStop( tr_torrent * );
    445445
    446 /***********************************************************************
    447  * tr_getComplete, tr_getIncomplete and tr_getPartial
    448  ***********************************************************************
    449  * The first call after a torrent changed state returns 1. Returns 0
    450  * in other cases.
    451  **********************************************************************/
    452 int tr_getIncomplete( tr_torrent * tor );
    453 int tr_getDone( tr_torrent * tor );
    454 int tr_getComplete( tr_torrent * tor );
    455 
     446
     447/**
     448***  Register to be notified whenever a torrent's state changes.
     449**/
     450
     451typedef enum
     452{
     453    TR_CP_INCOMPLETE,   /* doesn't have all the desired pieces */
     454    TR_CP_DONE,         /* has all the pieces but the DND ones */
     455    TR_CP_COMPLETE      /* has every piece */
     456}
     457cp_status_t;
     458
     459typedef void (tr_torrent_status_func)(tr_torrent   * torrent,
     460                                      cp_status_t    status,
     461                                      void         * user_data );
     462
     463void tr_torrentSetStatusCallback( tr_torrent             * torrent,
     464                                  tr_torrent_status_func   func,
     465                                  void                   * user_data );
     466
     467void tr_torrentClearStatusCallback( tr_torrent * torrent );
    456468
    457469/**
     
    611623#define TR_STATUS_INACTIVE \
    612624    (TR_STATUS_STOPPING|TR_STATUS_STOPPED)
    613 
    614 typedef enum
    615 {
    616     TR_CP_INCOMPLETE,   /* doesn't have all the desired pieces */
    617     TR_CP_DONE,         /* has all the pieces but the DND ones */
    618     TR_CP_COMPLETE      /* has every piece */
    619 }
    620 cp_status_t;
    621625
    622626/***********************************************************************
Note: See TracChangeset for help on using the changeset viewer.