From: Jamie Thompson Date: Sat, 1 Oct 2011 22:55:37 +0000 (+0100) Subject: Added utility method for looking up flag values in Rtcom database. Whoever thought... X-Git-Url: http://git.maemo.org/git/?p=qwerkisync;a=commitdiff_plain;h=6f10c189c55e152e9e81f92ff04a082be3a0d167 Added utility method for looking up flag values in Rtcom database. Whoever thought it a good idea...well... --- diff --git a/EventTypes/RtcomEvent.cpp b/EventTypes/RtcomEvent.cpp index cb0942f..b595858 100644 --- a/EventTypes/RtcomEvent.cpp +++ b/EventTypes/RtcomEvent.cpp @@ -16,9 +16,17 @@ * . */ +#include "RtcomEvent.h" + +#include + +#include +#include + #include +#include -#include "RtcomEvent.h" +#include using namespace EventTypes; @@ -30,3 +38,33 @@ void RtcomEvent::freeRTComContents(RTComElEvent &event) { rtcom_el_event_free_contents(&event); } + +const unsigned int RtcomEvent::GetFlagValue(const QString &value) const +{ + static QHash valueLookups; + + if(!valueLookups.contains(value)) + { + RTComEl *el(rtcom_el_new()); + if(NULL != el) + { + gint flagValue; + if(-1 != (flagValue = rtcom_el_get_flag_value(el, value.toUtf8()))) + valueLookups.insert(value, flagValue); + + g_object_unref(el); + + if(-1 == flagValue) + { + throw std::runtime_error( + QString("Unable to find flag value '%1'' in rtcom database") + .arg(value).toStdString()); + } + } + else + qDebug() << "Failed to create event logger."; + } + + return valueLookups.value(value); +} + diff --git a/EventTypes/RtcomEvent.h b/EventTypes/RtcomEvent.h index 27e44fb..c4a1341 100644 --- a/EventTypes/RtcomEvent.h +++ b/EventTypes/RtcomEvent.h @@ -22,6 +22,7 @@ #include "iEvent.h" #include // Needed for default value +class QString; class _RTComElAttachment; typedef _RTComElAttachment RTComElAttachment; @@ -44,6 +45,8 @@ namespace EventTypes virtual RTComElEvent * toRTComEvent(const NumberToNameLookup &numberToNameLookup) const = 0; static void freeRTComContents(RTComElEvent &event); + + const unsigned int GetFlagValue(const QString &value) const; }; }