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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.