Update style to (almost) conform to ndn-cxx style using clang-format
diff --git a/cmd/dump-db.cpp b/cmd/dump-db.cpp
index b9defea..e6245ea 100644
--- a/cmd/dump-db.cpp
+++ b/cmd/dump-db.cpp
@@ -18,179 +18,200 @@
* See AUTHORS.md for complete list of ChronoShare authors and contributors.
*/
+#include "ccnx-wrapper.hpp"
#include "dispatcher.hpp"
#include "fs-watcher.hpp"
#include "logging.hpp"
-#include "ccnx-wrapper.hpp"
-#include <boost/make_shared.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/make_shared.hpp>
using namespace boost;
using namespace std;
using namespace Ndnx;
-INIT_LOGGER ("DumpDb");
+INIT_LOGGER("DumpDb");
class StateLogDumper : public DbHelper
{
public:
- StateLogDumper (const filesystem::path &path)
- : DbHelper (path / ".chronoshare", "sync-log.db")
+ StateLogDumper(const filesystem::path& path)
+ : DbHelper(path / ".chronoshare", "sync-log.db")
{
}
void
- DumpState ()
+ DumpState()
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db, "SELECT hash(device_name, seq_no) FROM (SELECT * FROM SyncNodes ORDER BY device_name)", -1, &stmt, 0);
- sqlite3_step (stmt);
- Hash hash (sqlite3_column_blob (stmt, 0), sqlite3_column_bytes (stmt, 0));
- sqlite3_finalize (stmt);
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db,
+ "SELECT hash(device_name, seq_no) FROM (SELECT * FROM SyncNodes ORDER BY device_name)",
+ -1, &stmt, 0);
+ sqlite3_step(stmt);
+ Hash hash(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0));
+ sqlite3_finalize(stmt);
- sqlite3_prepare_v2 (m_db,
- "SELECT device_name, seq_no, last_known_locator, last_update "
- " FROM SyncNodes "
- " ORDER BY device_name", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "SELECT device_name, seq_no, last_known_locator, last_update "
+ " FROM SyncNodes "
+ " ORDER BY device_name",
+ -1, &stmt, 0);
cout.setf(std::ios::left, std::ios::adjustfield);
- cout << ">> SYNC NODES (" << hash.shortHash () << ") <<" << endl;
- cout << "====================================================================================" << endl;
- cout << setw(30) << "device_name" << " | seq_no | " << setw(20) << "locator" << " | last_update " << endl;
- cout << "====================================================================================" << endl;
+ cout << ">> SYNC NODES (" << hash.shortHash() << ") <<" << endl;
+ cout << "===================================================================================="
+ << endl;
+ cout << setw(30) << "device_name"
+ << " | seq_no | " << setw(20) << "locator"
+ << " | last_update " << endl;
+ cout << "===================================================================================="
+ << endl;
- while (sqlite3_step (stmt) == SQLITE_ROW)
- {
- cout << setw (30) << lexical_cast<string> (Name (sqlite3_column_blob (stmt, 0), sqlite3_column_bytes (stmt, 0))) << " | "; // device_name
- cout << setw (6) << sqlite3_column_int64 (stmt, 1) << " | "; // seq_no
- cout << setw (20) << lexical_cast<string> (Name (sqlite3_column_blob (stmt, 2), sqlite3_column_bytes (stmt, 2))) << " | "; // locator
- if (sqlite3_column_bytes (stmt, 3) > 0)
- {
- cout << setw (10) << sqlite3_column_text (stmt, 3) << endl;
- }
- else
- {
- cout << "unknown" << endl;
- }
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ cout << setw(30)
+ << lexical_cast<string>(Name(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0)))
+ << " | "; // device_name
+ cout << setw(6) << sqlite3_column_int64(stmt, 1) << " | "; // seq_no
+ cout << setw(20)
+ << lexical_cast<string>(Name(sqlite3_column_blob(stmt, 2), sqlite3_column_bytes(stmt, 2)))
+ << " | "; // locator
+ if (sqlite3_column_bytes(stmt, 3) > 0) {
+ cout << setw(10) << sqlite3_column_text(stmt, 3) << endl;
}
- sqlite3_finalize (stmt);
+ else {
+ cout << "unknown" << endl;
+ }
+ }
+ sqlite3_finalize(stmt);
}
void
- DumpLog ()
+ DumpLog()
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db,
- "SELECT state_hash, last_update, state_id "
- " FROM SyncLog "
- " ORDER BY last_update", -1, &stmt, 0);
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db, "SELECT state_hash, last_update, state_id "
+ " FROM SyncLog "
+ " ORDER BY last_update",
+ -1, &stmt, 0);
cout.setf(std::ios::left, std::ios::adjustfield);
cout << ">> SYNC LOG <<" << endl;
- cout << "====================================================================================" << endl;
- cout << setw(10) << "state_hash" << " | state details " << endl;
- cout << "====================================================================================" << endl;
+ cout << "===================================================================================="
+ << endl;
+ cout << setw(10) << "state_hash"
+ << " | state details " << endl;
+ cout << "===================================================================================="
+ << endl;
- while (sqlite3_step (stmt) == SQLITE_ROW)
- {
- cout << setw (10) << Hash (sqlite3_column_blob (stmt, 0), sqlite3_column_bytes (stmt, 0)).shortHash () << " | "; // state hash
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ cout << setw(10)
+ << Hash(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0)).shortHash()
+ << " | "; // state hash
- sqlite3_stmt *stmt2;
- sqlite3_prepare_v2 (m_db,
- "SELECT device_name, ss.seq_no "
- " FROM SyncStateNodes ss JOIN SyncNodes sn ON ss.device_id = sn.device_id "
- " WHERE state_id=? "
- " ORDER BY device_name", -1, &stmt2, 0);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
- sqlite3_bind_int64 (stmt2, 1, sqlite3_column_int64 (stmt, 2));
+ sqlite3_stmt* stmt2;
+ sqlite3_prepare_v2(m_db,
+ "SELECT device_name, ss.seq_no "
+ " FROM SyncStateNodes ss JOIN SyncNodes sn ON ss.device_id = sn.device_id "
+ " WHERE state_id=? "
+ " ORDER BY device_name",
+ -1, &stmt2, 0);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
+ sqlite3_bind_int64(stmt2, 1, sqlite3_column_int64(stmt, 2));
- while (sqlite3_step (stmt2) == SQLITE_ROW)
- {
- cout << lexical_cast<string> (Name (sqlite3_column_blob (stmt2, 0), sqlite3_column_bytes (stmt2, 0)))
- << "("
- << sqlite3_column_int64 (stmt2, 1)
- << "); ";
- }
-
- sqlite3_finalize (stmt2);
-
- cout << endl;
+ while (sqlite3_step(stmt2) == SQLITE_ROW) {
+ cout << lexical_cast<string>(
+ Name(sqlite3_column_blob(stmt2, 0), sqlite3_column_bytes(stmt2, 0)))
+ << "(" << sqlite3_column_int64(stmt2, 1) << "); ";
}
- sqlite3_finalize (stmt);
+
+ sqlite3_finalize(stmt2);
+
+ cout << endl;
+ }
+ sqlite3_finalize(stmt);
}
};
class ActionLogDumper : public DbHelper
{
public:
- ActionLogDumper (const filesystem::path &path)
- : DbHelper (path / ".chronoshare", "action-log.db")
+ ActionLogDumper(const filesystem::path& path)
+ : DbHelper(path / ".chronoshare", "action-log.db")
{
}
void
- Dump ()
+ Dump()
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db,
- "SELECT device_name, seq_no, action, filename, version, file_hash, file_seg_num, parent_device_name, parent_seq_no "
- " FROM ActionLog "
- " ORDER BY action_timestamp", -1, &stmt, 0);
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db,
+ "SELECT device_name, seq_no, action, filename, version, file_hash, file_seg_num, parent_device_name, parent_seq_no "
+ " FROM ActionLog "
+ " ORDER BY action_timestamp",
+ -1, &stmt, 0);
cout.setf(std::ios::left, std::ios::adjustfield);
cout << ">> ACTION LOG <<" << endl;
- cout << "=============================================================================================================================================================================" << endl;
- cout << setw(30) << "device_name" << " | seq_no | action |" << setw(40) << " filename " << " | version | file_hash | seg_num | parent_device_name | parent_seq_no" << endl;
- cout << "=============================================================================================================================================================================" << endl;
+ cout << "============================================================================================================================================================================="
+ << endl;
+ cout << setw(30) << "device_name"
+ << " | seq_no | action |" << setw(40) << " filename "
+ << " | version | file_hash | seg_num | parent_device_name | parent_seq_no"
+ << endl;
+ cout << "============================================================================================================================================================================="
+ << endl;
- while (sqlite3_step (stmt) == SQLITE_ROW)
- {
- cout << setw (30) << lexical_cast<string> (Name (sqlite3_column_blob (stmt, 0), sqlite3_column_bytes (stmt, 0))) << " | "; // device_name
- cout << setw (6) << sqlite3_column_int64 (stmt, 1) << " | "; // seq_no
- cout << setw (6) << (sqlite3_column_int (stmt, 2)==0?"UPDATE":"DELETE") << " | "; // action
- cout << setw (40) << sqlite3_column_text (stmt, 3) << " | "; // filename
- cout << setw (7) << sqlite3_column_int64 (stmt, 4) << " | "; // version
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ cout << setw(30)
+ << lexical_cast<string>(Name(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0)))
+ << " | "; // device_name
+ cout << setw(6) << sqlite3_column_int64(stmt, 1) << " | "; // seq_no
+ cout << setw(6) << (sqlite3_column_int(stmt, 2) == 0 ? "UPDATE" : "DELETE") << " | "; // action
+ cout << setw(40) << sqlite3_column_text(stmt, 3) << " | "; // filename
+ cout << setw(7) << sqlite3_column_int64(stmt, 4) << " | "; // version
- if (sqlite3_column_int (stmt, 2) == 0)
- {
- cout << setw (10) << Hash (sqlite3_column_blob (stmt, 5), sqlite3_column_bytes (stmt, 5)).shortHash () << " | ";
- cout << setw (7) << sqlite3_column_int64 (stmt, 6) << " | "; // seg_num
- }
- else
- cout << " | | ";
-
- if (sqlite3_column_bytes (stmt, 7) > 0)
- {
- cout << setw (30) << lexical_cast<string> (Name (sqlite3_column_blob (stmt, 7), sqlite3_column_bytes (stmt, 7))) << " | "; // parent_device_name
- cout << setw (5) << sqlite3_column_int64 (stmt, 8); // seq_no
- }
- else
- cout << setw (30) << " " << " | ";
- cout << endl;
+ if (sqlite3_column_int(stmt, 2) == 0) {
+ cout << setw(10)
+ << Hash(sqlite3_column_blob(stmt, 5), sqlite3_column_bytes(stmt, 5)).shortHash()
+ << " | ";
+ cout << setw(7) << sqlite3_column_int64(stmt, 6) << " | "; // seg_num
}
+ else
+ cout << " | | ";
- sqlite3_finalize (stmt);
+ if (sqlite3_column_bytes(stmt, 7) > 0) {
+ cout << setw(30) << lexical_cast<string>(
+ Name(sqlite3_column_blob(stmt, 7), sqlite3_column_bytes(stmt, 7)))
+ << " | "; // parent_device_name
+ cout << setw(5) << sqlite3_column_int64(stmt, 8); // seq_no
+ }
+ else
+ cout << setw(30) << " "
+ << " | ";
+ cout << endl;
+ }
+
+ sqlite3_finalize(stmt);
}
void
- DumpActionData(const Ndnx::Name &deviceName, int64_t seqno)
+ DumpActionData(const Ccnx::Name& deviceName, int64_t seqno)
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db, "SELECT action_content_object, action_name FROM ActionLog WHERE device_name = ? and seq_no = ?", -1, &stmt, 0);
- Ndnx::NdnxCharbufPtr device_name = deviceName.toNdnxCharbuf();
- sqlite3_bind_blob (stmt, 1, device_name->buf(), device_name->length(), SQLITE_STATIC);
- sqlite3_bind_int64 (stmt, 2, seqno);
- cout << "Dumping action data for: [" << deviceName << ", " << seqno << "]" <<endl;
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- PcoPtr pco = make_shared<ParsedContentObject> (reinterpret_cast<const unsigned char *> (sqlite3_column_blob (stmt, 0)), sqlite3_column_bytes (stmt, 0));
- Ndnx::Name actionName = Ndnx::Name(sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 0));
- if (pco)
- {
- ActionItemPtr action = deserializeMsg<ActionItem> (pco->content());
- if (action)
- {
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db,
+ "SELECT action_content_object, action_name FROM ActionLog WHERE device_name = ? and seq_no = ?",
+ -1, &stmt, 0);
+ Ccnx::CcnxCharbufPtr device_name = deviceName.toCcnxCharbuf();
+ sqlite3_bind_blob(stmt, 1, device_name->buf(), device_name->length(), SQLITE_STATIC);
+ sqlite3_bind_int64(stmt, 2, seqno);
+ cout << "Dumping action data for: [" << deviceName << ", " << seqno << "]" << endl;
+ if (sqlite3_step(stmt) == SQLITE_ROW) {
+ PcoPtr pco = make_shared<ParsedContentObject>(reinterpret_cast<const unsigned char*>(
+ sqlite3_column_blob(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0));
+ Ccnx::Name actionName = Ccnx::Name(sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 0));
+ if (pco) {
+ ActionItemPtr action = deserializeMsg<ActionItem>(pco->content());
+ if (action) {
cout << "Action data size : " << pco->content().size() << endl;
cout << "Action data name : " << actionName << endl;
string type = action->action() == ActionItem::UPDATE ? "UPDATE" : "DELETE";
@@ -198,27 +219,23 @@
cout << "Timestamp = " << action->timestamp() << endl;
string filename = action->filename();
cout << "Filename = " << filename << endl;
- if (action->has_seg_num())
- {
+ if (action->has_seg_num()) {
cout << "Segment number = " << action->seg_num() << endl;
}
- if (action->has_file_hash())
- {
- cout << "File hash = " << Hash(action->file_hash().c_str(), action->file_hash().size()) << endl;
+ if (action->has_file_hash()) {
+ cout << "File hash = " << Hash(action->file_hash().c_str(), action->file_hash().size())
+ << endl;
}
}
- else
- {
+ else {
cerr << "Error! Failed to parse action from pco! " << endl;
}
}
- else
- {
+ else {
cerr << "Error! Invalid pco! " << endl;
}
}
- else
- {
+ else {
cerr << "Error! Can not find the requested action" << endl;
}
sqlite3_finalize(stmt);
@@ -228,108 +245,108 @@
class FileStateDumper : public DbHelper
{
public:
- FileStateDumper (const filesystem::path &path)
- : DbHelper (path / ".chronoshare", "file-state.db")
+ FileStateDumper(const filesystem::path& path)
+ : DbHelper(path / ".chronoshare", "file-state.db")
{
}
void
- Dump ()
+ Dump()
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db,
- "SELECT filename,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,directory,is_complete "
- " FROM FileState "
- " WHERE type = 0 ORDER BY filename", -1, &stmt, 0);
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db,
+ "SELECT filename,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,directory,is_complete "
+ " FROM FileState "
+ " WHERE type = 0 ORDER BY filename",
+ -1, &stmt, 0);
cout.setf(std::ios::left, std::ios::adjustfield);
cout << ">> FILE STATE <<" << endl;
- cout << "===================================================================================================================================" << endl;
- cout << "filename | device_name | seq_no | file_hash | seg_num | directory | is_complete" << endl;
- cout << "===================================================================================================================================" << endl;
+ cout << "==================================================================================================================================="
+ << endl;
+ cout << "filename | device_name | seq_no | file_hash | seg_num | directory | is_complete"
+ << endl;
+ cout << "==================================================================================================================================="
+ << endl;
- while (sqlite3_step (stmt) == SQLITE_ROW)
- {
- cout << setw (40) << sqlite3_column_text (stmt, 0) << " | ";
- cout << setw (30) << lexical_cast<string> (Name (sqlite3_column_blob (stmt, 1), sqlite3_column_bytes (stmt, 1))) << " | ";
- cout << setw (6) << sqlite3_column_int64 (stmt, 2) << " | ";
- cout << setw (10) << Hash (sqlite3_column_blob (stmt, 3), sqlite3_column_bytes (stmt, 3)).shortHash () << " | ";
- cout << setw (6) << sqlite3_column_int64 (stmt, 6) << " | ";
- if (sqlite3_column_bytes (stmt, 7) == 0)
- cout << setw (20) << "<NULL>" << " | ";
- else
- cout << setw (20) << sqlite3_column_text (stmt, 7) << " | ";
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ cout << setw(40) << sqlite3_column_text(stmt, 0) << " | ";
+ cout << setw(30)
+ << lexical_cast<string>(Name(sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 1)))
+ << " | ";
+ cout << setw(6) << sqlite3_column_int64(stmt, 2) << " | ";
+ cout << setw(10)
+ << Hash(sqlite3_column_blob(stmt, 3), sqlite3_column_bytes(stmt, 3)).shortHash() << " | ";
+ cout << setw(6) << sqlite3_column_int64(stmt, 6) << " | ";
+ if (sqlite3_column_bytes(stmt, 7) == 0)
+ cout << setw(20) << "<NULL>"
+ << " | ";
+ else
+ cout << setw(20) << sqlite3_column_text(stmt, 7) << " | ";
- if (sqlite3_column_int (stmt, 8) == 0)
- cout << setw (20) << "no" << endl;
- else
- cout << setw (20) << "yes" << endl;
- }
+ if (sqlite3_column_int(stmt, 8) == 0)
+ cout << setw(20) << "no" << endl;
+ else
+ cout << setw(20) << "yes" << endl;
+ }
- sqlite3_finalize (stmt);
+ sqlite3_finalize(stmt);
}
};
-int main(int argc, char *argv[])
+int
+main(int argc, char* argv[])
{
- INIT_LOGGERS ();
+ INIT_LOGGERS();
- if (argc != 3 && !(argc == 5 && string(argv[1]) == "action"))
- {
- cerr << "Usage: ./dump-db state|action|file|all <path-to-shared-folder>" << endl;
- cerr << " or: ./dump-db action <path-to-shared-folder> <device-name> <seq-no>" << endl;
- return 1;
- }
+ if (argc != 3 && !(argc == 5 && string(argv[1]) == "action")) {
+ cerr << "Usage: ./dump-db state|action|file|all <path-to-shared-folder>" << endl;
+ cerr << " or: ./dump-db action <path-to-shared-folder> <device-name> <seq-no>" << endl;
+ return 1;
+ }
string type = argv[1];
- if (type == "state")
- {
- StateLogDumper dumper (argv[2]);
- dumper.DumpState ();
- dumper.DumpLog ();
+ if (type == "state") {
+ StateLogDumper dumper(argv[2]);
+ dumper.DumpState();
+ dumper.DumpLog();
+ }
+ else if (type == "action") {
+ ActionLogDumper dumper(argv[2]);
+ if (argc == 5) {
+ dumper.DumpActionData(string(argv[3]), boost::lexical_cast<int64_t>(argv[4]));
}
- else if (type == "action")
- {
- ActionLogDumper dumper (argv[2]);
- if (argc == 5)
- {
- dumper.DumpActionData(string(argv[3]), boost::lexical_cast<int64_t>(argv[4]));
- }
- else
- {
- dumper.Dump ();
- }
+ else {
+ dumper.Dump();
}
- else if (type == "file")
+ }
+ else if (type == "file") {
+ FileStateDumper dumper(argv[2]);
+ dumper.Dump();
+ }
+ else if (type == "all") {
{
- FileStateDumper dumper (argv[2]);
- dumper.Dump ();
+ StateLogDumper dumper(argv[2]);
+ dumper.DumpState();
+ dumper.DumpLog();
}
- else if (type == "all")
- {
- {
- StateLogDumper dumper (argv[2]);
- dumper.DumpState ();
- dumper.DumpLog ();
- }
- {
- ActionLogDumper dumper (argv[2]);
- dumper.Dump ();
- }
-
- {
- FileStateDumper dumper (argv[2]);
- dumper.Dump ();
- }
- }
- else
{
- cerr << "ERROR: Wrong database type" << endl;
- cerr << "\nUsage: ./dump-db state|action|file|all <path-to-shared-folder>" << endl;
- return 1;
+ ActionLogDumper dumper(argv[2]);
+ dumper.Dump();
}
+ {
+ FileStateDumper dumper(argv[2]);
+ dumper.Dump();
+ }
+ }
+ else {
+ cerr << "ERROR: Wrong database type" << endl;
+ cerr << "\nUsage: ./dump-db state|action|file|all <path-to-shared-folder>" << endl;
+ return 1;
+ }
+
return 0;
}