#define DB_COLUMN_S0 (3)
#define DB_PREFETCH_LEN (6)
+#define DB_BACKUP_TIMEOUT (60)
std::unique_ptr<Database> Database::m_instance;
}
Database::Database (void)
- : m_db (NULL),
- m_timeout_id (0)
+ : m_db (NULL)
+ , m_timeout_id (0)
+ , m_timer (g_timer_new ())
{
open ();
}
Database::~Database (void)
{
+ g_timer_destroy (m_timer);
if (m_timeout_id != 0) {
saveUserDB ();
g_source_remove (m_timeout_id);
{
Database *self = static_cast<Database*> (data);
- if (self->saveUserDB ()) {
+ /* Get elapsed time since last modification of database. */
+ guint elapsed = (guint)g_timer_elapsed (self->m_timer, NULL);
+
+ if (elapsed >= DB_BACKUP_TIMEOUT &&
+ self->saveUserDB ()) {
self->m_timeout_id = 0;
return FALSE;
}
void
Database::modified (void)
{
+ /* Restart the timer */
+ g_timer_start (m_timer);
+
if (m_timeout_id != 0)
return;
- m_timeout_id = g_timeout_add (60000, // one minute
- Database::timeoutCallback,
- static_cast<gpointer> (this));
+ m_timeout_id = g_timeout_add_seconds (DB_BACKUP_TIMEOUT,
+ Database::timeoutCallback,
+ static_cast<gpointer> (this));
}
inline static gboolean