mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
feat(MainDb): provide a way to check stored events
This commit is contained in:
parent
f7b64d5ad5
commit
bc32805af0
10 changed files with 203 additions and 21 deletions
|
|
@ -91,6 +91,8 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
|
|||
core/platform-helpers/platform-helpers.h
|
||||
db/abstract/abstract-db-p.h
|
||||
db/abstract/abstract-db.h
|
||||
db/main-db-event-key-p.h
|
||||
db/main-db-event-key.h
|
||||
db/main-db-p.h
|
||||
db/main-db.h
|
||||
db/session/db-session-p.h
|
||||
|
|
@ -188,6 +190,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
|
|||
core/paths/paths.cpp
|
||||
core/platform-helpers/platform-helpers.cpp
|
||||
db/abstract/abstract-db.cpp
|
||||
db/main-db-event-key.cpp
|
||||
db/main-db.cpp
|
||||
db/session/db-session-provider.cpp
|
||||
db/session/db-session.cpp
|
||||
|
|
|
|||
38
src/db/main-db-event-key-p.h
Normal file
38
src/db/main-db-event-key-p.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* main-db-event-key-p.h
|
||||
* Copyright (C) 2010-2017 Belledonne Communications SARL
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _MAIN_DB_EVENT_KEY_P_H_
|
||||
#define _MAIN_DB_EVENT_KEY_P_H_
|
||||
|
||||
#include "main-db-event-key.h"
|
||||
#include "object/clonable-object-p.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class MainDbEventKeyPrivate : public ClonableObjectPrivate {
|
||||
public:
|
||||
std::weak_ptr<Core> core;
|
||||
long long storageId = -1;
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
||||
#endif // ifndef _MAIN_DB_EVENT_KEY_P_H_
|
||||
69
src/db/main-db-event-key.cpp
Normal file
69
src/db/main-db-event-key.cpp
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* main-db-event-key.cpp
|
||||
* Copyright (C) 2010-2017 Belledonne Communications SARL
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "main-db-event-key-p.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
MainDbEventKey::MainDbEventKey () : ClonableObject(*new MainDbEventKeyPrivate) {}
|
||||
|
||||
MainDbEventKey::MainDbEventKey (const shared_ptr<Core> &core, long long storageId) : MainDbEventKey() {
|
||||
L_D();
|
||||
d->core = core;
|
||||
d->storageId = storageId;
|
||||
}
|
||||
|
||||
MainDbEventKey::MainDbEventKey (const MainDbEventKey &src) : MainDbEventKey() {
|
||||
L_D();
|
||||
const MainDbEventKeyPrivate *dSrc = src.getPrivate();
|
||||
|
||||
d->core = dSrc->core;
|
||||
d->storageId = dSrc->storageId;
|
||||
}
|
||||
|
||||
MainDbEventKey::~MainDbEventKey () {
|
||||
if (isValid()) {
|
||||
// TODO: Remove key from main db references if necessary.
|
||||
}
|
||||
}
|
||||
|
||||
MainDbEventKey &MainDbEventKey::operator= (const MainDbEventKey &src) {
|
||||
L_D();
|
||||
|
||||
if (this != &src) {
|
||||
const MainDbEventKeyPrivate *dSrc = src.getPrivate();
|
||||
d->core = dSrc->core;
|
||||
d->storageId = dSrc->storageId;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool MainDbEventKey::isValid () const {
|
||||
L_D();
|
||||
return !d->core.expired() && d->storageId >= 0;
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
53
src/db/main-db-event-key.h
Normal file
53
src/db/main-db-event-key.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* main-db-event-key.h
|
||||
* Copyright (C) 2010-2017 Belledonne Communications SARL
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _MAIN_DB_EVENT_KEY_H_
|
||||
#define _MAIN_DB_EVENT_KEY_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "object/clonable-object.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class Core;
|
||||
class MainDbEventKeyPrivate;
|
||||
|
||||
class MainDbEventKey : public ClonableObject {
|
||||
friend class MainDb;
|
||||
|
||||
public:
|
||||
MainDbEventKey ();
|
||||
MainDbEventKey (const std::shared_ptr<Core> &core, long long storageId);
|
||||
MainDbEventKey (const MainDbEventKey &src);
|
||||
~MainDbEventKey ();
|
||||
|
||||
MainDbEventKey &operator= (const MainDbEventKey &src);
|
||||
|
||||
bool isValid () const;
|
||||
|
||||
private:
|
||||
L_DECLARE_PRIVATE(MainDbEventKey);
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
||||
#endif // ifndef _MAIN_DB_EVENT_KEY_H_
|
||||
|
|
@ -36,6 +36,7 @@
|
|||
#include "event-log/event-log-p.h"
|
||||
#include "event-log/events.h"
|
||||
#include "logger/logger.h"
|
||||
#include "main-db-event-key-p.h"
|
||||
#include "main-db-p.h"
|
||||
|
||||
// =============================================================================
|
||||
|
|
@ -778,7 +779,14 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
|
|||
return false;
|
||||
}
|
||||
|
||||
const EventLogPrivate *dEventLog = eventLog->getPrivate();
|
||||
if (dEventLog->dbKey.isValid()) {
|
||||
lWarning() << "Unable to add an event twice!!!";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool soFarSoGood = false;
|
||||
long long storageId;
|
||||
|
||||
L_BEGIN_LOG_EXCEPTION
|
||||
|
||||
|
|
@ -790,32 +798,32 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
|
|||
|
||||
case EventLog::Type::ConferenceCreated:
|
||||
case EventLog::Type::ConferenceDestroyed:
|
||||
d->insertConferenceEvent(eventLog);
|
||||
storageId = d->insertConferenceEvent(eventLog);
|
||||
break;
|
||||
|
||||
case EventLog::Type::ConferenceCallStart:
|
||||
case EventLog::Type::ConferenceCallEnd:
|
||||
d->insertConferenceCallEvent(eventLog);
|
||||
storageId = d->insertConferenceCallEvent(eventLog);
|
||||
break;
|
||||
|
||||
case EventLog::Type::ConferenceChatMessage:
|
||||
d->insertConferenceChatMessageEvent(eventLog);
|
||||
storageId = d->insertConferenceChatMessageEvent(eventLog);
|
||||
break;
|
||||
|
||||
case EventLog::Type::ConferenceParticipantAdded:
|
||||
case EventLog::Type::ConferenceParticipantRemoved:
|
||||
case EventLog::Type::ConferenceParticipantSetAdmin:
|
||||
case EventLog::Type::ConferenceParticipantUnsetAdmin:
|
||||
d->insertConferenceParticipantEvent(eventLog);
|
||||
storageId = d->insertConferenceParticipantEvent(eventLog);
|
||||
break;
|
||||
|
||||
case EventLog::Type::ConferenceParticipantDeviceAdded:
|
||||
case EventLog::Type::ConferenceParticipantDeviceRemoved:
|
||||
d->insertConferenceParticipantDeviceEvent(eventLog);
|
||||
storageId = d->insertConferenceParticipantDeviceEvent(eventLog);
|
||||
break;
|
||||
|
||||
case EventLog::Type::ConferenceSubjectChanged:
|
||||
d->insertConferenceSubjectEvent(eventLog);
|
||||
storageId = d->insertConferenceSubjectEvent(eventLog);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -825,30 +833,39 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
|
|||
|
||||
L_END_LOG_EXCEPTION
|
||||
|
||||
if (soFarSoGood)
|
||||
dEventLog->dbKey = MainDbEventKey(getCore(), storageId);
|
||||
|
||||
return soFarSoGood;
|
||||
}
|
||||
|
||||
bool MainDb::deleteEvent (const shared_ptr<EventLog> &eventLog) {
|
||||
L_D();
|
||||
EventLogPrivate *dEventLog = eventLog->getPrivate();
|
||||
if (!dEventLog->dbKey.isValid()) {
|
||||
lWarning() << "Unable to delete invalid event.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isConnected()) {
|
||||
MainDbEventKeyPrivate *dEventKey = dEventLog->dbKey.getPrivate();
|
||||
shared_ptr<Core> core = dEventKey->core.lock();
|
||||
L_ASSERT(core);
|
||||
|
||||
MainDb &mainDb = *core->getPrivate()->mainDb.get();
|
||||
if (!mainDb.isConnected()) {
|
||||
lWarning() << "Unable to delete event. Not connected.";
|
||||
return false;
|
||||
}
|
||||
|
||||
long long &storageId = eventLog->getPrivate()->storageId;
|
||||
if (storageId < 0)
|
||||
return false;
|
||||
|
||||
L_BEGIN_LOG_EXCEPTION
|
||||
|
||||
soci::session *session = d->dbSession.getBackendSession<soci::session>();
|
||||
*session << "DELETE FROM event WHERE id = :id", soci::use(storageId);
|
||||
storageId = -1;
|
||||
soci::session *session = mainDb.getPrivate()->dbSession.getBackendSession<soci::session>();
|
||||
*session << "DELETE FROM event WHERE id = :id", soci::use(dEventKey->storageId);
|
||||
|
||||
L_END_LOG_EXCEPTION
|
||||
|
||||
return storageId == -1;
|
||||
dEventLog->dbKey = MainDbEventKey();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int MainDb::getEventsCount (FilterMask mask) const {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Core;
|
|||
class EventLog;
|
||||
class MainDbPrivate;
|
||||
|
||||
class LINPHONE_PUBLIC MainDb : public AbstractDb, public CoreAccessor {
|
||||
class MainDb : public AbstractDb, public CoreAccessor {
|
||||
public:
|
||||
enum Filter {
|
||||
NoFilter = 0x0,
|
||||
|
|
@ -53,7 +53,7 @@ public:
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool addEvent (const std::shared_ptr<EventLog> &eventLog);
|
||||
bool deleteEvent (const std::shared_ptr<EventLog> &eventLog);
|
||||
static bool deleteEvent (const std::shared_ptr<EventLog> &eventLog);
|
||||
int getEventsCount (FilterMask mask = NoFilter) const;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#ifndef _EVENT_LOG_P_H_
|
||||
#define _EVENT_LOG_P_H_
|
||||
|
||||
#include "db/main-db-event-key.h"
|
||||
#include "object/base-object-p.h"
|
||||
|
||||
#include "event-log.h"
|
||||
|
|
@ -30,7 +31,7 @@ LINPHONE_BEGIN_NAMESPACE
|
|||
|
||||
class EventLogPrivate : public BaseObjectPrivate {
|
||||
public:
|
||||
long long storageId = -1;
|
||||
mutable MainDbEventKey dbKey;
|
||||
|
||||
private:
|
||||
EventLog::Type type = EventLog::Type::None;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "core/core-p.h"
|
||||
#include "event-log-p.h"
|
||||
|
||||
// =============================================================================
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
#define _EVENT_LOG_H_
|
||||
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
|
||||
#include "linphone/enums/event-log-enums.h"
|
||||
#include "linphone/utils/enum-generator.h"
|
||||
|
|
|
|||
|
|
@ -59,7 +59,8 @@ LINPHONE_END_NAMESPACE
|
|||
#define lFatal() LinphonePrivate::Logger(LinphonePrivate::Logger::Fatal).getOutput()
|
||||
|
||||
#define L_BEGIN_LOG_EXCEPTION try {
|
||||
#define L_END_LOG_EXCEPTION \
|
||||
|
||||
#define L_END_LOG_EXCEPTION \
|
||||
} catch (const exception &e) { \
|
||||
lWarning() << "Error: " << e.what(); \
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue