Changeset 13913


Ignore:
Timestamp:
Jan 31, 2013, 9:58:25 PM (8 years ago)
Author:
jordan
Message:

(libT) change the API signature for tr_torrentVerify() s.t. client code can be notified when the verify is finished

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/cli.c

    r13842 r13913  
    329329    {
    330330      verify = false;
    331       tr_torrentVerify (tor);
     331      tr_torrentVerify (tor, NULL, NULL);
    332332    }
    333333
  • trunk/gtk/open-dialog.c

    r13683 r13913  
    164164        gtk_widget_set_sensitive (o->file_list, tr_torrentHasMetadata (o->tor));
    165165        gtr_file_list_set_torrent (o->file_list, tr_torrentId (o->tor));
    166         tr_torrentVerify (o->tor);
     166        tr_torrentVerify (o->tor, NULL, NULL);
    167167    }
    168168}
  • trunk/libtransmission/fail.sh

    r13909 r13913  
    44  count=$((count+1))
    55  echo starting run number $count
    6   make check
     6  ./rename-test
    77  err=$?
    88done
  • trunk/libtransmission/libtransmission-test.c

    r13908 r13913  
    55#include "platform.h" /* TR_PATH_DELIMETER */
    66#include "torrent.h"
     7#include "trevent.h"
    78#include "libtransmission-test.h"
    89
     
    324325}
    325326
    326 #define verify_and_block_until_done(tor) \
    327   do { \
    328     do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
    329     tr_torrentVerify (tor); \
    330     do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
    331   } while (0)
    332 
    333 
    334327void
    335328libtransmission_test_zero_torrent_populate (tr_torrent * tor, bool complete)
     
    369362
    370363  sync ();
    371   verify_and_block_until_done (tor);
     364  libttest_blockingTorrentVerify (tor);
    372365
    373366  if (complete)
     
    376369    assert (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
    377370}
     371
     372/***
     373****
     374***/
     375
     376static void
     377onVerifyDone (tr_torrent * tor UNUSED, bool aborted UNUSED, void * done)
     378{
     379  *(bool*)done = true;
     380}
     381
     382void
     383libttest_blockingTorrentVerify (tr_torrent * tor)
     384{
     385  bool done = false;
     386
     387  assert (session != NULL);
     388  assert (!tr_amInEventThread (session));
     389
     390  tr_torrentVerify (tor, onVerifyDone, &done);
     391  while (!done)
     392    tr_wait_msec (10);
     393}
  • trunk/libtransmission/libtransmission-test.h

    r13879 r13913  
    8282tr_torrent * libtransmission_test_zero_torrent_init (void);
    8383
     84void         libttest_blockingTorrentVerify (tr_torrent * tor);
     85
    8486
    8587
  • trunk/libtransmission/move-test.c

    r13909 r13913  
    2424****
    2525***/
    26 
    27 #define verify_and_block_until_done(tor) \
    28   do { \
    29     do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
    30     tr_torrentVerify (tor); \
    31     do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
    32   } while (0)
    3326
    3427static void
     
    123116  }
    124117
    125   verify_and_block_until_done (tor);
     118  libttest_blockingTorrentVerify (tor);
    126119  check_int_eq (0, tr_torrentStat(tor)->leftUntilDone);
    127120
  • trunk/libtransmission/rename-test.c

    r13911 r13913  
    2020****
    2121***/
    22 
    23 #define verify_and_block_until_done(tor) \
    24   do { \
    25     do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
    26     tr_torrentVerify (tor); \
    27     do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
    28   } while (0)
    2922
    3023#define check_have_none(tor, totalSize) \
     
    173166
    174167  /* sanity check the (empty) stats */
    175   verify_and_block_until_done (tor);
     168  libttest_blockingTorrentVerify (tor);
    176169  check_have_none (tor, totalSize);
    177170
     
    179172
    180173  /* sanity check the stats again, now that we've added the file */
    181   verify_and_block_until_done (tor);
     174  libttest_blockingTorrentVerify (tor);
    182175  st = tr_torrentStat (tor);
    183176  check_int_eq (TR_STATUS_STOPPED, st->activity);
     
    329322
    330323  /* sanity check the (empty) stats */
    331   verify_and_block_until_done (tor);
     324  libttest_blockingTorrentVerify (tor);
    332325  check_have_none (tor, totalSize);
    333326
     
    336329
    337330  /* sanity check the (full) stats */
    338   verify_and_block_until_done (tor);
     331  libttest_blockingTorrentVerify (tor);
    339332  st = tr_torrentStat (tor);
    340333  check_int_eq (TR_STATUS_STOPPED, st->activity);
     
    415408  tr_free (str);
    416409  sync ();
    417   verify_and_block_until_done (tor);
     410  libttest_blockingTorrentVerify (tor);
    418411  testFileExistsAndConsistsOfThisString (tor, 0, expected_contents[0]);
    419412  for (i=1; i<=2; ++i)
  • trunk/libtransmission/rpcimpl.c

    r13868 r13913  
    396396    {
    397397        tr_torrent * tor = torrents[i];
    398         tr_torrentVerify (tor);
     398        tr_torrentVerify (tor, NULL, NULL);
    399399        notify (session, TR_RPC_TORRENT_CHANGED, tor);
    400400    }
  • trunk/libtransmission/torrent.c

    r13909 r13913  
    919919    {
    920920        tor->startAfterVerify = doStart;
    921         tr_torrentVerify (tor);
     921        tr_torrentVerify (tor, NULL, NULL);
    922922    }
    923923    else if (doStart)
     
    16831683}
    16841684
     1685struct verify_data
     1686{
     1687  bool aborted;
     1688  tr_torrent * tor;
     1689  tr_verify_done_func callback_func;
     1690  void * callback_data;
     1691};
     1692
    16851693static void
    1686 torrentRecheckDoneImpl (void * vtor)
    1687 {
    1688     tr_torrent * tor = vtor;
    1689     assert (tr_isTorrent (tor));
    1690 
     1694onVerifyDoneThreadFunc (void * vdata)
     1695{
     1696  struct verify_data * data = vdata;
     1697  tr_torrent * tor = data->tor;
     1698
     1699  if (!data->aborted)
    16911700    tr_torrentRecheckCompleteness (tor);
    16921701
    1693     if (tor->startAfterVerify) {
    1694         tor->startAfterVerify = false;
    1695         torrentStart (tor, false);
    1696     }
     1702  if (data->callback_func != NULL)
     1703    (*data->callback_func)(tor, data->aborted, data->callback_data);
     1704
     1705  if (!data->aborted && tor->startAfterVerify)
     1706    {
     1707      tor->startAfterVerify = false;
     1708      torrentStart (tor, false);
     1709    }
     1710
     1711  tr_free (data);
    16971712}
    16981713
    16991714static void
    1700 torrentRecheckDoneCB (tr_torrent * tor)
    1701 {
    1702     assert (tr_isTorrent (tor));
    1703 
    1704     tr_runInEventThread (tor->session, torrentRecheckDoneImpl, tor);
     1715onVerifyDone (tr_torrent * tor, bool aborted, void * vdata)
     1716{
     1717  struct verify_data * data = vdata;
     1718  assert (data->tor == tor);
     1719  data->aborted = aborted;
     1720  tr_runInEventThread (tor->session, onVerifyDoneThreadFunc, data);
    17051721}
    17061722
    17071723static void
    1708 verifyTorrent (void * vtor)
    1709 {
    1710     bool startAfter;
    1711     tr_torrent * tor = vtor;
    1712 
    1713     tr_sessionLock (tor->session);
    1714 
    1715     /* if the torrent's already being verified, stop it */
    1716     tr_verifyRemove (tor);
    1717 
    1718     startAfter = (tor->isRunning || tor->startAfterVerify) && !tor->isStopping;
    1719 
    1720     if (tor->isRunning)
    1721         tr_torrentStop (tor);
    1722 
    1723     tor->startAfterVerify = startAfter;
    1724 
    1725     if (setLocalErrorIfFilesDisappeared (tor))
    1726         tor->startAfterVerify = false;
    1727     else
    1728         tr_verifyAdd (tor, torrentRecheckDoneCB);
    1729 
    1730     tr_sessionUnlock (tor->session);
    1731 }
    1732 
    1733 void
    1734 tr_torrentVerify (tr_torrent * tor)
    1735 {
    1736   if (tr_isTorrent (tor))
    1737     tr_runInEventThread (tor->session, verifyTorrent, tor);
     1724verifyTorrent (void * vdata)
     1725{
     1726  bool startAfter;
     1727  struct verify_data * data = vdata;
     1728  tr_torrent * tor = data->tor;
     1729  tr_sessionLock (tor->session);
     1730
     1731  /* if the torrent's already being verified, stop it */
     1732  tr_verifyRemove (tor);
     1733
     1734  startAfter = (tor->isRunning || tor->startAfterVerify) && !tor->isStopping;
     1735  if (tor->isRunning)
     1736    tr_torrentStop (tor);
     1737  tor->startAfterVerify = startAfter;
     1738
     1739  if (setLocalErrorIfFilesDisappeared (tor))
     1740    tor->startAfterVerify = false;
     1741  else
     1742    tr_verifyAdd (tor, onVerifyDone, data);
     1743
     1744  tr_sessionUnlock (tor->session);
     1745}
     1746
     1747void
     1748tr_torrentVerify (tr_torrent           * tor,
     1749                  tr_verify_done_func    callback_func,
     1750                  void                 * callback_data)
     1751{
     1752  struct verify_data * data;
     1753
     1754  data = tr_new (struct verify_data, 1);
     1755  data->tor = tor;
     1756  data->aborted = false;
     1757  data->callback_func = callback_func;
     1758  data->callback_data = callback_data;
     1759  tr_runInEventThread (tor->session, verifyTorrent, data);
    17381760}
    17391761
  • trunk/libtransmission/transmission.h

    r13868 r13913  
    14401440
    14411441typedef void (tr_torrent_metadata_func)(tr_torrent  * torrent,
    1442                                            void        * user_data);
     1442                                        void        * user_data);
    14431443/**
    14441444 * Register to be notified whenever a torrent changes from
     
    17231723                               int                 size);
    17241724
    1725 void tr_torrentVerify (tr_torrent * torrent);
     1725/**
     1726 * Callback function invoked when a torrent finishes being verified.
     1727 *
     1728 * @param torrent the torrent that was verified
     1729 * @param aborted true if the verify ended prematurely for some reason,
     1730 *                such as tr_torrentStop() or tr_torrentSetLocation()
     1731 *                being called during verification.
     1732 * @param callback_data the user-defined pointer from tr_torrentVerify()
     1733 */
     1734typedef void (*tr_verify_done_func)(tr_torrent  * torrent,
     1735                                    bool          aborted,
     1736                                    void        * user_data);
     1737
     1738/**
     1739 * Queue a torrent for verification.
     1740 *
     1741 * If callback_func is non-NULL, it will be called from the libtransmission
     1742 * thread after the torrent's completness state is updated after the
     1743 * file verification pass.
     1744 */
     1745void tr_torrentVerify (tr_torrent           * torrent,
     1746                       tr_verify_done_func    callback_func_or_NULL,
     1747                       void                 * callback_data_or_NULL);
    17261748
    17271749/***********************************************************************
  • trunk/libtransmission/verify.c

    r13868 r13913  
    174174struct verify_node
    175175{
    176   tr_torrent *         torrent;
    177   tr_verify_done_cb    verify_done_cb;
    178   uint64_t             current_size;
     176  tr_torrent          * torrent;
     177  tr_verify_done_func   callback_func;
     178  void                * callback_data;
     179  uint64_t              current_size;
    179180};
    180 
    181 static void
    182 fireCheckDone (tr_torrent * tor, tr_verify_done_cb verify_done_cb)
    183 {
    184   assert (tr_isTorrent (tor));
    185 
    186   if (verify_done_cb)
    187     verify_done_cb (tor);
    188 }
    189181
    190182static struct verify_node currentNode;
     
    234226      assert (tr_isTorrent (tor));
    235227
    236       if (!stopCurrent)
    237         {
    238           if (changed)
    239             tr_torrentSetDirty (tor);
    240           fireCheckDone (tor, currentNode.verify_done_cb);
    241         }
     228      if (!stopCurrent && changed)
     229        tr_torrentSetDirty (tor);
     230
     231      if (currentNode.callback_func)
     232        (*currentNode.callback_func)(tor, stopCurrent, currentNode.callback_data);
    242233    }
    243234
     
    267258
    268259void
    269 tr_verifyAdd (tr_torrent * tor, tr_verify_done_cb verify_done_cb)
     260tr_verifyAdd (tr_torrent           * tor,
     261              tr_verify_done_func    callback_func,
     262              void                 * callback_data)
    270263{
    271264  struct verify_node * node;
     
    276269  node = tr_new (struct verify_node, 1);
    277270  node->torrent = tor;
    278   node->verify_done_cb = verify_done_cb;
     271  node->callback_func = callback_func;
     272  node->callback_data = callback_data;
    279273  node->current_size = tr_torrentGetCurrentSizeOnDisk (tor);
    280274
  • trunk/libtransmission/verify.h

    r13625 r13913  
    2323 */
    2424
    25 typedef void (*tr_verify_done_cb)(tr_torrent * tor);
    26 
    27 void tr_verifyAdd (tr_torrent *      tor,
    28                    tr_verify_done_cb recheck_done_cb);
     25void tr_verifyAdd (tr_torrent           * tor,
     26                   tr_verify_done_func    callback_func,
     27                   void                 * callback_user_data);
    2928
    3029void tr_verifyRemove (tr_torrent * tor);
  • trunk/macosx/Torrent.m

    r13872 r13913  
    407407- (void) resetCache
    408408{
    409     tr_torrentVerify(fHandle);
     409    tr_torrentVerify(fHandle, NULL, NULL);
    410410    [self update];
    411411}
Note: See TracChangeset for help on using the changeset viewer.