Commit a322fb9a authored by Ronan's avatar Ronan

feat(EventsDb): impl `getEventsCount`

parent abf91b06
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "event/call-event.h" #include "event/call-event.h"
#include "event/event.h" #include "event/event.h"
#include "event/message-event.h" #include "event/message-event.h"
#include "logger/logger.h"
#include "events-db.h" #include "events-db.h"
...@@ -39,8 +40,50 @@ class EventsDbPrivate : public AbstractDbPrivate {}; ...@@ -39,8 +40,50 @@ class EventsDbPrivate : public AbstractDbPrivate {};
EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} 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); L_D(EventsDb);
soci::session *session = d->dbSession.getBackendSession<soci::session>(); soci::session *session = d->dbSession.getBackendSession<soci::session>();
...@@ -102,75 +145,124 @@ void EventsDb::init () { ...@@ -102,75 +145,124 @@ void EventsDb::init () {
" REFERENCES message_direction(id)" " REFERENCES message_direction(id)"
" ON DELETE CASCADE" " 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) { #else
// TODO.
switch (event.getType()) { void EventsDb::init () {}
case Event::None:
return false; bool EventsDb::addEvent (const Event &) {
case Event::MessageEvent: return false;
case Event::CallStartEvent:
case Event::CallEndEvent:
break;
} }
return true; bool EventsDb::deleteEvent (const Event &) {
} return false;
}
bool EventsDb::deleteEvent (const Event &event) { void EventsDb::cleanEvents (FilterMask) {}
// TODO.
(void)event;
return true;
}
void EventsDb::cleanEvents (FilterMask mask) { int EventsDb::getEventsCount (FilterMask) const {
// TODO. return 0;
(void)mask; }
}
int EventsDb::getEventsCount (FilterMask mask) { int EventsDb::getMessagesCount (const string &) const {
// TODO. return 0;
(void)mask; }
return 0;
}
int EventsDb::getMessagesCount (const string &remoteAddress) { int EventsDb::getUnreadMessagesCount (const string &) const {
// TODO. return 0;
(void)remoteAddress; }
return 0;
}
int EventsDb::getUnreadMessagesCount (const string &remoteAddress) { list<Event> EventsDb::getHistory (const string &, int, FilterMask) const {
// TODO. return list<Event>();
(void)remoteAddress; }
return 0;
}
list<Event> EventsDb::getHistory (const string &remoteAddress, int nLast, FilterMask mask) { list<Event> EventsDb::getHistory (const string &, int, int, FilterMask) const {
// TODO. return list<Event>();
(void)remoteAddress; }
(void)nLast;
(void)mask;
return list<Event>();
}
list<Event> EventsDb::getHistory (const string &remoteAddress, int begin, int end, FilterMask mask) { void EventsDb::cleanHistory (const string &) {}
// TODO.
(void)remoteAddress;
(void)begin;
(void)end;
(void)mask;
return list<Event>();
}
void EventsDb::cleanHistory (const string &remoteAddress) { #endif // ifdef SOCI_ENABLED
// TODO.
(void)remoteAddress;
}
LINPHONE_END_NAMESPACE LINPHONE_END_NAMESPACE
...@@ -47,13 +47,13 @@ public: ...@@ -47,13 +47,13 @@ public:
bool addEvent (const Event &event); bool addEvent (const Event &event);
bool deleteEvent (const Event &event); bool deleteEvent (const Event &event);
void cleanEvents (FilterMask mask = NoFilter); void cleanEvents (FilterMask mask = NoFilter);
int getEventsCount (FilterMask mask = NoFilter); int getEventsCount (FilterMask mask = NoFilter) const;
// Messages, calls and conferences. // Messages, calls and conferences.
int getMessagesCount (const std::string &remoteAddress); int getMessagesCount (const std::string &remoteAddress) const;
int getUnreadMessagesCount (const std::string &remoteAddress); int getUnreadMessagesCount (const std::string &remoteAddress) const;
std::list<Event> getHistory (const std::string &remoteAddress, int nLast, FilterMask mask = NoFilter); 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); std::list<Event> getHistory (const std::string &remoteAddress, int begin, int end, FilterMask mask = NoFilter) const;
void cleanHistory (const std::string &remoteAddress); void cleanHistory (const std::string &remoteAddress);
protected: protected:
......
...@@ -57,4 +57,10 @@ LINPHONE_END_NAMESPACE ...@@ -57,4 +57,10 @@ LINPHONE_END_NAMESPACE
#define lError() LINPHONE_NAMESPACE::Logger(Logger::Error).getOutput() #define lError() LINPHONE_NAMESPACE::Logger(Logger::Error).getOutput()
#define lFatal() LINPHONE_NAMESPACE::Logger(Logger::Fatal).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_ #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