action-log: Switch code to use ndn-cxx
This commit also moves code to ndn::chronoshare namespace
Change-Id: I3431833f1037eec9100515c405528cd4674be158
diff --git a/src/file-state.cpp b/src/file-state.cpp
index 33a4384..83d2acc 100644
--- a/src/file-state.cpp
+++ b/src/file-state.cpp
@@ -18,14 +18,13 @@
* See AUTHORS.md for complete list of ChronoShare authors and contributors.
*/
-#include "file-state.h"
-#include "logging.h"
-#include <boost/bind.hpp>
+#include "file-state.hpp"
+#include "core/logging.hpp"
_LOG_INIT(FileState);
-using namespace boost;
-using namespace std;
+namespace ndn {
+namespace chronoshare {
const std::string INIT_DATABASE = "\
\n\
@@ -63,9 +62,9 @@
}
void
-FileState::UpdateFile(const std::string& filename, sqlite3_int64 version, const Hash& hash,
- const Ccnx::CcnxCharbuf& device_name, sqlite3_int64 seq_no, time_t atime,
- time_t mtime, time_t ctime, int mode, int seg_num)
+FileState::UpdateFile(const std::string& filename, sqlite3_int64 version, const Buffer& hash,
+ const Buffer& device_name, sqlite3_int64 seq_no, time_t atime, time_t mtime,
+ time_t ctime, int mode, int seg_num)
{
sqlite3_stmt* stmt;
sqlite3_prepare_v2(m_db, "UPDATE FileState "
@@ -81,10 +80,10 @@
"WHERE type=0 AND filename=?",
-1, &stmt, 0);
- sqlite3_bind_blob(stmt, 1, device_name.buf(), device_name.length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, device_name.buf(), device_name.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, seq_no);
sqlite3_bind_int64(stmt, 3, version);
- sqlite3_bind_blob(stmt, 4, hash.GetHash(), hash.GetHashBytes(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 4, hash.buf(), hash.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 5, atime);
sqlite3_bind_int64(stmt, 6, mtime);
sqlite3_bind_int64(stmt, 7, ctime);
@@ -105,7 +104,8 @@
sqlite3_stmt* stmt;
sqlite3_prepare_v2(m_db,
"INSERT INTO FileState "
- "(type,filename,version,device_name,seq_no,file_hash,file_atime,file_mtime,file_ctime,file_chmod,file_seg_num) "
+ "(type,filename,version,device_name,seq_no,file_hash,"
+ "file_atime,file_mtime,file_ctime,file_chmod,file_seg_num) "
"VALUES (0, ?, ?, ?, ?, ?, "
"datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?, ?)",
-1, &stmt, 0);
@@ -114,9 +114,9 @@
sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, version);
- sqlite3_bind_blob(stmt, 3, device_name.buf(), device_name.length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 3, device_name.buf(), device_name.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 4, seq_no);
- sqlite3_bind_blob(stmt, 5, hash.GetHash(), hash.GetHashBytes(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 5, hash.buf(), hash.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 6, atime);
sqlite3_bind_int64(stmt, 7, mtime);
sqlite3_bind_int64(stmt, 8, ctime);
@@ -139,7 +139,6 @@
}
}
-
void
FileState::DeleteFile(const std::string& filename)
{
@@ -154,7 +153,6 @@
sqlite3_finalize(stmt);
}
-
void
FileState::SetFileComplete(const std::string& filename)
{
@@ -170,7 +168,6 @@
sqlite3_finalize(stmt);
}
-
/**
* @todo Implement checking modification time and permissions
*/
@@ -207,7 +204,7 @@
}
FileItemsPtr
-FileState::LookupFilesForHash(const Hash& hash)
+FileState::LookupFilesForHash(const Buffer& hash)
{
sqlite3_stmt* stmt;
sqlite3_prepare_v2(m_db,
@@ -216,7 +213,7 @@
" WHERE type = 0 AND file_hash = ?",
-1, &stmt, 0);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- sqlite3_bind_blob(stmt, 1, hash.GetHash(), hash.GetHashBytes(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, hash.buf(), hash.size(), SQLITE_STATIC);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
FileItemsPtr retval = make_shared<FileItems>();
@@ -243,7 +240,7 @@
}
void
-FileState::LookupFilesInFolder(const boost::function<void(const FileItem&)>& visitor,
+FileState::LookupFilesInFolder(const function<void(const FileItem&)>& visitor,
const std::string& folder, int offset /*=0*/, int limit /*=-1*/)
{
sqlite3_stmt* stmt;
@@ -286,13 +283,15 @@
FileState::LookupFilesInFolder(const std::string& folder, int offset /*=0*/, int limit /*=-1*/)
{
FileItemsPtr retval = make_shared<FileItems>();
- LookupFilesInFolder(boost::bind(&FileItems::push_back, retval.get(), _1), folder, offset, limit);
+ LookupFilesInFolder(bind(static_cast<void (FileItems::*)(const FileItem&)>(&FileItems::push_back),
+ retval.get(), _1),
+ folder, offset, limit);
return retval;
}
bool
-FileState::LookupFilesInFolderRecursively(const boost::function<void(const FileItem&)>& visitor,
+FileState::LookupFilesInFolderRecursively(const function<void(const FileItem&)>& visitor,
const std::string& folder, int offset /*=0*/,
int limit /*=-1*/)
{
@@ -308,7 +307,7 @@
sqlite3_prepare_v2(m_db,
"SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
" FROM FileState "
- " WHERE type = 0 AND is_dir_prefix (?, directory)=1 "
+ " WHERE type = 0 AND is_dir_prefix(?, directory)=1 "
" ORDER BY filename "
" LIMIT ? OFFSET ?",
-1, &stmt,
@@ -367,7 +366,12 @@
int limit /*=-1*/)
{
FileItemsPtr retval = make_shared<FileItems>();
- LookupFilesInFolder(boost::bind(&FileItems::push_back, retval.get(), _1), folder, offset, limit);
+ LookupFilesInFolder(bind(static_cast<void (FileItems::*)(const FileItem&)>(&FileItems::push_back),
+ retval.get(), _1),
+ folder, offset, limit);
return retval;
}
+
+} // namespace chronoshare
+} // namespace ndn