Added processEvents() call to TorrentManager and update clients to use it including adding a seed method to the FetchStratedegyManager to seed data.

Change-Id: I98e4c794c98ca35765df968c2cf7c4fe1e622595
diff --git a/src/fetching-strategy-manager.hpp b/src/fetching-strategy-manager.hpp
index 53de939..a34afa0 100644
--- a/src/fetching-strategy-manager.hpp
+++ b/src/fetching-strategy-manager.hpp
@@ -22,8 +22,9 @@
 #ifndef FETCHING_STRATEGY_MANAGER_HPP
 #define FETCHING_STRATEGY_MANAGER_HPP
 
-#include <ndn-cxx/interest.hpp>
 #include <ndn-cxx/data.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/util/time.hpp>
 
 namespace ndn {
 namespace ntorrent {
@@ -66,6 +67,12 @@
     struct status {
       double downloadedPercent;
     };
+    /**
+     * @brief Seed downloaded data for the specified timeout.
+     * By default this will go into an infinite loop.
+     */
+    virtual void
+    seed(const time::milliseconds& timeout = time::milliseconds::zero()) const = 0;
 
   private:
     /**
diff --git a/src/sequential-data-fetcher.cpp b/src/sequential-data-fetcher.cpp
index 971b59f..5873374 100644
--- a/src/sequential-data-fetcher.cpp
+++ b/src/sequential-data-fetcher.cpp
@@ -80,6 +80,7 @@
                               ".appdata/manifests/",
                               bind(&SequentialDataFetcher::onManifestReceived, this, _1),
                               bind(&SequentialDataFetcher::onDataRetrievalFailure, this, _1, _2));
+    m_manager->processEvents();
   }
 }
 
@@ -90,6 +91,7 @@
     m_manager->download_data_packet(*i,
                               bind(&SequentialDataFetcher::onDataPacketReceived, this, _1),
                               bind(&SequentialDataFetcher::onDataRetrievalFailure, this, _1, _2));
+    m_manager->processEvents();
   }
 }
 
@@ -133,7 +135,7 @@
                                               const std::string& errorCode)
 {
   std::cerr << "Data Retrieval Failed: " << interest.getName() << std::endl;
-  
+
   // Data retrieval failure
   uint32_t nameType = IoUtil::findType(interest.getName());
   if (nameType == IoUtil::TORRENT_FILE) {
diff --git a/src/sequential-data-fetcher.hpp b/src/sequential-data-fetcher.hpp
index ea6ce90..8687d9c 100644
--- a/src/sequential-data-fetcher.hpp
+++ b/src/sequential-data-fetcher.hpp
@@ -70,6 +70,9 @@
     void
     resume();
 
+    void
+    seed(const time::milliseconds& timeout = time::milliseconds::zero()) const;
+
   protected:
     std::vector<ndn::Name>
     downloadTorrentFile();
@@ -98,6 +101,13 @@
     shared_ptr<TorrentManager> m_manager;
 };
 
+inline
+void
+SequentialDataFetcher::seed(const time::milliseconds& timeout) const
+{
+  m_manager->processEvents(timeout);
+}
+
 } // namespace ntorrent
 } // namespace ndn
 
diff --git a/src/torrent-manager.hpp b/src/torrent-manager.hpp
index 17e59db..4a8beb4 100644
--- a/src/torrent-manager.hpp
+++ b/src/torrent-manager.hpp
@@ -147,8 +147,15 @@
   void
   seed(const Data& data);
 
+  /**
+   * @brief Process any data to receive or call timeout callbacks and update prefix list (if needed)
+   * By default only process pending events and return immediately, optionally specify a timeout.
+   */
+  void
+  processEvents(const time::milliseconds& timeout = time::milliseconds(-1));
+
  protected:
-  /*
+  /**
    * \brief Write @p packet composed of torrent date to disk.
    * @param packet The data packet to be written to the disk
    * Write the Data packet to disk, return 'true' if data successfully written to disk 'false'
@@ -359,6 +366,13 @@
   m_stats_table_iter = m_statsTable.begin();
 }
 
+inline
+void
+TorrentManager::processEvents(const time::milliseconds& timeout)
+{
+  m_face->processEvents(timeout);
+}
+
 }  // end ntorrent
 }  // end ndn
 
diff --git a/tests/unit-tests/torrent-manager.t.cpp b/tests/unit-tests/torrent-manager.t.cpp
index cf009f1..d0f5110 100644
--- a/tests/unit-tests/torrent-manager.t.cpp
+++ b/tests/unit-tests/torrent-manager.t.cpp
@@ -13,7 +13,7 @@
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received copies of the GNU General Public License and GNU Lesser
-* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
+* General Public License along with nTorrent, e.g., in COPYING.md file. SoIf not, see
 * <http://www.gnu.org/licenses/>.
 *
 * See AUTHORS for complete list of nTorrent authors and contributors.
@@ -1061,7 +1061,7 @@
                             }));
       advanceClocks(time::milliseconds(1), 40);
       face->receive(interest);
-      face->processEvents(time::milliseconds(-1));
+      manager.processEvents();
       // check that one piece of data is sent, and it is what was expected
       BOOST_CHECK_EQUAL(++nData, face->sentData.size());
       face->receive(face->sentData[nData - 1]);
@@ -1083,7 +1083,7 @@
                              }));
       advanceClocks(time::milliseconds(1), 40);
       face->receive(interest);
-      face->processEvents(time::milliseconds(-1));
+      manager.processEvents();
       // check that one piece of data is sent, and it is what was expected
       BOOST_CHECK_EQUAL(++nData, face->sentData.size());
       face->receive(face->sentData[nData - 1]);
@@ -1091,7 +1091,7 @@
     // request all the data packets
     for (const auto& file : fileData) {
       for (const auto& data : file) {
-      Interest interest(data. getFullName(), time::milliseconds(50));
+      Interest interest(data.getFullName(), time::milliseconds(50));
       face->expressInterest(interest,
                             [&data](const Interest& i, const Data& d) {
                               BOOST_CHECK(data == d);
@@ -1104,7 +1104,7 @@
                              }));
         advanceClocks(time::milliseconds(1), 40);
         face->receive(interest);
-        face->processEvents(time::milliseconds(-1));
+        manager.processEvents();
         // check that one piece of data is sent, and it is what was expected
         BOOST_CHECK_EQUAL(++nData, face->sentData.size());
         face->receive(face->sentData[nData - 1]);
@@ -1188,7 +1188,7 @@
                           }));
     advanceClocks(time::milliseconds(1), 40);
     face->receive(interest);
-    face->processEvents(time::milliseconds(-1));
+    manager.processEvents();
     // check that one piece of data is sent, and it is what was expected
     BOOST_CHECK_EQUAL(++nData, face->sentData.size());
     face->receive(face->sentData[nData - 1]);