Update style to (almost) conform to ndn-cxx style using clang-format
diff --git a/src/object-db.cpp b/src/object-db.cpp
index 3b1a0f2..fd4223e 100644
--- a/src/object-db.cpp
+++ b/src/object-db.cpp
@@ -19,13 +19,13 @@
*/
#include "object-db.h"
-#include <iostream>
-#include <boost/make_shared.hpp>
#include "db-helper.h"
-#include <sys/stat.h>
#include "logging.h"
+#include <boost/make_shared.hpp>
+#include <iostream>
+#include <sys/stat.h>
-INIT_LOGGER ("Object.Db");
+INIT_LOGGER("Object.Db");
using namespace std;
using namespace Ndnx;
@@ -44,133 +44,132 @@
CREATE INDEX device ON File(device_name); \n\
";
-ObjectDb::ObjectDb (const fs::path &folder, const std::string &hash)
- : m_lastUsed (time(NULL))
+ObjectDb::ObjectDb(const fs::path& folder, const std::string& hash)
+ : m_lastUsed(time(NULL))
{
- fs::path actualFolder = folder / "objects" / hash.substr (0, 2);
- fs::create_directories (actualFolder);
+ fs::path actualFolder = folder / "objects" / hash.substr(0, 2);
+ fs::create_directories(actualFolder);
- _LOG_DEBUG ("Open " << (actualFolder / hash.substr (2, hash.size () - 2)));
+ _LOG_DEBUG("Open " << (actualFolder / hash.substr(2, hash.size() - 2)));
- int res = sqlite3_open((actualFolder / hash.substr (2, hash.size () - 2)).c_str (), &m_db);
- if (res != SQLITE_OK)
- {
- BOOST_THROW_EXCEPTION (Error::Db ()
- << errmsg_info_str ("Cannot open/create dabatabase: [" +
- (actualFolder / hash.substr (2, hash.size () - 2)).string () + "]"));
- }
+ int res = sqlite3_open((actualFolder / hash.substr(2, hash.size() - 2)).c_str(), &m_db);
+ if (res != SQLITE_OK) {
+ BOOST_THROW_EXCEPTION(Error::Db() << errmsg_info_str(
+ "Cannot open/create dabatabase: [" +
+ (actualFolder / hash.substr(2, hash.size() - 2)).string() + "]"));
+ }
// Alex: determine if tables initialized. if not, initialize... not sure what is the best way to go...
// for now, just attempt to create everything
- 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);
- }
+ 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);
+ }
// _LOG_DEBUG ("open db");
- willStartSave ();
+ willStartSave();
}
bool
-ObjectDb::DoesExist (const boost::filesystem::path &folder, const Ndnx::Name &deviceName, const std::string &hash)
+ObjectDb::DoesExist(const boost::filesystem::path& folder, const Ccnx::Name& deviceName,
+ const std::string& hash)
{
- fs::path actualFolder = folder / "objects" / hash.substr (0, 2);
+ fs::path actualFolder = folder / "objects" / hash.substr(0, 2);
bool retval = false;
- sqlite3 *db;
- int res = sqlite3_open((actualFolder / hash.substr (2, hash.size () - 2)).c_str (), &db);
- if (res == SQLITE_OK)
- {
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (db, "SELECT count(*), count(nullif(content_object,0)) FROM File WHERE device_name=?", -1, &stmt, 0);
+ sqlite3* db;
+ int res = sqlite3_open((actualFolder / hash.substr(2, hash.size() - 2)).c_str(), &db);
+ if (res == SQLITE_OK) {
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(db,
+ "SELECT count(*), count(nullif(content_object,0)) FROM File WHERE device_name=?",
+ -1, &stmt, 0);
- NdnxCharbufPtr buf = deviceName.toNdnxCharbuf ();
- sqlite3_bind_blob (stmt, 1, buf->buf (), buf->length (), SQLITE_TRANSIENT);
+ CcnxCharbufPtr buf = deviceName.toCcnxCharbuf();
+ sqlite3_bind_blob(stmt, 1, buf->buf(), buf->length(), SQLITE_TRANSIENT);
- int res = sqlite3_step (stmt);
- if (res == SQLITE_ROW)
- {
- int countAll = sqlite3_column_int (stmt, 0);
- int countNonNull = sqlite3_column_int (stmt, 1);
+ int res = sqlite3_step(stmt);
+ if (res == SQLITE_ROW) {
+ int countAll = sqlite3_column_int(stmt, 0);
+ int countNonNull = sqlite3_column_int(stmt, 1);
- _LOG_TRACE ("Total segments: " << countAll << ", non-empty segments: " << countNonNull);
+ _LOG_TRACE("Total segments: " << countAll << ", non-empty segments: " << countNonNull);
- if (countAll > 0 && countAll==countNonNull)
- {
- retval = true;
- }
- }
-
- sqlite3_finalize (stmt);
+ if (countAll > 0 && countAll == countNonNull) {
+ retval = true;
+ }
}
- sqlite3_close (db);
+ sqlite3_finalize(stmt);
+ }
+
+ sqlite3_close(db);
return retval;
}
-ObjectDb::~ObjectDb ()
+ObjectDb::~ObjectDb()
{
- didStopSave ();
+ didStopSave();
// _LOG_DEBUG ("close db");
- int res = sqlite3_close (m_db);
- if (res != SQLITE_OK)
- {
- // complain
- }
+ int res = sqlite3_close(m_db);
+ if (res != SQLITE_OK) {
+ // complain
+ }
}
void
-ObjectDb::saveContentObject (const Ndnx::Name &deviceName, sqlite3_int64 segment, const Ndnx::Bytes &data)
+ObjectDb::saveContentObject(const Ccnx::Name& deviceName, sqlite3_int64 segment,
+ const Ccnx::Bytes& data)
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db, "INSERT INTO File "
- "(device_name, segment, content_object) "
- "VALUES (?, ?, ?)", -1, &stmt, 0);
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db, "INSERT INTO File "
+ "(device_name, segment, content_object) "
+ "VALUES (?, ?, ?)",
+ -1, &stmt, 0);
//_LOG_DEBUG ("Saving content object for [" << deviceName << ", seqno: " << segment << ", size: " << data.size () << "]");
- NdnxCharbufPtr buf = deviceName.toNdnxCharbuf ();
- sqlite3_bind_blob (stmt, 1, buf->buf (), buf->length (), SQLITE_STATIC);
- sqlite3_bind_int64 (stmt, 2, segment);
- sqlite3_bind_blob (stmt, 3, &data[0], data.size (), SQLITE_STATIC);
+ CcnxCharbufPtr buf = deviceName.toCcnxCharbuf();
+ sqlite3_bind_blob(stmt, 1, buf->buf(), buf->length(), SQLITE_STATIC);
+ sqlite3_bind_int64(stmt, 2, segment);
+ sqlite3_bind_blob(stmt, 3, &data[0], data.size(), SQLITE_STATIC);
- sqlite3_step (stmt);
+ sqlite3_step(stmt);
//_LOG_DEBUG ("After saving object: " << sqlite3_errmsg (m_db));
- sqlite3_finalize (stmt);
+ sqlite3_finalize(stmt);
// update last used time
m_lastUsed = time(NULL);
}
-Ndnx::BytesPtr
-ObjectDb::fetchSegment (const Ndnx::Name &deviceName, sqlite3_int64 segment)
+Ccnx::BytesPtr
+ObjectDb::fetchSegment(const Ccnx::Name& deviceName, sqlite3_int64 segment)
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db, "SELECT content_object FROM File WHERE device_name=? AND segment=?", -1, &stmt, 0);
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db, "SELECT content_object FROM File WHERE device_name=? AND segment=?", -1,
+ &stmt, 0);
- NdnxCharbufPtr buf = deviceName.toNdnxCharbuf ();
- sqlite3_bind_blob (stmt, 1, buf->buf (), buf->length (), SQLITE_TRANSIENT);
- sqlite3_bind_int64 (stmt, 2, segment);
+ CcnxCharbufPtr buf = deviceName.toCcnxCharbuf();
+ sqlite3_bind_blob(stmt, 1, buf->buf(), buf->length(), SQLITE_TRANSIENT);
+ sqlite3_bind_int64(stmt, 2, segment);
BytesPtr ret;
- int res = sqlite3_step (stmt);
- if (res == SQLITE_ROW)
- {
- const unsigned char *buf = reinterpret_cast<const unsigned char*> (sqlite3_column_blob (stmt, 0));
- int bufBytes = sqlite3_column_bytes (stmt, 0);
+ int res = sqlite3_step(stmt);
+ if (res == SQLITE_ROW) {
+ const unsigned char* buf = reinterpret_cast<const unsigned char*>(sqlite3_column_blob(stmt, 0));
+ int bufBytes = sqlite3_column_bytes(stmt, 0);
- ret = make_shared<Bytes> (buf, buf+bufBytes);
- }
+ ret = make_shared<Bytes>(buf, buf + bufBytes);
+ }
- sqlite3_finalize (stmt);
+ sqlite3_finalize(stmt);
// update last used time
m_lastUsed = time(NULL);
@@ -202,15 +201,15 @@
// }
void
-ObjectDb::willStartSave ()
+ObjectDb::willStartSave()
{
- sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
+ sqlite3_exec(m_db, "BEGIN TRANSACTION;", 0, 0, 0);
// _LOG_DEBUG ("Open transaction: " << sqlite3_errmsg (m_db));
}
void
-ObjectDb::didStopSave ()
+ObjectDb::didStopSave()
{
- sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
+ sqlite3_exec(m_db, "END TRANSACTION;", 0, 0, 0);
// _LOG_DEBUG ("Close transaction: " << sqlite3_errmsg (m_db));
}