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/fetch-task-db.cpp b/src/fetch-task-db.cpp
index 912f063..e753f95 100644
--- a/src/fetch-task-db.cpp
+++ b/src/fetch-task-db.cpp
@@ -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.
  *
@@ -17,15 +17,16 @@
  *
  * See AUTHORS.md for complete list of ChronoShare authors and contributors.
  */
+
 #include "fetch-task-db.hpp"
 #include "db-helper.hpp"
 
-using namespace std;
-using namespace boost;
-using namespace Ndnx;
+namespace ndn {
+namespace chronoshare {
+
 namespace fs = boost::filesystem;
 
-const string INIT_DATABASE = "\
+const std::string INIT_DATABASE = "\
 CREATE TABLE IF NOT EXISTS                                      \n\
   Task(                                                         \n\
     deviceName  BLOB NOT NULL,                                  \n\
@@ -45,14 +46,12 @@
 
   int res = sqlite3_open((actualFolder / tag).c_str(), &m_db);
   if (res != SQLITE_OK) {
-    BOOST_THROW_EXCEPTION(
-      Error::Db() << errmsg_info_str("Cannot open database: " + (actualFolder / tag).string()));
+    BOOST_THROW_EXCEPTION(Error("Cannot open database: " + (actualFolder / tag).string()));
   }
 
   char* errmsg = 0;
   res = sqlite3_exec(m_db, INIT_DATABASE.c_str(), NULL, NULL, &errmsg);
   if (res != SQLITE_OK && errmsg != 0) {
-    // _LOG_TRACE ("Init \"error\": " << errmsg);
     sqlite3_free(errmsg);
   }
   else {
@@ -73,12 +72,13 @@
 {
   sqlite3_stmt* stmt;
   sqlite3_prepare_v2(m_db,
-                     "INSERT OR IGNORE INTO Task (deviceName, baseName, minSeqNo, maxSeqNo, priority) VALUES (?, ?, ?, ?, ?)",
+                     "INSERT OR IGNORE INTO Task(deviceName, baseName, minSeqNo, maxSeqNo, priority) VALUES(?, ?, ?, ?, ?)",
                      -1, &stmt, 0);
-  CcnxCharbufPtr deviceBuf = CcnxCharbufPtr(deviceName);
-  CcnxCharbufPtr baseBuf = CcnxCharbufPtr(baseName);
-  sqlite3_bind_blob(stmt, 1, deviceBuf->buf(), deviceBuf->length(), SQLITE_STATIC);
-  sqlite3_bind_blob(stmt, 2, baseBuf->buf(), baseBuf->length(), SQLITE_STATIC);
+
+  sqlite3_bind_blob(stmt, 1, deviceName.wireEncode().wire(), deviceName.wireEncode().size(),
+                    SQLITE_STATIC);
+  sqlite3_bind_blob(stmt, 2, baseName.wireEncode().wire(), baseName.wireEncode().size(),
+                    SQLITE_STATIC);
   sqlite3_bind_int64(stmt, 3, minSeqNo);
   sqlite3_bind_int64(stmt, 4, maxSeqNo);
   sqlite3_bind_int(stmt, 5, priority);
@@ -94,10 +94,12 @@
 {
   sqlite3_stmt* stmt;
   sqlite3_prepare_v2(m_db, "DELETE FROM Task WHERE deviceName = ? AND baseName = ?;", -1, &stmt, 0);
-  NdnxCharbufPtr deviceBuf = NdnxCharbufPtr(deviceName);
-  NdnxCharbufPtr baseBuf = NdnxCharbufPtr(baseName);
-  sqlite3_bind_blob(stmt, 1, deviceBuf->buf(), deviceBuf->length(), SQLITE_STATIC);
-  sqlite3_bind_blob(stmt, 2, baseBuf->buf(), baseBuf->length(), SQLITE_STATIC);
+
+  sqlite3_bind_blob(stmt, 1, deviceName.wireEncode().wire(), deviceName.wireEncode().size(),
+                    SQLITE_STATIC);
+  sqlite3_bind_blob(stmt, 2, baseName.wireEncode().wire(), baseName.wireEncode().size(),
+                    SQLITE_STATIC);
+
   int res = sqlite3_step(stmt);
   if (res == SQLITE_OK) {
   }
@@ -110,8 +112,10 @@
   sqlite3_stmt* stmt;
   sqlite3_prepare_v2(m_db, "SELECT * FROM Task;", -1, &stmt, 0);
   while (sqlite3_step(stmt) == SQLITE_ROW) {
-    Name deviceName(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0));
-    Name baseName(sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 1));
+    Name deviceName(Block(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0)));
+    Name baseName(Block(sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 1)));
+
+    std::cout << "deviceName: " << deviceName << " baseName: " << baseName << std::endl;
     uint64_t minSeqNo = sqlite3_column_int64(stmt, 2);
     uint64_t maxSeqNo = sqlite3_column_int64(stmt, 3);
     int priority = sqlite3_column_int(stmt, 4);
@@ -120,3 +124,6 @@
 
   sqlite3_finalize(stmt);
 }
+
+} // namespace chronoshare
+} // namespace ndn