Commit 9a5f620c authored by Ronan's avatar Ronan

feat(MainDb): refactor main db event key

parent db5b8dfc
......@@ -96,8 +96,9 @@ 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-key-p.h
db/main-db-key.h
db/main-db-p.h
db/main-db.h
db/session/db-session-p.h
......@@ -200,6 +201,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
core/platform-helpers/platform-helpers.cpp
db/abstract/abstract-db.cpp
db/main-db-event-key.cpp
db/main-db-key.cpp
db/main-db.cpp
db/session/db-session-provider.cpp
db/session/db-session.cpp
......
......@@ -18,7 +18,8 @@
*/
#include "core/core-p.h"
#include "main-db-event-key-p.h"
#include "main-db-event-key.h"
#include "main-db-key-p.h"
#include "main-db-p.h"
// =============================================================================
......@@ -29,21 +30,9 @@ LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
MainDbEventKey::MainDbEventKey () : ClonableObject(*new MainDbEventKeyPrivate) {}
MainDbEventKey::MainDbEventKey () : MainDbKey() {};
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 (const shared_ptr<Core> &core, long long storageId) : MainDbKey(core, storageId) {}
MainDbEventKey::~MainDbEventKey () {
L_D();
......@@ -52,21 +41,4 @@ MainDbEventKey::~MainDbEventKey () {
d->core.lock()->getPrivate()->mainDb->getPrivate()->storageIdToEvent.erase(d->storageId);
}
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
......@@ -20,33 +20,20 @@
#ifndef _MAIN_DB_EVENT_KEY_H_
#define _MAIN_DB_EVENT_KEY_H_
#include <memory>
#include "object/clonable-object.h"
#include "main-db-key.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class Core;
class MainDbEventKeyPrivate;
class MainDbEventKey : public ClonableObject {
friend class MainDb;
friend class MainDbPrivate;
class MainDbEventKey : public MainDbKey {
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);
L_DECLARE_PRIVATE(MainDbKey);
};
LINPHONE_END_NAMESPACE
......
/*
* main-db-event-key-p.h
* main-db-key-p.h
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
......@@ -17,17 +17,17 @@
* 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_
#ifndef _MAIN_DB_KEY_P_H_
#define _MAIN_DB_KEY_P_H_
#include "main-db-event-key.h"
#include "main-db-key.h"
#include "object/clonable-object-p.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class MainDbEventKeyPrivate : public ClonableObjectPrivate {
class MainDbKeyPrivate : public ClonableObjectPrivate {
public:
std::weak_ptr<Core> core;
long long storageId = -1;
......@@ -35,4 +35,4 @@ public:
LINPHONE_END_NAMESPACE
#endif // ifndef _MAIN_DB_EVENT_KEY_P_H_
#endif // ifndef _MAIN_DB_KEY_P_H_
/*
* main-db-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 "core/core-p.h"
#include "main-db-key-p.h"
#include "main-db-p.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
MainDbKey::MainDbKey () : ClonableObject(*new MainDbKeyPrivate) {}
MainDbKey::MainDbKey (const shared_ptr<Core> &core, long long storageId) : MainDbKey() {
L_D();
d->core = core;
d->storageId = storageId;
}
MainDbKey::MainDbKey (const MainDbKey &src) : MainDbKey() {
L_D();
const MainDbKeyPrivate *dSrc = src.getPrivate();
d->core = dSrc->core;
d->storageId = dSrc->storageId;
}
MainDbKey::~MainDbKey () {}
MainDbKey &MainDbKey::operator= (const MainDbKey &src) {
L_D();
if (this != &src) {
const MainDbKeyPrivate *dSrc = src.getPrivate();
d->core = dSrc->core;
d->storageId = dSrc->storageId;
}
return *this;
}
bool MainDbKey::isValid () const {
L_D();
return !d->core.expired() && d->storageId >= 0;
}
LINPHONE_END_NAMESPACE
/*
* main-db-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_KEY_H_
#define _MAIN_DB_KEY_H_
#include <memory>
#include "object/clonable-object.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class Core;
class MainDbKeyPrivate;
class MainDbKey : public ClonableObject {
friend class MainDb;
friend class MainDbPrivate;
public:
MainDbKey ();
MainDbKey (const std::shared_ptr<Core> &core, long long storageId);
MainDbKey (const MainDbKey &src);
virtual ~MainDbKey () = 0;
MainDbKey &operator= (const MainDbKey &src);
bool isValid () const;
private:
L_DECLARE_PRIVATE(MainDbKey);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _MAIN_DB_KEY_H_
......@@ -37,7 +37,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-key-p.h"
#include "main-db-p.h"
// =============================================================================
......@@ -676,7 +676,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
}
const EventLogPrivate *dEventLog = eventLog->getPrivate();
MainDbEventKeyPrivate *dEventKey = dEventLog->dbKey.getPrivate();
MainDbKeyPrivate *dEventKey = static_cast<MainDbKey &>(dEventLog->dbKey).getPrivate();
const long long &eventId = dEventKey->storageId;
soci::session *session = dbSession.getBackendSession<soci::session>();
......@@ -1143,9 +1143,8 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
break;
}
tr.commit();
soFarSoGood = storageId >= 0;
if ((soFarSoGood = storageId >= 0))
tr.commit();
L_END_LOG_EXCEPTION
......@@ -1211,7 +1210,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
return false;
}
MainDbEventKeyPrivate *dEventKey = dEventLog->dbKey.getPrivate();
MainDbKeyPrivate *dEventKey = static_cast<MainDbKey &>(dEventLog->dbKey).getPrivate();
shared_ptr<Core> core = dEventKey->core.lock();
L_ASSERT(core);
......
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