24#include "ns3/nstime.h"
33 int rc = sqlite3_open (name.c_str (), &
m_db);
41 rc = sqlite3_close_v2 (
m_db);
49 SpinExec (
"PRAGMA journal_mode = MEMORY");
102 return sqlite3_column_int (stmt, pos);
110 return static_cast<uint32_t> (sqlite3_column_int (stmt, pos));
118 return sqlite3_column_double (stmt, pos);
123SQLiteOutput::Bind ([[maybe_unused]] sqlite3_stmt *stmt, [[maybe_unused]]
int pos, [[maybe_unused]]
const T &value)
const
134 if (sqlite3_bind_double (stmt, pos, value.
GetSeconds ()) == SQLITE_OK)
146 if (sqlite3_bind_double (stmt, pos, value) == SQLITE_OK)
158 if (sqlite3_bind_int (stmt, pos,
static_cast<int> (value)) == SQLITE_OK)
170 if (sqlite3_bind_int64 (stmt, pos, value) == SQLITE_OK)
182 if (sqlite3_bind_int64 (stmt, pos, value) == SQLITE_OK)
194 if (sqlite3_bind_int (stmt, pos,
static_cast<int> (value)) == SQLITE_OK)
206 if (sqlite3_bind_int (stmt, pos,
static_cast<int> (value)) == SQLITE_OK)
218 if (sqlite3_bind_int (stmt, pos, value) == SQLITE_OK)
230 if (sqlite3_bind_text (stmt, pos, value.c_str (), -1, SQLITE_STATIC) == SQLITE_OK)
242 sem_t *sem = sem_open (
m_semName.c_str (), O_CREAT, S_IRUSR | S_IWUSR, 1);
245 "FAILED to open system semaphore, errno: " << errno);
247 if (sem_wait (sem) == 0)
249 rc = sqlite3_prepare_v2 (db,
cmd.c_str (),
250 static_cast<int> (
cmd.size ()),
279 rc = sqlite3_prepare_v2 (db,
cmd.c_str (),
280 static_cast<int> (
cmd.size ()),
283 while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
293 rc = sqlite3_step (stmt);
295 while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
306 rc = sqlite3_finalize (stmt);
308 while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
319 rc = sqlite3_reset (stmt);
321 while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
334 sem_t *sem,
bool hardExit)
336 if (rc != SQLITE_OK && rc != SQLITE_DONE)
349 std::cerr << sqlite3_errmsg (db) << std::endl;
387 ret =
CheckError (db, rc,
"",
nullptr,
false);
401 int rc = SQLITE_ERROR;
403 sem_t *sem = sem_open (
m_semName.c_str (), O_CREAT, S_IRUSR | S_IWUSR, 1);
406 "FAILED to open system semaphore, errno: " << errno);
408 if (sem_wait (sem) == 0)
437 int rc = SQLITE_ERROR;
439 sem_t *sem = sem_open (
m_semName.c_str (), O_CREAT, S_IRUSR | S_IWUSR, 1);
442 "FAILED to open system semaphore, errno: " << errno);
444 if (sem_wait (sem) == 0)
sqlite3 * m_db
Database pointer.
bool SpinExec(const std::string &cmd) const
Execute a command until the return value is OK or an ERROR.
~SQLiteOutput()
Destructor.
static bool CheckError(sqlite3 *db, int rc, const std::string &cmd, sem_t *sem, bool hardExit)
Check any error in the db.
static int SpinStep(sqlite3_stmt *stmt)
Execute a step operation on a statement until the result is ok or an error.
SQLiteOutput(const std::string &name, const std::string &semName)
SQLiteOutput constructor.
void SetJournalInMemory()
Instruct SQLite to store the journal in memory.
T RetrieveColumn(sqlite3_stmt *stmt, int pos) const
Retrieve a value from an executed statement.
bool Bind(sqlite3_stmt *stmt, int pos, const T &value) const
Bind a value to a sqlite statement.
std::string m_semName
System semaphore name.
static int SpinReset(sqlite3_stmt *stmt)
Reset a statement until the result is ok or an error.
static int SpinFinalize(sqlite3_stmt *stmt)
Finalize a statement until the result is ok or an error.
bool WaitExec(const std::string &cmd) const
Execute a command, waiting on a system semaphore.
static void Error(sqlite3 *db, const std::string &cmd)
Fail, printing an error message from sqlite.
bool SpinPrepare(sqlite3_stmt **stmt, const std::string &cmd) const
Prepare a statement.
bool WaitPrepare(sqlite3_stmt **stmt, const std::string &cmd) const
Prepare a statement, waiting on a system semaphore.
Simulation virtual time values and global simulation resolution.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.