Commit a322fb9a authored by Ronan's avatar Ronan

feat(EventsDb): impl `getEventsCount`

parent abf91b06
......@@ -24,6 +24,7 @@
#include "event/call-event.h"
#include "event/event.h"
#include "event/message-event.h"
#include "logger/logger.h"
#include "events-db.h"
......@@ -39,8 +40,50 @@ class EventsDbPrivate : public AbstractDbPrivate {};
EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
void EventsDb::init () {
#ifdef SOCI_ENABLED
// -----------------------------------------------------------------------------
// Helpers.
// -----------------------------------------------------------------------------
inline string mapFilterToSqlEvent (EventsDb::Filter filter) {
switch (filter) {
case EventsDb::NoFilter:
break;
case EventsDb::MessageFilter:
return "0";
case EventsDb::CallFilter:
return "1";
case EventsDb::ConferenceFilter:
return "2";
}
return "";
}
static string buildSqlEventFilter (const list<EventsDb::Filter> &filters, EventsDb::FilterMask mask) {
bool isStart = true;
string sql;
for (const auto &filter : filters) {
if (!(mask & filter))
continue;
if (isStart) {
isStart = false;
sql += " WHERE ";
} else
sql += " OR ";
sql += " type = " + mapFilterToSqlEvent(filter);
}
return sql;
}
// -----------------------------------------------------------------------------
// Soci backend.
// -----------------------------------------------------------------------------
#ifdef SOCI_ENABLED
void EventsDb::init () {
L_D(EventsDb);
soci::session *session = d->dbSession.getBackendSession<soci::session>();
......@@ -102,75 +145,124 @@ void EventsDb::init () {
" REFERENCES message_direction(id)"
" ON DELETE CASCADE"
")";
}
#endif // ifdef SOCI_ENABLED
}
bool EventsDb::addEvent (const Event &event) {
// TODO.
switch (event.getType()) {
case Event::None:
return false;
case Event::MessageEvent:
case Event::CallStartEvent:
case Event::CallEndEvent:
break;
}
return true;
}
bool EventsDb::deleteEvent (const Event &event) {
// TODO.
(void)event;
return true;
}
void EventsDb::cleanEvents (FilterMask mask) {
// TODO.
(void)mask;
}
int EventsDb::getEventsCount (FilterMask mask) const {
L_D(const EventsDb);
string query = "SELECT COUNT(*) FROM event" +
buildSqlEventFilter({ MessageFilter, CallFilter, ConferenceFilter }, mask);
int count = 0;
L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>();
*session << query, soci::into(count);
L_END_LOG_EXCEPTION
return count;
}
int EventsDb::getMessagesCount (const string &remoteAddress) const {
// TODO.
(void)remoteAddress;
return 0;
}
int EventsDb::getUnreadMessagesCount (const string &remoteAddress) const {
// TODO.
(void)remoteAddress;
return 0;
}
list<Event> EventsDb::getHistory (const string &remoteAddress, int nLast, FilterMask mask) const {
// TODO.
(void)remoteAddress;
(void)nLast;
(void)mask;
return list<Event>();
}
list<Event> EventsDb::getHistory (const string &remoteAddress, int begin, int end, FilterMask mask) const {
// TODO.
(void)remoteAddress;
(void)begin;
(void)end;
(void)mask;
return list<Event>();
}
void EventsDb::cleanHistory (const string &remoteAddress) {
// TODO.
(void)remoteAddress;
}
// -----------------------------------------------------------------------------
// No backend.
// -----------------------------------------------------------------------------
bool EventsDb::addEvent (const Event &event) {
// TODO.
switch (event.getType()) {
case Event::None:
return false;
case Event::MessageEvent:
case Event::CallStartEvent:
case Event::CallEndEvent:
break;
#else
void EventsDb::init () {}
bool EventsDb::addEvent (const Event &) {
return false;
}
return true;
}
bool EventsDb::deleteEvent (const Event &) {
return false;
}
bool EventsDb::deleteEvent (const Event &event) {
// TODO.
(void)event;
return true;
}
void EventsDb::cleanEvents (FilterMask) {}
void EventsDb::cleanEvents (FilterMask mask) {
// TODO.
(void)mask;
}
int EventsDb::getEventsCount (FilterMask) const {
return 0;
}
int EventsDb::getEventsCount (FilterMask mask) {
// TODO.
(void)mask;
return 0;
}
int EventsDb::getMessagesCount (const string &) const {
return 0;
}
int EventsDb::getMessagesCount (const string &remoteAddress) {
// TODO.
(void)remoteAddress;
return 0;
}
int EventsDb::getUnreadMessagesCount (const string &) const {
return 0;
}
int EventsDb::getUnreadMessagesCount (const string &remoteAddress) {
// TODO.
(void)remoteAddress;
return 0;
}
list<Event> EventsDb::getHistory (const string &, int, FilterMask) const {
return list<Event>();
}
list<Event> EventsDb::getHistory (const string &remoteAddress, int nLast, FilterMask mask) {
// TODO.
(void)remoteAddress;
(void)nLast;
(void)mask;
return list<Event>();
}
list<Event> EventsDb::getHistory (const string &, int, int, FilterMask) const {
return list<Event>();
}
list<Event> EventsDb::getHistory (const string &remoteAddress, int begin, int end, FilterMask mask) {
// TODO.
(void)remoteAddress;
(void)begin;
(void)end;
(void)mask;
return list<Event>();
}
void EventsDb::cleanHistory (const string &) {}
void EventsDb::cleanHistory (const string &remoteAddress) {
// TODO.
(void)remoteAddress;
}
#endif // ifdef SOCI_ENABLED
LINPHONE_END_NAMESPACE
......@@ -47,13 +47,13 @@ public:
bool addEvent (const Event &event);
bool deleteEvent (const Event &event);
void cleanEvents (FilterMask mask = NoFilter);
int getEventsCount (FilterMask mask = NoFilter);
int getEventsCount (FilterMask mask = NoFilter) const;
// Messages, calls and conferences.
int getMessagesCount (const std::string &remoteAddress);
int getUnreadMessagesCount (const std::string &remoteAddress);
std::list<Event> getHistory (const std::string &remoteAddress, int nLast, FilterMask mask = NoFilter);
std::list<Event> getHistory (const std::string &remoteAddress, int begin, int end, FilterMask mask = NoFilter);
int getMessagesCount (const std::string &remoteAddress) const;
int getUnreadMessagesCount (const std::string &remoteAddress) const;
std::list<Event> getHistory (const std::string &remoteAddress, int nLast, FilterMask mask = NoFilter) const;
std::list<Event> getHistory (const std::string &remoteAddress, int begin, int end, FilterMask mask = NoFilter) const;
void cleanHistory (const std::string &remoteAddress);
protected:
......
......@@ -57,4 +57,10 @@ LINPHONE_END_NAMESPACE
#define lError() LINPHONE_NAMESPACE::Logger(Logger::Error).getOutput()
#define lFatal() LINPHONE_NAMESPACE::Logger(Logger::Fatal).getOutput()
#define L_BEGIN_LOG_EXCEPTION try {
#define L_END_LOG_EXCEPTION \
} catch (const exception &e) { \
lWarning() << "Error: " << e.what(); \
}
#endif // ifndef _LOGGER_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment