fetch: Switch code to use ndn-cxx

This commit also moves code to ndn::chronoshare namespace and changes
logging to show file and line number of the logging statement.

Change-Id: I075320644166cea9d5d3ef65bb26a2cabfd4dc5a
diff --git a/src/fetcher.hpp b/src/fetcher.hpp
index c1da2a3..40d5258 100644
--- a/src/fetcher.hpp
+++ b/src/fetcher.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
  *
  * This file is part of ChronoShare, a decentralized file sharing application over NDN.
  *
@@ -18,47 +18,46 @@
  * See AUTHORS.md for complete list of ChronoShare authors and contributors.
  */
 
-#ifndef FETCHER_H
-#define FETCHER_H
+#ifndef CHRONOSHARE_SRC_FETCHER_HPP
+#define CHRONOSHARE_SRC_FETCHER_HPP
 
-#include "ccnx-name.h"
-#include "ccnx-wrapper.h"
+#include "core/chronoshare-common.hpp"
 
-#include "executor.h"
-#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <ndn-cxx/face.hpp>
+
+#include <set>
+#include <thread>
+#include <mutex>
 #include <boost/intrusive/list.hpp>
-#include <set>
 
-#include <set>
+namespace ndn {
+namespace chronoshare {
 
 class FetchManager;
 
 class Fetcher
 {
 public:
-  typedef boost::function<void(Ccnx::Name& deviceName, Ccnx::Name& baseName, uint64_t seq, Ccnx::PcoPtr pco)>
-    SegmentCallback;
-  typedef boost::function<void(Ccnx::Name& deviceName, Ccnx::Name& baseName)> FinishCallback;
-  typedef boost::function<void(Fetcher&, const Ccnx::Name& deviceName, const Ccnx::Name& baseName)>
-    OnFetchCompleteCallback;
-  typedef boost::function<void(Fetcher&)> OnFetchFailedCallback;
+  typedef std::function<void(Name& deviceName, Name& baseName, uint64_t seq, shared_ptr<Data> data)> SegmentCallback;
+  typedef std::function<void(Name& deviceName, Name& baseName)> FinishCallback;
+  typedef std::function<void(Fetcher&, const Name& deviceName, const Name& baseName)> OnFetchCompleteCallback;
+  typedef std::function<void(Fetcher&)> OnFetchFailedCallback;
 
-  Fetcher(Ccnx::CcnxWrapperPtr ccnx, ExecutorPtr executor,
+  Fetcher(Face& face,
           const SegmentCallback& segmentCallback, // callback passed by caller of FetchManager
           const FinishCallback& finishCallback,   // callback passed by caller of FetchManager
-          OnFetchCompleteCallback onFetchComplete,
-          OnFetchFailedCallback onFetchFailed, // callbacks provided by FetchManager
-          const Ccnx::Name& deviceName, const Ccnx::Name& name, int64_t minSeqNo, int64_t maxSeqNo,
-          boost::posix_time::time_duration timeout =
-            boost::posix_time::seconds(30), // this time is not precise, but sets min bound
-                                            // actual time depends on how fast Interests timeout
-          const Ccnx::Name& forwardingHint = Ccnx::Name());
+          const OnFetchCompleteCallback& onFetchComplete,
+          const OnFetchFailedCallback& onFetchFailed, // callbacks provided by FetchManager
+          const Name& deviceName, const Name& name, int64_t minSeqNo, int64_t maxSeqNo,
+          time::milliseconds timeout = time::seconds(30), // this time is not precise, but sets min bound
+                                                          // actual time depends on how fast Interests timeout
+          const Name& forwardingHint = Name());
   virtual ~Fetcher();
 
-  inline bool
+  bool
   IsActive() const;
 
-  inline bool
+  bool
   IsTimedWait() const
   {
     return m_timedwait;
@@ -68,46 +67,46 @@
   RestartPipeline();
 
   void
-  SetForwardingHint(const Ccnx::Name& forwardingHint);
+  SetForwardingHint(const Name& forwardingHint);
 
-  const Ccnx::Name&
+  const Name&
   GetForwardingHint() const
   {
     return m_forwardingHint;
   }
 
-  const Ccnx::Name&
+  const Name&
   GetName() const
   {
     return m_name;
   }
 
-  const Ccnx::Name&
+  const Name&
   GetDeviceName() const
   {
     return m_deviceName;
   }
 
-  double
+  time::seconds
   GetRetryPause() const
   {
     return m_retryPause;
   }
 
   void
-  SetRetryPause(double pause)
+  SetRetryPause(time::seconds pause)
   {
     m_retryPause = pause;
   }
 
-  boost::posix_time::ptime
+  const time::steady_clock::TimePoint&
   GetNextScheduledRetry() const
   {
     return m_nextScheduledRetry;
   }
 
   void
-  SetNextScheduledRetry(boost::posix_time::ptime nextScheduledRetry)
+  SetNextScheduledRetry(const time::steady_clock::TimePoint& nextScheduledRetry)
   {
     m_nextScheduledRetry = nextScheduledRetry;
   }
@@ -117,24 +116,16 @@
   FillPipeline();
 
   void
-  OnData(uint64_t seqno, const Ccnx::Name& name, Ccnx::PcoPtr data);
+  OnData(uint64_t seqno, const Interest& interest, Data& data);
 
   void
-  OnData_Execute(uint64_t seqno, Ccnx::Name name, Ccnx::PcoPtr data);
-
-  void
-  OnTimeout(uint64_t seqno, const Ccnx::Name& name, const Ccnx::Closure& closure,
-            Ccnx::Selectors selectors);
-
-  void
-  OnTimeout_Execute(uint64_t seqno, Ccnx::Name name, Ccnx::Closure closure,
-                    Ccnx::Selectors selectors);
+  OnTimeout(uint64_t seqno, const Interest& interest);
 
 public:
   boost::intrusive::list_member_hook<> m_managerListHook;
 
 private:
-  Ndnx::NdnxWrapperPtr m_ndnx;
+  Face& m_face;
 
   SegmentCallback m_segmentCallback;
   OnFetchCompleteCallback m_onFetchComplete;
@@ -145,55 +136,47 @@
   bool m_active;
   bool m_timedwait;
 
-  Ndnx::Name m_name;
-  Ndnx::Name m_deviceName;
-  Ndnx::Name m_forwardingHint;
+  Name m_name;
+  Name m_deviceName;
+  Name m_forwardingHint;
 
-  boost::posix_time::time_duration m_maximumNoActivityPeriod;
+  time::milliseconds m_maximumNoActivityPeriod;
 
   int64_t m_minSendSeqNo;
   int64_t m_maxInOrderRecvSeqNo;
   std::set<int64_t> m_outOfOrderRecvSeqNo;
   std::set<int64_t> m_inActivePipeline;
 
-  int64_t m_minSeqNo;
+  // int64_t m_minSeqNo;
   int64_t m_maxSeqNo;
 
   uint32_t m_pipeline;
   uint32_t m_activePipeline;
-  double m_rto;
-  double m_maxRto;
+  // double m_rto;
+  // double m_maxRto;
   bool m_slowStart;
   uint32_t m_threshold;
   uint32_t m_roundCount;
 
-  boost::posix_time::ptime m_lastPositiveActivity;
+  time::steady_clock::TimePoint m_lastPositiveActivity;
 
-  double m_retryPause; // pause to stop trying to fetch (for fetch-manager)
-  boost::posix_time::ptime m_nextScheduledRetry;
+  time::seconds m_retryPause; // pause to stop trying to fetch(for fetch-manager)
+  time::steady_clock::TimePoint m_nextScheduledRetry;
 
-  ExecutorPtr m_executor; // to serialize FillPipeline events
+  std::mutex m_seqNoMutex;
 
-  boost::mutex m_seqNoMutex;
-  boost::mutex m_rtoMutex;
-  boost::mutex m_pipelineMutex;
+  boost::asio::io_service& m_ioService;
 };
 
-typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
+typedef shared_ptr<Fetcher> FetcherPtr;
 
-namespace Error {
-struct Fetcher : virtual boost::exception, virtual std::exception
-{
-};
-}
-
-typedef boost::shared_ptr<Fetcher> FetcherPtr;
-
-bool
+inline bool
 Fetcher::IsActive() const
 {
   return m_active;
 }
 
+} // namespace chronoshare
+} // namespace ndn
 
-#endif // FETCHER_H
+#endif // CHRONOSHARE_SRC_FETCHER_HPP