action-log: Switch code to use ndn-cxx
This commit also moves code to ndn::chronoshare namespace
Change-Id: I3431833f1037eec9100515c405528cd4674be158
diff --git a/src/action-log.cpp b/src/action-log.cpp
index 179be79..7dbc663 100644
--- a/src/action-log.cpp
+++ b/src/action-log.cpp
@@ -19,13 +19,13 @@
*/
#include "action-log.hpp"
-#include "logging.hpp"
+#include "sync-core.hpp"
+#include "core/logging.hpp"
-#include <boost/make_shared.hpp>
+#include <ndn-cxx/util/string-helper.hpp>
-using namespace boost;
-using namespace std;
-using namespace Ndnx;
+namespace ndn {
+namespace chronoshare {
_LOG_INIT(ActionLog);
@@ -78,7 +78,8 @@
SELECT apply_action (NEW.device_name, NEW.seq_no, \
NEW.action,NEW.filename,NEW.version,NEW.file_hash, \
strftime('%s', NEW.file_atime),strftime('%s', NEW.file_mtime),strftime('%s', NEW.file_ctime), \
- NEW.file_chmod, NEW.file_seg_num); /* function that applies action and adds record the FileState */ \n \
+ NEW.file_chmod, NEW.file_seg_num); \n\
+ /* function that applies action and adds record the FileState */ \n\
END; \n\
";
@@ -88,13 +89,13 @@
// _LOG_TRACE("SQLITE: " << q);
// }
-ActionLog::ActionLog(Ccnx::CcnxWrapperPtr ccnx, const boost::filesystem::path& path,
- SyncLogPtr syncLog, const std::string& sharedFolder,
- const std::string& appName, OnFileAddedOrChangedCallback onFileAddedOrChanged,
+ActionLog::ActionLog(Face& face, const boost::filesystem::path& path, SyncLogPtr syncLog,
+ const std::string& sharedFolder, const std::string& appName,
+ OnFileAddedOrChangedCallback onFileAddedOrChanged,
OnFileRemovedCallback onFileRemoved)
: DbHelper(path / ".chronoshare", "action-log.db")
, m_syncLog(syncLog)
- , m_ccnx(ccnx)
+ // , m_face(face)
, m_sharedFolderName(sharedFolder)
, m_appName(appName)
, m_onFileAddedOrChanged(onFileAddedOrChanged)
@@ -110,13 +111,13 @@
sqlite3_create_function(m_db, "apply_action", -1, SQLITE_ANY, reinterpret_cast<void*>(this),
ActionLog::apply_action_xFun, 0, 0);
if (res != SQLITE_OK) {
- BOOST_THROW_EXCEPTION(Error::Db() << errmsg_info_str("Cannot create function ``apply_action''"));
+ BOOST_THROW_EXCEPTION(Error("Cannot create function ``apply_action''"));
}
m_fileState = make_shared<FileState>(path);
}
-tuple<sqlite3_int64 /*version*/, Ccnx::CcnxCharbufPtr /*device name*/, sqlite3_int64 /*seq_no*/>
+std::tuple<sqlite3_int64 /*version*/, BufferPtr /*device name*/, sqlite3_int64 /*seq_no*/>
ActionLog::GetLatestActionForFile(const std::string& filename)
{
// check if something already exists
@@ -127,11 +128,11 @@
-1, &stmt, 0);
if (res != SQLITE_OK) {
- BOOST_THROW_EXCEPTION(Error::Db() << errmsg_info_str("Some error with GetExistingRecord"));
+ BOOST_THROW_EXCEPTION(Error("Some error with GetExistingRecord"));
}
sqlite3_int64 version = -1;
- NdnxCharbufPtr parent_device_name;
+ BufferPtr parent_device_name;
sqlite3_int64 parent_seq_no = -1;
sqlite3_bind_text(stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC);
@@ -141,32 +142,30 @@
if (sqlite3_column_int(stmt, 3) == 0) // prevent "linking" if the file was previously deleted
{
parent_device_name =
- make_shared<CcnxCharbuf>(sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 1));
+ std::make_shared<Buffer>(sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 1));
parent_seq_no = sqlite3_column_int64(stmt, 2);
}
}
sqlite3_finalize(stmt);
- return make_tuple(version, parent_device_name, parent_seq_no);
+ return std::make_tuple(version, parent_device_name, parent_seq_no);
}
// local add action. remote action is extracted from content object
ActionItemPtr
-ActionLog::AddLocalActionUpdate(const std::string& filename,
- const Hash& hash,
- time_t wtime,
- int mode,
- int seg_num)
+ActionLog::AddLocalActionUpdate(const std::string& filename, const Buffer& hash, time_t wtime,
+ int mode, int seg_num)
{
sqlite3_exec(m_db, "BEGIN TRANSACTION;", 0, 0, 0);
- CcnxCharbufPtr device_name = m_syncLog->GetLocalName().toCcnxCharbuf();
+ Block device_name = m_syncLog->GetLocalName().wireEncode();
+
sqlite3_int64 seq_no = m_syncLog->GetNextLocalSeqNo();
sqlite3_int64 version;
- CcnxCharbufPtr parent_device_name;
+ BufferPtr parent_device_name;
sqlite3_int64 parent_seq_no = -1;
- sqlite3_int64 action_time = time(0);
+ sqlite3_int64 action_time = std::time(0);
tie(version, parent_device_name, parent_seq_no) = GetLatestActionForFile(filename);
version++;
@@ -188,27 +187,26 @@
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
if (res != SQLITE_OK) {
- BOOST_THROW_EXCEPTION(Error::Db() << errmsg_info_str(sqlite3_errmsg(m_db)));
+ BOOST_THROW_EXCEPTION(Error(sqlite3_errmsg(m_db)));
}
- sqlite3_bind_blob(stmt, 1, device_name->buf(), device_name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, device_name.wire(), device_name.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, seq_no);
sqlite3_bind_int(stmt, 3, 0);
sqlite3_bind_text(stmt, 4, filename.c_str(), filename.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 5, version);
sqlite3_bind_int64(stmt, 6, action_time);
- sqlite3_bind_blob(stmt, 7, hash.GetHash(), hash.GetHashBytes(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 7, hash.buf(), hash.size(), SQLITE_STATIC);
- // sqlite3_bind_int64 (stmt, 8, atime); // NULL
+ // sqlite3_bind_int64(stmt, 8, atime); // NULL
sqlite3_bind_int64(stmt, 9, wtime);
- // sqlite3_bind_int64 (stmt, 10, ctime); // NULL
+ // sqlite3_bind_int64(stmt, 10, ctime); // NULL
sqlite3_bind_int(stmt, 11, mode);
sqlite3_bind_int(stmt, 12, seg_num);
if (parent_device_name && parent_seq_no > 0) {
- sqlite3_bind_blob(stmt, 13, parent_device_name->buf(), parent_device_name->length(),
- SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 13, parent_device_name->buf(), parent_device_name->size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 14, parent_seq_no);
}
@@ -217,38 +215,44 @@
item->set_filename(filename);
item->set_version(version);
item->set_timestamp(action_time);
- item->set_file_hash(hash.GetHash(), hash.GetHashBytes());
- // item->set_atime (atime);
+ item->set_file_hash(hash.buf(), hash.size());
+ // item->set_atime(atime);
item->set_mtime(wtime);
- // item->set_ctime (ctime);
+ // item->set_ctime(ctime);
item->set_mode(mode);
item->set_seg_num(seg_num);
if (parent_device_name && parent_seq_no > 0) {
- // cout << Name (*parent_device_name) << endl;
+ // cout << Name(*parent_device_name) << endl;
- item->set_parent_device_name(parent_device_name->buf(), parent_device_name->length());
+ item->set_parent_device_name(parent_device_name->buf(), parent_device_name->size());
item->set_parent_seq_no(parent_seq_no);
}
// assign name to the action, serialize action, and create content object
-
- string item_msg;
+ std::string item_msg;
item->SerializeToString(&item_msg);
// action name: /<device_name>/<appname>/action/<shared-folder>/<action-seq>
- Name actionName =
- Name("/")(m_syncLog->GetLocalName())(m_appName)("action")(m_sharedFolderName)(seq_no);
+
+ Name actionName = Name("/");
+ actionName.append(m_syncLog->GetLocalName()).append(m_appName).append("action");
+ actionName.append(m_sharedFolderName).appendNumber(seq_no);
_LOG_DEBUG("ActionName: " << actionName);
- Bytes actionData = m_ccnx->createContentObject(actionName, item_msg.c_str(), item_msg.size());
- CcnxCharbufPtr namePtr = actionName.toCcnxCharbuf();
+ shared_ptr<Data> actionData = make_shared<Data>();
+ actionData->setName(actionName);
+ actionData->setFreshnessPeriod(time::seconds(60));
+ actionData->setContent(reinterpret_cast<const uint8_t*>(item_msg.c_str()), item_msg.size());
+ m_keyChain.sign(*actionData);
- // _LOG_DEBUG (" >>>>>>> " << Name (namePtr->buf () << " " << namePtr->length ());
+ // _LOG_DEBUG(" >>>>>>> " << Name(namePtr->buf() << " " << namePtr->length());
- sqlite3_bind_blob(stmt, 15, namePtr->buf(), namePtr->length(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 16, head(actionData), actionData.size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 15, actionName.wireEncode().wire(), actionName.wireEncode().size(),
+ SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 16, actionData->wireEncode().wire(), actionData->wireEncode().size(),
+ SQLITE_STATIC);
sqlite3_step(stmt);
@@ -262,7 +266,7 @@
-1, &stmt, 0);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- sqlite3_bind_blob(stmt, 1, device_name->buf(), device_name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, device_name.wire(), device_name.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, seq_no);
sqlite3_step(stmt);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
@@ -278,11 +282,10 @@
}
// void
-// ActionLog::AddActionMove (const std::string &oldFile, const std::string &newFile)
+// ActionLog::AddActionMove(const std::string &oldFile, const std::string &newFile)
// {
// // not supported yet
-// BOOST_THROW_EXCEPTION (Error::Db ()
-// << errmsg_info_str ("Move operation is not yet supported"));
+// BOOST_THROW_EXCEPTION(Error("Move operation is not yet supported"));
// }
ActionItemPtr
@@ -292,12 +295,12 @@
sqlite3_exec(m_db, "BEGIN TRANSACTION;", 0, 0, 0);
- CcnxCharbufPtr device_name = m_syncLog->GetLocalName().toCcnxCharbuf();
+ const Block device_name = m_syncLog->GetLocalName().wireEncode();
sqlite3_int64 version;
- CcnxCharbufPtr parent_device_name;
+ BufferPtr parent_device_name;
sqlite3_int64 parent_seq_no = -1;
- sqlite3_int64 action_time = time(0);
+ sqlite3_int64 action_time = std::time(0);
tie(version, parent_device_name, parent_seq_no) = GetLatestActionForFile(filename);
if (!parent_device_name) // no records exist or file was already deleted
@@ -327,12 +330,12 @@
"(device_name, seq_no, action, filename, version, action_timestamp, "
"parent_device_name, parent_seq_no, "
"action_name, action_content_object) "
- "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
+ "VALUES(?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
" ?, ?,"
" ?, ?)",
-1, &stmt, 0);
- sqlite3_bind_blob(stmt, 1, device_name->buf(), device_name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, device_name.wire(), device_name.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, seq_no);
sqlite3_bind_int(stmt, 3, 1);
sqlite3_bind_text(stmt, 4, filename.c_str(), filename.size(), SQLITE_STATIC); // file
@@ -340,7 +343,7 @@
sqlite3_bind_int64(stmt, 5, version);
sqlite3_bind_int64(stmt, 6, action_time);
- sqlite3_bind_blob(stmt, 7, parent_device_name->buf(), parent_device_name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 7, parent_device_name->buf(), parent_device_name->size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 8, parent_seq_no);
ActionItemPtr item = make_shared<ActionItem>();
@@ -348,28 +351,34 @@
item->set_filename(filename);
item->set_version(version);
item->set_timestamp(action_time);
- item->set_parent_device_name(parent_device_name->buf(), parent_device_name->length());
+ item->set_parent_device_name(parent_device_name->buf(), parent_device_name->size());
item->set_parent_seq_no(parent_seq_no);
- string item_msg;
+ std::string item_msg;
item->SerializeToString(&item_msg);
// action name: /<device_name>/<appname>/action/<shared-folder>/<action-seq>
- Name actionName =
- Name("/")(m_syncLog->GetLocalName())(m_appName)("action")(m_sharedFolderName)(seq_no);
+ Name actionName = Name("/");
+ actionName.append(m_syncLog->GetLocalName()).append(m_appName).append("action");
+ actionName.append(m_sharedFolderName).appendNumber(seq_no);
_LOG_DEBUG("ActionName: " << actionName);
- Bytes actionData = m_ccnx->createContentObject(actionName, item_msg.c_str(), item_msg.size());
- CcnxCharbufPtr namePtr = actionName.toCcnxCharbuf();
+ shared_ptr<Data> actionData = make_shared<Data>();
+ actionData->setName(actionName);
+ actionData->setFreshnessPeriod(time::seconds(60));
+ actionData->setContent(reinterpret_cast<const uint8_t*>(item_msg.c_str()), item_msg.size());
+ m_keyChain.sign(*actionData);
- sqlite3_bind_blob(stmt, 9, namePtr->buf(), namePtr->length(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 10, &actionData[0], actionData.size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 9, actionName.wireEncode().wire(), actionName.wireEncode().size(),
+ SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 10, actionData->wireEncode().wire(), actionData->wireEncode().size(),
+ SQLITE_STATIC);
sqlite3_step(stmt);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
- // cout << Ndnx::Name (parent_device_name) << endl;
+ // cout << Name(parent_device_name) << endl;
// assign name to the action, serialize action, and create content object
@@ -381,7 +390,7 @@
-1, &stmt, 0);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- sqlite3_bind_blob(stmt, 1, device_name->buf(), device_name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, device_name.wire(), device_name.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, seq_no);
sqlite3_step(stmt);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
@@ -393,68 +402,68 @@
return item;
}
-
-PcoPtr
-ActionLog::LookupActionPco(const Ccnx::Name& deviceName, sqlite3_int64 seqno)
+shared_ptr<Data>
+ActionLog::LookupActionData(const Name& deviceName, sqlite3_int64 seqno)
{
sqlite3_stmt* stmt;
sqlite3_prepare_v2(m_db,
"SELECT action_content_object FROM ActionLog WHERE device_name=? AND seq_no=?",
-1, &stmt, 0);
- CcnxCharbufPtr name = deviceName.toCcnxCharbuf();
-
- sqlite3_bind_blob(stmt, 1, name->buf(), name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, deviceName.wireEncode().wire(), deviceName.wireEncode().size(),
+ SQLITE_STATIC); // ndn version
sqlite3_bind_int64(stmt, 2, seqno);
- PcoPtr retval;
+ shared_ptr<Data> retval;
+
if (sqlite3_step(stmt) == SQLITE_ROW) {
- // _LOG_DEBUG (sqlite3_column_blob (stmt, 0) << ", " << sqlite3_column_bytes (stmt, 0));
- retval = make_shared<ParsedContentObject>(reinterpret_cast<const unsigned char*>(
- sqlite3_column_blob(stmt, 0)),
- sqlite3_column_bytes(stmt, 0));
+ // _LOG_DEBUG(sqlite3_column_blob(stmt, 0) << ", " << sqlite3_column_bytes(stmt, 0));
+ retval = make_shared<Data>();
+ retval->wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0)));
}
else {
_LOG_TRACE("No action found for deviceName [" << deviceName << "] and seqno:" << seqno);
}
- // _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK && sqlite3_errcode (m_db) != SQLITE_ROW, sqlite3_errmsg (m_db));
+ // _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK && sqlite3_errcode(m_db) != SQLITE_ROW,
+ // sqlite3_errmsg(m_db));
sqlite3_finalize(stmt);
return retval;
}
ActionItemPtr
-ActionLog::LookupAction(const Ccnx::Name& deviceName, sqlite3_int64 seqno)
+ActionLog::LookupAction(const Name& deviceName, sqlite3_int64 seqno)
{
- PcoPtr pco = LookupActionPco(deviceName, seqno);
- if (!pco)
+ shared_ptr<Data> data = LookupActionData(deviceName, seqno);
+ if (!data)
return ActionItemPtr();
- ActionItemPtr action = deserializeMsg<ActionItem>(pco->content());
-
+ ActionItemPtr action =
+ deserializeMsg<ActionItem>(Buffer(data->getContent().value(), data->getContent().value_size()));
return action;
}
-Ccnx::PcoPtr
-ActionLog::LookupActionPco(const Ccnx::Name& actionName)
+shared_ptr<Data>
+ActionLog::LookupActionData(const Name& actionName)
{
sqlite3_stmt* stmt;
sqlite3_prepare_v2(m_db, "SELECT action_content_object FROM ActionLog WHERE action_name=?", -1,
&stmt, 0);
_LOG_DEBUG(actionName);
- CcnxCharbufPtr name = actionName.toCcnxCharbuf();
- _LOG_DEBUG(" <<<<<<< " << name->buf() << " " << name->length());
+ _LOG_DEBUG(" LookActionData <<<<<<< " << actionName << " " << actionName.wireEncode().size());
- sqlite3_bind_blob(stmt, 1, name->buf(), name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, actionName.wireEncode().wire(), actionName.wireEncode().size(),
+ SQLITE_STATIC);
- PcoPtr retval;
+ shared_ptr<Data> retval; // = make_shared<Data>();
if (sqlite3_step(stmt) == SQLITE_ROW) {
- // _LOG_DEBUG (sqlite3_column_blob (stmt, 0) << ", " << sqlite3_column_bytes (stmt, 0));
- retval = make_shared<ParsedContentObject>(reinterpret_cast<const unsigned char*>(
- sqlite3_column_blob(stmt, 0)),
- sqlite3_column_bytes(stmt, 0));
+ // _LOG_DEBUG(sqlite3_column_blob(stmt, 0) << ", " << sqlite3_column_bytes(stmt, 0));
+ retval = make_shared<Data>();
+ retval->wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0)));
}
else {
_LOG_TRACE("No action found for name: " << actionName);
@@ -466,19 +475,20 @@
}
ActionItemPtr
-ActionLog::LookupAction(const Ccnx::Name& actionName)
+ActionLog::LookupAction(const Name& actionName)
{
- PcoPtr pco = LookupActionPco(actionName);
- if (!pco)
+ shared_ptr<Data> data = LookupActionData(actionName);
+ if (!data)
return ActionItemPtr();
- ActionItemPtr action = deserializeMsg<ActionItem>(pco->content());
+ ActionItemPtr action =
+ deserializeMsg<ActionItem>(Buffer(data->getContent().value(), data->getContent().value_size()));
return action;
}
FileItemPtr
-ActionLog::LookupAction(const std::string& filename, sqlite3_int64 version, const Hash& filehash)
+ActionLog::LookupAction(const std::string& filename, sqlite3_int64 version, const Buffer& filehash)
{
sqlite3_stmt* stmt;
sqlite3_prepare_v2(m_db,
@@ -487,13 +497,13 @@
" WHERE action = 0 AND "
" filename=? AND "
" version=? AND "
- " is_prefix (?, file_hash)=1",
+ " is_prefix(?, file_hash)=1",
-1, &stmt, 0);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
sqlite3_bind_text(stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, version);
- sqlite3_bind_blob(stmt, 3, filehash.GetHash(), filehash.GetHashBytes(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 3, filehash.buf(), filehash.size(), SQLITE_STATIC);
FileItemPtr fileItem;
@@ -518,38 +528,38 @@
ActionItemPtr
-ActionLog::AddRemoteAction(const Ccnx::Name& deviceName, sqlite3_int64 seqno, Ccnx::PcoPtr actionPco)
+ActionLog::AddRemoteAction(const Name& deviceName, sqlite3_int64 seqno, shared_ptr<Data> actionData)
{
- if (!actionPco) {
- _LOG_ERROR("actionPco is not valid");
+ if (!actionData) {
+ _LOG_ERROR("actionData is not valid");
return ActionItemPtr();
}
- ActionItemPtr action = deserializeMsg<ActionItem>(actionPco->content());
+ ActionItemPtr action = deserializeMsg<ActionItem>(
+ Buffer(actionData->getContent().value(), actionData->getContent().value_size()));
if (!action) {
_LOG_ERROR("action cannot be decoded");
return ActionItemPtr();
}
- _LOG_DEBUG("AddRemoteAction: [" << deviceName << "] seqno: " << seqno);
+ _LOG_DEBUG("AddRemoteAction: [" << deviceName.toUri() << "] seqno: " << seqno);
sqlite3_stmt* stmt;
- int res =
- sqlite3_prepare_v2(m_db,
- "INSERT INTO ActionLog "
- "(device_name, seq_no, action, filename, version, action_timestamp, "
- "file_hash, file_atime, file_mtime, file_ctime, file_chmod, file_seg_num, "
- "parent_device_name, parent_seq_no, "
- "action_name, action_content_object) "
- "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
- " ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?,?, "
- " ?, ?, "
- " ?, ?);",
- -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db,
+ "INSERT INTO ActionLog "
+ "(device_name, seq_no, action, filename, version, action_timestamp, "
+ "file_hash, file_atime, file_mtime, file_ctime, file_chmod, file_seg_num, "
+ "parent_device_name, parent_seq_no, "
+ "action_name, action_content_object) "
+ "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
+ " ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?,?, "
+ " ?, ?, "
+ " ?, ?);",
+ -1, &stmt, 0);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- CcnxCharbufPtr device_name = deviceName.toCcnxCharbuf();
- sqlite3_bind_blob(stmt, 1, device_name->buf(), device_name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, deviceName.wireEncode().wire(), deviceName.wireEncode().size(),
+ SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, seqno);
sqlite3_bind_int(stmt, 3, action->action());
@@ -561,9 +571,9 @@
sqlite3_bind_blob(stmt, 7, action->file_hash().c_str(), action->file_hash().size(),
SQLITE_STATIC);
- // sqlite3_bind_int64 (stmt, 8, atime); // NULL
+ // sqlite3_bind_int64(stmt, 8, atime); // NULL
sqlite3_bind_int64(stmt, 9, action->mtime());
- // sqlite3_bind_int64 (stmt, 10, ctime); // NULL
+ // sqlite3_bind_int64(stmt, 10, ctime); // NULL
sqlite3_bind_int(stmt, 11, action->mode());
sqlite3_bind_int(stmt, 12, action->seg_num());
@@ -575,11 +585,13 @@
sqlite3_bind_int64(stmt, 14, action->parent_seq_no());
}
- Name actionName = Name(deviceName)("action")(m_sharedFolderName)(seqno);
- CcnxCharbufPtr namePtr = actionName.toCcnxCharbuf();
+ Name actionName = Name(deviceName);
+ actionName.append("action").append(m_sharedFolderName).appendNumber(seqno);
- sqlite3_bind_blob(stmt, 15, namePtr->buf(), namePtr->length(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 16, head(actionPco->buf()), actionPco->buf().size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 15, actionName.wireEncode().wire(), actionName.wireEncode().size(),
+ SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 16, actionData->wireEncode().wire(), actionData->wireEncode().size(),
+ SQLITE_STATIC);
sqlite3_step(stmt);
// if action needs to be applied to file state, the trigger will take care of it
@@ -594,7 +606,8 @@
-1, &stmt, 0);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- sqlite3_bind_blob(stmt, 1, device_name->buf(), device_name->length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, deviceName.wireEncode().wire(), deviceName.wireEncode().size(),
+ SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, seqno);
sqlite3_step(stmt);
_LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
@@ -605,40 +618,40 @@
}
ActionItemPtr
-ActionLog::AddRemoteAction(Ccnx::PcoPtr actionPco)
+ActionLog::AddRemoteAction(shared_ptr<Data> actionData)
{
- Name name = actionPco->name();
+ Name name = actionData->getName();
// action name: /<device_name>/<appname>/action/<shared-folder>/<action-seq>
- uint64_t seqno = name.getCompFromBackAsInt(0);
- string sharedFolder = name.getCompFromBackAsString(1);
+ uint64_t seqno = name.get(-1).toNumber();
+ std::string sharedFolder = name.get(-2).toUri();
if (sharedFolder != m_sharedFolderName) {
_LOG_ERROR("Action doesn't belong to this shared folder");
return ActionItemPtr();
}
- string action = name.getCompFromBackAsString(2);
+ std::string action = name.get(-3).toUri();
if (action != "action") {
_LOG_ERROR("not an action");
return ActionItemPtr();
}
- string appName = name.getCompFromBackAsString(3);
+ std::string appName = name.get(-4).toUri();
if (appName != m_appName) {
_LOG_ERROR("Action doesn't belong to this application");
return ActionItemPtr();
}
- Name deviceName = name.getPartialName(0, name.size() - 4);
+ Name deviceName = name.getSubName(0, name.size() - 4);
_LOG_DEBUG("From [" << name << "] extracted deviceName: " << deviceName << ", sharedFolder: "
<< sharedFolder
<< ", seqno: "
<< seqno);
- return AddRemoteAction(deviceName, seqno, actionPco);
+ return AddRemoteAction(deviceName, seqno, actionData);
}
sqlite3_int64
@@ -655,10 +668,9 @@
return retval;
}
-
bool
ActionLog::LookupActionsInFolderRecursively(
- const boost::function<void(const Ccnx::Name& name, sqlite3_int64 seq_no, const ActionItem&)>& visitor,
+ const function<void(const Name& name, sqlite3_int64 seq_no, const ActionItem&)>& visitor,
const std::string& folder, int offset /*=0*/, int limit /*=-1*/)
{
_LOG_DEBUG("LookupActionsInFolderRecursively: [" << folder << "]");
@@ -709,7 +721,9 @@
ActionItem action;
- Ccnx::Name device_name(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0));
+ Name device_name(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0)));
+
sqlite3_int64 seq_no = sqlite3_column_int64(stmt, 1);
action.set_action(static_cast<ActionItem_ActionType>(sqlite3_column_int(stmt, 2)));
action.set_filename(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3)),
@@ -746,7 +760,7 @@
*/
bool
ActionLog::LookupActionsForFile(
- const boost::function<void(const Ccnx::Name& name, sqlite3_int64 seq_no, const ActionItem&)>& visitor,
+ const function<void(const Name& name, sqlite3_int64 seq_no, const ActionItem&)>& visitor,
const std::string& file, int offset /*=0*/, int limit /*=-1*/)
{
_LOG_DEBUG("LookupActionsInFolderRecursively: [" << file << "]");
@@ -783,7 +797,9 @@
ActionItem action;
- Ccnx::Name device_name(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0));
+ Name device_name(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0)));
+
sqlite3_int64 seq_no = sqlite3_column_int64(stmt, 1);
action.set_action(static_cast<ActionItem_ActionType>(sqlite3_column_int(stmt, 2)));
action.set_filename(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3)),
@@ -815,9 +831,8 @@
return (limit == 1); // more data is available
}
-
void
-ActionLog::LookupRecentFileActions(const boost::function<void(const string&, int, int)>& visitor,
+ActionLog::LookupRecentFileActions(const function<void(const std::string&, int, int)>& visitor,
int limit)
{
sqlite3_stmt* stmt;
@@ -864,25 +879,31 @@
return;
}
- CcnxCharbuf device_name(sqlite3_value_blob(argv[0]), sqlite3_value_bytes(argv[0]));
+ Buffer device_name(sqlite3_value_blob(argv[0]), sqlite3_value_bytes(argv[0]));
sqlite3_int64 seq_no = sqlite3_value_int64(argv[1]);
int action = sqlite3_value_int(argv[2]);
- string filename = reinterpret_cast<const char*>(sqlite3_value_text(argv[3]));
+ std::string filename = reinterpret_cast<const char*>(sqlite3_value_text(argv[3]));
sqlite3_int64 version = sqlite3_value_int64(argv[4]);
_LOG_TRACE("apply_function called with " << argc);
- _LOG_TRACE("device_name: " << Name(device_name) << ", action: " << action << ", file: " << filename);
+ _LOG_TRACE("device_name: " << Name(Block(reinterpret_cast<const char*>(device_name.buf()),
+ device_name.size()))
+ << ", action: "
+ << action
+ << ", file: "
+ << filename);
if (action == 0) // update
{
- Hash hash(sqlite3_value_blob(argv[5]), sqlite3_value_bytes(argv[5]));
+ Buffer hash(sqlite3_value_blob(argv[5]), sqlite3_value_bytes(argv[5]));
time_t atime = static_cast<time_t>(sqlite3_value_int64(argv[6]));
time_t mtime = static_cast<time_t>(sqlite3_value_int64(argv[7]));
time_t ctime = static_cast<time_t>(sqlite3_value_int64(argv[8]));
int mode = sqlite3_value_int(argv[9]);
int seg_num = sqlite3_value_int(argv[10]);
- _LOG_DEBUG("Update " << filename << " " << atime << " " << mtime << " " << ctime << " " << hash);
+ _LOG_DEBUG("Update " << filename << " " << atime << " " << mtime << " " << ctime << " "
+ << toHex(hash));
the->m_fileState->UpdateFile(filename, version, hash, device_name, seq_no, atime, mtime, ctime,
mode, seg_num);
@@ -898,3 +919,6 @@
sqlite3_result_null(context);
}
+
+} // namespace chronoshare
+} // namespace ndn
diff --git a/src/action-log.hpp b/src/action-log.hpp
index 80f354c..99bcb0e 100644
--- a/src/action-log.hpp
+++ b/src/action-log.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,34 +18,48 @@
* See AUTHORS.md for complete list of ChronoShare authors and contributors.
*/
-#ifndef ACTION_LOG_H
-#define ACTION_LOG_H
+#ifndef CHRONOSHARE_SRC_ACTION_LOG_HPP
+#define CHRONOSHARE_SRC_ACTION_LOG_HPP
-#include "action-item.pb.hpp"
-#include "ccnx-pco.hpp"
-#include "ccnx-wrapper.hpp"
#include "db-helper.hpp"
-#include "file-item.pb.hpp"
#include "file-state.hpp"
#include "sync-log.hpp"
+#include "core/chronoshare-common.hpp"
-#include <boost/tuple/tuple.hpp>
+#include "action-item.pb.h"
+#include "file-item.pb.h"
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
+namespace ndn {
+namespace chronoshare {
class ActionLog;
-typedef boost::shared_ptr<ActionLog> ActionLogPtr;
-typedef boost::shared_ptr<ActionItem> ActionItemPtr;
+typedef shared_ptr<ActionLog> ActionLogPtr;
+typedef shared_ptr<ActionItem> ActionItemPtr;
class ActionLog : public DbHelper
{
public:
- typedef boost::function<void(std::string /*filename*/, Ccnx::Name /*device_name*/, sqlite3_int64 /*seq_no*/,
- HashPtr /*hash*/, time_t /*m_time*/, int /*mode*/, int /*seg_num*/)>
+ class Error : public DbHelper::Error
+ {
+ public:
+ explicit Error(const std::string& what)
+ : DbHelper::Error(what)
+ {
+ }
+ };
+
+public:
+ typedef function<void(std::string /*filename*/, Name /*device_name*/, sqlite3_int64 /*seq_no*/,
+ ConstBufferPtr /*hash*/, time_t /*m_time*/, int /*mode*/, int /*seg_num*/)>
OnFileAddedOrChangedCallback;
typedef boost::function<void(std::string /*filename*/)> OnFileRemovedCallback;
public:
- ActionLog(Ccnx::CcnxWrapperPtr ccnx, const boost::filesystem::path& path, SyncLogPtr syncLog,
+ ActionLog(Face& face, const boost::filesystem::path& path, SyncLogPtr syncLog,
const std::string& sharedFolder, const std::string& appName,
OnFileAddedOrChangedCallback onFileAddedOrChanged, OnFileRemovedCallback onFileRemoved);
@@ -57,14 +71,11 @@
// Local operations //
//////////////////////////
ActionItemPtr
- AddLocalActionUpdate(const std::string& filename,
- const Hash& hash,
- time_t wtime,
- int mode,
+ AddLocalActionUpdate(const std::string& filename, const Buffer& hash, time_t wtime, int mode,
int seg_num);
// void
- // AddActionMove (const std::string &oldFile, const std::string &newFile);
+ // AddActionMove(const std::string &oldFile, const std::string &newFile);
ActionItemPtr
AddLocalActionDelete(const std::string& filename);
@@ -74,51 +85,52 @@
//////////////////////////
ActionItemPtr
- AddRemoteAction(const Ccnx::Name& deviceName, sqlite3_int64 seqno, Ccnx::PcoPtr actionPco);
+ AddRemoteAction(const Name& deviceName, sqlite3_int64 seqno, shared_ptr<Data> actionData);
/**
* @brief Add remote action using just action's parsed content object
*
- * This function extracts device name and sequence number from the content object's and calls the overloaded method
+ * This function extracts device name and sequence number from the content object's and calls the
+ * overloaded method
*/
ActionItemPtr
- AddRemoteAction(Ccnx::PcoPtr actionPco);
+ AddRemoteAction(shared_ptr<Data> actionData);
///////////////////////////
// General operations //
///////////////////////////
- Ccnx::PcoPtr
- LookupActionPco(const Ccnx::Name& deviceName, sqlite3_int64 seqno);
+ shared_ptr<Data>
+ LookupActionData(const Name& deviceName, sqlite3_int64 seqno);
- Ccnx::PcoPtr
- LookupActionPco(const Ccnx::Name& actionName);
+ shared_ptr<Data>
+ LookupActionData(const Name& actionName);
ActionItemPtr
- LookupAction(const Ccnx::Name& deviceName, sqlite3_int64 seqno);
+ LookupAction(const Name& deviceName, sqlite3_int64 seqno);
ActionItemPtr
- LookupAction(const Ccnx::Name& actionName);
+ LookupAction(const Name& actionName);
FileItemPtr
- LookupAction(const std::string& filename, sqlite3_int64 version, const Hash& filehash);
+ LookupAction(const std::string& filename, sqlite3_int64 version, const Buffer& filehash);
/**
- * @brief Lookup up to [limit] actions starting [offset] in decreasing order (by timestamp) and calling visitor(device_name,seqno,action) for each action
+ * @brief Lookup up to [limit] actions starting [offset] in decreasing order(by timestamp) and
+ * calling visitor(device_name,seqno,action) for each action
*/
bool
LookupActionsInFolderRecursively(
- const boost::function<void(const Ccnx::Name& name, sqlite3_int64 seq_no, const ActionItem&)>& visitor,
+ const function<void(const Name& name, sqlite3_int64 seq_no, const ActionItem&)>& visitor,
const std::string& folder, int offset = 0, int limit = -1);
bool
LookupActionsForFile(
- const boost::function<void(const Ccnx::Name& name, sqlite3_int64 seq_no, const ActionItem&)>& visitor,
+ const function<void(const Name& name, sqlite3_int64 seq_no, const ActionItem&)>& visitor,
const std::string& file, int offset = 0, int limit = -1);
void
- LookupRecentFileActions(const boost::function<void(const std::string&, int, int)>& visitor,
- int limit = 5);
+ LookupRecentFileActions(const function<void(const std::string&, int, int)>& visitor, int limit = 5);
//
inline FileStatePtr
@@ -130,7 +142,7 @@
LogSize();
private:
- boost::tuple<sqlite3_int64 /*version*/, Ccnx::CcnxCharbufPtr /*device name*/, sqlite3_int64 /*seq_no*/>
+ std::tuple<sqlite3_int64 /*version*/, BufferPtr /*device name*/, sqlite3_int64 /*seq_no*/>
GetLatestActionForFile(const std::string& filename);
static void
@@ -140,25 +152,22 @@
SyncLogPtr m_syncLog;
FileStatePtr m_fileState;
- Ndnx::NdnxWrapperPtr m_ndnx;
+ // Face& m_face;
std::string m_sharedFolderName;
std::string m_appName;
OnFileAddedOrChangedCallback m_onFileAddedOrChanged;
OnFileRemovedCallback m_onFileRemoved;
+ KeyChain m_keyChain;
};
-namespace Error {
-struct ActionLog : virtual boost::exception, virtual std::exception
-{
-};
-}
-
inline FileStatePtr
ActionLog::GetFileState()
{
return m_fileState;
}
+} // namespace chronoshare
+} // namespace ndn
-#endif // ACTION_LOG_H
+#endif // CHRONOSHARE_SRC_ACTION_LOG_HPP
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
diff --git a/src/file-state.hpp b/src/file-state.hpp
index e074794..d9ea339 100644
--- a/src/file-state.hpp
+++ b/src/file-state.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.
*
@@ -22,20 +22,20 @@
#define FILE_STATE_H
#include "db-helper.hpp"
+#include "core/chronoshare-common.hpp"
-#include "ccnx-name.hpp"
-#include "file-item.pb.hpp"
-#include "hash-helper.hpp"
+#include "file-item.pb.h"
-#include <boost/exception/all.hpp>
-#include <boost/tuple/tuple.hpp>
+#include <ndn-cxx/util/digest.hpp>
#include <list>
-typedef std::list<FileItem> FileItems;
-typedef boost::shared_ptr<FileItem> FileItemPtr;
-typedef boost::shared_ptr<FileItems> FileItemsPtr;
+namespace ndn {
+namespace chronoshare {
+typedef std::list<FileItem> FileItems;
+typedef shared_ptr<FileItem> FileItemPtr;
+typedef shared_ptr<FileItems> FileItemsPtr;
class FileState : public DbHelper
{
@@ -47,8 +47,8 @@
* @brief Update or add a file
*/
void
- UpdateFile(const std::string& filename, sqlite3_int64 version, const Hash& hash,
- const Ccnx::CcnxCharbuf& device_name, sqlite3_int64 seqno, time_t atime, time_t mtime,
+ UpdateFile(const std::string& filename, sqlite3_int64 version, const Buffer& hash,
+ const Buffer& device_name, sqlite3_int64 seqno, time_t atime, time_t mtime,
time_t ctime, int mode, int seg_num);
/**
@@ -60,7 +60,8 @@
/**
* @brief Set "complete" flag
*
- * The call will do nothing if FileState does not have a record for the file (e.g., file got subsequently deleted)
+ * The call will do nothing if FileState does not have a record for the file(e.g., file got
+ * subsequently deleted)
*/
void
SetFileComplete(const std::string& filename);
@@ -72,45 +73,49 @@
LookupFile(const std::string& filename);
/**
- * @brief Lookup file state using content hash (multiple items may be returned)
+ * @brief Lookup file state using content hash(multiple items may be returned)
*/
FileItemsPtr
- LookupFilesForHash(const Hash& hash);
+ LookupFilesForHash(const Buffer& hash);
/**
* @brief Lookup all files in the specified folder and call visitor(file) for each file
*/
void
- LookupFilesInFolder(const boost::function<void(const FileItem&)>& visitor,
- const std::string& folder, int offset = 0, int limit = -1);
+ LookupFilesInFolder(const function<void(const FileItem&)>& visitor, const std::string& folder,
+ int offset = 0, int limit = -1);
/**
- * @brief Lookup all files in the specified folder (wrapper around the overloaded version)
+ * @brief Lookup all files in the specified folder(wrapper around the overloaded version)
*/
FileItemsPtr
LookupFilesInFolder(const std::string& folder, int offset = 0, int limit = -1);
/**
- * @brief Recursively lookup all files in the specified folder and call visitor(file) for each file
+ * @brief Recursively lookup all files in the specified folder and call visitor(file) for each
+ * file
*/
bool
- LookupFilesInFolderRecursively(const boost::function<void(const FileItem&)>& visitor,
+ LookupFilesInFolderRecursively(const function<void(const FileItem&)>& visitor,
const std::string& folder, int offset = 0, int limit = -1);
/**
- * @brief Recursively lookup all files in the specified folder (wrapper around the overloaded version)
+ * @brief Recursively lookup all files in the specified folder(wrapper around the overloaded
+ * version)
*/
FileItemsPtr
LookupFilesInFolderRecursively(const std::string& folder, int offset = 0, int limit = -1);
};
-typedef boost::shared_ptr<FileState> FileStatePtr;
+typedef shared_ptr<FileState> FileStatePtr;
-namespace Error {
+namespace error {
struct FileState : virtual boost::exception, virtual std::exception
{
};
-}
+} // namespace error
+} // namespace chronoshare
+} // namespace ndn
#endif // ACTION_LOG_H