Commit 9d4a1f3c authored by Ronan's avatar Ronan

feat(MainDb): add a weak list of event references

parent 057db033
......@@ -38,6 +38,7 @@ class LINPHONE_PUBLIC Core : public Object {
friend class ChatRoom;
friend class ClientGroupChatRoom;
friend class MainDb;
friend class MainDbEventKey;
public:
L_OVERRIDE_SHARED_FROM_THIS(Core);
......
......@@ -17,7 +17,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "core/core-p.h"
#include "main-db-event-key-p.h"
#include "main-db-p.h"
// =============================================================================
......@@ -44,9 +46,10 @@ MainDbEventKey::MainDbEventKey (const MainDbEventKey &src) : MainDbEventKey() {
}
MainDbEventKey::~MainDbEventKey () {
if (isValid()) {
// TODO: Remove key from main db references if necessary.
}
L_D();
if (isValid())
d->core.lock()->getPrivate()->mainDb->getPrivate()->storageIdToEvent.erase(d->storageId);
}
MainDbEventKey &MainDbEventKey::operator= (const MainDbEventKey &src) {
......
......@@ -31,6 +31,9 @@ LINPHONE_BEGIN_NAMESPACE
class Content;
class MainDbPrivate : public AbstractDbPrivate {
public:
std::unordered_map<long long, std::weak_ptr<EventLog>> storageIdToEvent;
private:
// ---------------------------------------------------------------------------
// Low level API.
......
......@@ -833,8 +833,10 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
L_END_LOG_EXCEPTION
if (soFarSoGood)
if (soFarSoGood) {
dEventLog->dbKey = MainDbEventKey(getCore(), storageId);
d->storageIdToEvent[storageId] = eventLog;
}
return soFarSoGood;
}
......
......@@ -36,6 +36,8 @@ class EventLog;
class MainDbPrivate;
class MainDb : public AbstractDb, public CoreAccessor {
friend class MainDbEventKey;
public:
enum Filter {
NoFilter = 0x0,
......
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