#include "EventTypes/iEvent.h"
#include "EventTypes/PhoneCall.h"
#include "EventTypes/SMS.h"
+#include "RtcomEventLoggerComponents/TriggerDisabler.h"
#include "Settings.h"
#include <QDebug>
QDebug operator<<(QDebug, QList<RTComElAttachment*> &);
RtcomEventLogger::RtcomEventLogger(const Settings &settings) :
- m_Settings(settings), mk_DBPath("/.rtcom-eventlogger/el-v1.db")
+ m_Settings(settings)
{
RTComEl *el(rtcom_el_new());
if(NULL != el)
}
RtcomEventLogger::RtcomEventLogger(const Settings &settings, const EventTypes::RtcomEvent &event) :
- m_Settings(settings), mk_DBPath("/.rtcom-eventlogger/el-v1.db")
+ m_Settings(settings)
{
}
{
RTComEl *el_nonconst(const_cast<RTComEl *>(&el));
- bool incoming = CurrentSettings().ShouldProcess( Settings::TYPE_RECIEVED, service);
- bool outgoing = CurrentSettings().ShouldProcess( Settings::TYPE_SENT, service);
+ bool incoming = CurrentSettings().ShouldProcess( Settings::INCOMING, service);
+ bool outgoing = CurrentSettings().ShouldProcess( Settings::OUTGOING, service);
if(incoming || outgoing)
{
QList<RTComElAttachment *> rattachments;
RTComElAttachIter *at_it = rtcom_el_iter_get_attachments(it);
- if(it != NULL)
+ if(at_it != NULL)
{
qDebug() << "Attachments OK";
if(rtcom_el_attach_iter_first(at_it))
return NULL;
}
+void RtcomEventLogger::PreInsert()
+{
+ m_TriggerDisabler = new RtcomEventLoggerComponents::TriggerDisabler(CurrentSettings());
+}
+
void RtcomEventLogger::Insert(EventTypes::iEvent &event, const NumberToNameLookup &numberToNameLookup)
{
if(EventTypes::RtcomEvent *rtcomEvent = dynamic_cast<EventTypes::RtcomEvent *>(&event))
// Add the event
QDateTime startTime(QDateTime::currentDateTimeUtc());
int newEventID(-1);
+ int currentBackoffInMillisecs(5);
while(((newEventID = rtcom_el_add_event_full(el, revent, rheaders, rattachments, &error)) == -1)
- && startTime.msecsTo(QDateTime::currentDateTimeUtc()) < 1000)
+ && startTime.msecsTo(QDateTime::currentDateTimeUtc()) < 10000)
{
if(error != NULL)
{
qDebug() << "err: " << error->message;
- qDebug() << *revent << "\n";
g_error_free(error);
error = NULL;
}
mutex.lock();
QWaitCondition waitCondition;
- waitCondition.wait(&mutex, 5);
+ waitCondition.wait(&mutex, currentBackoffInMillisecs);
mutex.unlock();
+
+ // Exponential backoff...
+ currentBackoffInMillisecs *= 2;
}
if(-1 == newEventID)
{
+ qDebug() << "Unable to insert event due to error.";
+ qDebug() << *revent << "\n";
+ }
+ else
+ {
qDebug() << "new id: " << newEventID;
InsertedIDs().append(newEventID);
}
- else
- qDebug() << "Unable to insert event due to error.";
// Release the attachments
g_list_foreach (rattachments, (GFunc) rtcom_el_free_attachment, NULL);
// Reorder the DB IDs as Nokia are guilty of both premature
// optimisation as well as closed source UIs...
Reindex();
+
+ delete m_TriggerDisabler;
}
void RtcomEventLogger::ClearInsertedIDs()
void RtcomEventLogger::Reindex()
{
// Set up the database connection...
- QSqlDatabase db(QSqlDatabase::addDatabase( "QSQLITE" ));
+ QSqlDatabase db(QSqlDatabase::addDatabase("QSQLITE"));
- db.setDatabaseName( QDir::homePath() + mk_DBPath );
- if ( ! db.open() )
+ db.setDatabaseName(CurrentSettings().DBPath());
+ if(!db.open())
{
throw std::runtime_error("Cannot open database: Unable to establish database connection");
}
if(min == 0)
min = one;
- qDebug() << "( " << one << ", " << two << " )";
+ //qDebug() << "( " << one << ", " << two << " )";
mapping.insert(one, two);
}
}
int val(min);
sequence.append(0);
sequence.append(val);
- qDebug().nospace() << "val1: " << val << ", ";
+ //qDebug().nospace() << "val1: " << val << ", ";
while((val = mapping[val]) && val != min)
{
sequence.append(val);
- qDebug().nospace() << val << ", ";
+ //qDebug().nospace() << val << ", ";
}
sequence.append(0);
- qDebug().nospace() << "seq: ";
+ //qDebug().nospace() << "seq: ";
QList<QPair<int,int> > updates;
int last(sequence.first());
foreach(int seq, sequence)
{
if(seq != last)
{
- qDebug().nospace() << seq << ", " << last << ", ";
+ //qDebug().nospace() << seq << ", " << last << ", ";
updates.append(QPair<int,int>(seq, last));
}
}
}
- qDebug() << query;
+ //qDebug() << query;
QSqlQuery * UpdateQuery(new QSqlQuery( db ));
if(UpdateQuery != NULL)
{
for( QStringList::const_iterator currentStatement(statements.constBegin()); currentStatement != statements.constEnd(); ++currentStatement)
{
- if ( UpdateQuery->exec( *currentStatement ))
- qDebug() << "Query OK, " << UpdateQuery->numRowsAffected() << " rows affected.";
- else
+ if (!UpdateQuery->exec(*currentStatement))
{
qDebug() << "Query Failed: " << *currentStatement;
throw std::exception();
dbg.nospace() << "\tservice:\t" << event.fld_service << "\n";
dbg.nospace() << "\tevt_typ_id:\t" << event.fld_event_type_id << "\n";
dbg.nospace() << "\tevt_typ:\t" << event.fld_event_type << "\n";
- dbg.nospace() << "\tstore-time:\t" << QDateTime::fromTime_t(event.fld_storage_time) << "\n";
- dbg.nospace() << "\tstart-time:\t" << QDateTime::fromTime_t(event.fld_start_time) << "\n";
- dbg.nospace() << "\tend-time:\t\t" << QDateTime::fromTime_t(event.fld_end_time) << "\n";
- dbg.nospace() << "\tis-read:\t\t" << (event.fld_is_read ? "true" : "false") << "\n";
+ dbg.nospace() << "\tstore-time:\t" << QDateTime::fromTime_t(event.fld_storage_time).toUTC() << "\n";
+ dbg.nospace() << "\tstart-time:\t" << QDateTime::fromTime_t(event.fld_start_time).toUTC() << "\n";
+ dbg.nospace() << "\tend-time:\t" << QDateTime::fromTime_t(event.fld_end_time).toUTC() << "\n";
+ dbg.nospace() << "\tis-read:\t" << (event.fld_is_read ? "true" : "false") << "\n";
dbg.nospace() << "\tdirection:\t" << (event.fld_outgoing ? "Outgoing" : "Incoming") << "\n";
dbg.nospace() << "\tflags:\t\t" << "0x" << QString::number(event.fld_flags, 16) << "\n";
dbg.nospace() << "\tbytes sent:\t" << event.fld_bytes_sent << "\n";
dbg.nospace() << "\tlocal-name:\t" << event.fld_local_name << "\n";
dbg.nospace() << "\tremote-uid:\t" << event.fld_remote_uid << "\n";
dbg.nospace() << "\tremote-name:\t" << event.fld_remote_name << "\n";
+ dbg.nospace() << "\tremote-ebid:\t" << event.fld_remote_ebook_uid << "\n";
dbg.nospace() << "\tchannel:\t\t" << event.fld_channel << "\n";
dbg.nospace() << "\tfree-text:\t" << event.fld_free_text << "\n";
dbg.nospace() << "\tgroup-uid:\t" << event.fld_group_uid << "\n";