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

This commit is contained in:
Ronan Abhamon 2017-11-08 15:21:51 +01:00
parent 057db03349
commit 9d4a1f3cd5
5 changed files with 15 additions and 4 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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.

View file

@ -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;
}

View file

@ -36,6 +36,8 @@ class EventLog;
class MainDbPrivate;
class MainDb : public AbstractDb, public CoreAccessor {
friend class MainDbEventKey;
public:
enum Filter {
NoFilter = 0x0,