Changeset 138


Ignore:
Timestamp:
Mar 9, 2006, 1:36:29 AM (16 years ago)
Author:
titer
Message:

Adds an error feedback for tr_torrentInit.
Adds tr_torrentInfo along with tr_torrentStat.
Removed now unused tr_setFinished.

Location:
branches/new_api
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/new_api/libtransmission/transmission.c

    r137 r138  
    167167 * to fill it.
    168168 **********************************************************************/
    169 tr_torrent_t * tr_torrentInit( tr_handle_t * h, const char * path )
     169tr_torrent_t * tr_torrentInit( tr_handle_t * h, const char * path,
     170                               int * error )
    170171{
    171172    tr_torrent_t  * tor, * tor_tmp;
     
    180181    if( tr_metainfoParse( inf, path ) )
    181182    {
     183        *error = TR_EINVALID;
    182184        free( tor );
    183185        return NULL;
     
    190192                     SHA_DIGEST_LENGTH ) )
    191193        {
    192             tr_err( "Torrent already open" );
     194            *error = TR_EDUPLICATE;
    193195            free( tor );
    194196            return NULL;
     
    253255}
    254256
     257tr_info_t * tr_torrentInfo( tr_torrent_t * tor )
     258{
     259    return &tor->info;
     260}
     261
    255262/***********************************************************************
    256263 * tr_torrentScrape
     
    329336int tr_getFinished( tr_torrent_t * tor )
    330337{
    331         return tor->finished;
    332 }
    333 void tr_setFinished( tr_torrent_t * tor, int val)
    334 {
    335         tor->finished = val;
     338    if( tor->finished )
     339    {
     340        tor->finished = 0;
     341        return 1;
     342    }
     343    return 0;
    336344}
    337345
     
    355363    tr_lockLock( &tor->lock );
    356364
    357     memcpy( &s->info, &tor->info, sizeof( tr_info_t ) );
    358365    s->status = tor->status;
    359366    memcpy( s->error, tor->error, sizeof( s->error ) );
  • branches/new_api/libtransmission/transmission.h

    r137 r138  
    4747 **********************************************************************/
    4848typedef struct tr_handle_s tr_handle_t;
    49 
    5049tr_handle_t * tr_init();
    5150
     
    7574
    7675/***********************************************************************
     76 * tr_torrentCount
     77 ***********************************************************************
     78 * Returns the count of open torrents
     79 **********************************************************************/
     80int tr_torrentCount( tr_handle_t * h );
     81
     82/***********************************************************************
    7783 * tr_torrentRates
    7884 ***********************************************************************
     
    8086 **********************************************************************/
    8187void tr_torrentRates( tr_handle_t *, float *, float * );
     88
     89/***********************************************************************
     90 * tr_close
     91 ***********************************************************************
     92 * Frees memory allocated by tr_init.
     93 **********************************************************************/
     94void tr_close( tr_handle_t * );
    8295
    8396/***********************************************************************
     
    8699 * Opens and parses torrent file at 'path'. If the file exists and is a
    87100 * valid torrent file, returns an handle and adds it to the list of
    88  * torrents (but doesn't start it). Returns NULL otherwise.
     101 * torrents (but doesn't start it). Returns NULL and sets error
     102 * otherwise.
    89103 **********************************************************************/
    90104typedef struct tr_torrent_s tr_torrent_t;
    91 
    92 tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path );
     105#define TR_SUCCESS      0
     106#define TR_EINVALID     1
     107#define TR_EUNSUPPORTED 2
     108#define TR_EDUPLICATE   3
     109#define TR_EOTHER       666
     110tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
     111                               int * error );
     112
     113typedef struct tr_info_s tr_info_t;
     114tr_info_t * tr_torrentInfo( tr_torrent_t * );
    93115
    94116/***********************************************************************
     
    129151 * tr_getFinished
    130152 ***********************************************************************
    131  * Tests to see if torrent is finished
     153 * The first call after a torrent is completed returns 1. Returns 0
     154 * in other cases.
    132155 **********************************************************************/
    133156int tr_getFinished( tr_torrent_t * );
    134157
    135158/***********************************************************************
    136  * tr_setFinished
    137  ***********************************************************************
    138  * Sets the boolean value finished in the torrent back to false
    139  **********************************************************************/
    140 void tr_setFinished( tr_torrent_t *, int );
    141 
    142 
    143 
    144 /***********************************************************************
    145159 * tr_torrentStat
    146160 ***********************************************************************
    147  * Allocates an array of tr_stat_t structures, containing information
    148  * about the current status of all open torrents (see the contents
    149  * of tr_stat_s below). Returns the count of open torrents and sets
    150  * (*s) to the address of the array, or NULL if no torrent is open.
    151  * In the former case, the array belongs to the caller who is
    152  * responsible of freeing it.
    153  * The interface should call this function every 0.5 second or so in
    154  * order to update itself.
     161 * Returns a pointer to an tr_stat_t structure with updated information
     162 * on the torrent. The structure belongs to libtransmission (do not
     163 * free it) and is guaranteed to be unchanged until the next call to
     164 * tr_torrentStat.
     165 * The interface should call this function every second or so in order
     166 * to update itself.
    155167 **********************************************************************/
    156168typedef struct tr_stat_s tr_stat_t;
    157 
    158 int tr_torrentCount( tr_handle_t * h );
    159169tr_stat_t * tr_torrentStat( tr_torrent_t * );
    160170
     
    166176 **********************************************************************/
    167177void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
    168 
    169 /***********************************************************************
    170  * tr_close
    171  ***********************************************************************
    172  * Frees memory allocated by tr_init.
    173  **********************************************************************/
    174 void tr_close( tr_handle_t * );
    175 
    176178
    177179/***********************************************************************
     
    185187tr_file_t;
    186188
    187 typedef struct tr_info_s
     189struct tr_info_s
    188190{
    189191    /* Path to torrent */
     
    208210    int         fileCount;
    209211    tr_file_t * files;
    210 }
    211 tr_info_t;
     212};
    212213
    213214struct tr_stat_s
    214215{
    215     tr_info_t   info;
    216 
    217216#define TR_STATUS_CHECK    0x001 /* Checking files */
    218217#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
  • branches/new_api/transmissioncli.c

    r137 r138  
    6060int main( int argc, char ** argv )
    6161{
    62     int i;
     62    int i, error;
    6363    tr_handle_t  * h;
    6464    tr_torrent_t * tor;
     
    106106
    107107    /* Open and parse torrent file */
    108     if( !( tor = tr_torrentInit( h, torrentPath ) ) )
     108    if( !( tor = tr_torrentInit( h, torrentPath, &error ) ) )
    109109    {
    110110        printf( "Failed opening torrent file `%s'\n", torrentPath );
     
    114114    if( showInfo )
    115115    {
    116         tr_info_t * info;
    117 
    118         s = tr_torrentStat( tor );
    119         info = &s->info;
     116        tr_info_t * info = tr_torrentInfo( tor );
    120117
    121118        /* Print torrent info (quite à la btshowmetainfo) */
     
    212209        if( tr_getFinished( tor ) )
    213210        {
    214             tr_setFinished( tor, 0 );
    215211            result = system(finishCall);
    216212        }
Note: See TracChangeset for help on using the changeset viewer.