From c42c4464460e71a349abd919c37ab9d31c9c678a Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 24 Oct 2024 01:03:16 +0200 Subject: [PATCH] managed subscribtions --- .../message_fragment_store.cpp | 16 ++++++++++------ .../message_fragment_store.hpp | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/solanaceae/message_fragment_store/message_fragment_store.cpp b/src/solanaceae/message_fragment_store/message_fragment_store.cpp index 2e6ad4e..85f05de 100644 --- a/src/solanaceae/message_fragment_store/message_fragment_store.cpp +++ b/src/solanaceae/message_fragment_store/message_fragment_store.cpp @@ -485,10 +485,12 @@ MessageFragmentStore::MessageFragmentStore( ObjectStore2& os, StorageBackendI& sb, MessageSerializerNJ& scnj -) : _cr(cr), _rmm(rmm), _os(os), _sb(sb), _scnj(scnj) { - _rmm.subscribe(this, RegistryMessageModel_Event::message_construct); - _rmm.subscribe(this, RegistryMessageModel_Event::message_updated); - _rmm.subscribe(this, RegistryMessageModel_Event::message_destroy); +) : _cr(cr), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _os(os), _os_sr(_os.newSubRef(this)), _sb(sb), _scnj(scnj) { + _rmm_sr + .subscribe(RegistryMessageModel_Event::message_construct) + .subscribe(RegistryMessageModel_Event::message_updated) + .subscribe(RegistryMessageModel_Event::message_destroy) + ; // TODO: move somewhere else? auto& sjc = _os.registry().ctx().get>(); @@ -505,8 +507,10 @@ MessageFragmentStore::MessageFragmentStore( sjc.registerSerializer(sjc.component_get_json); sjc.registerDeSerializer(sjc.component_emplace_or_replace_json); - _os.subscribe(this, ObjectStore_Event::object_construct); - _os.subscribe(this, ObjectStore_Event::object_update); + _os_sr + .subscribe(ObjectStore_Event::object_construct) + .subscribe(ObjectStore_Event::object_update) + ; } MessageFragmentStore::~MessageFragmentStore(void) { diff --git a/src/solanaceae/message_fragment_store/message_fragment_store.hpp b/src/solanaceae/message_fragment_store/message_fragment_store.hpp index caf635f..22c3734 100644 --- a/src/solanaceae/message_fragment_store/message_fragment_store.hpp +++ b/src/solanaceae/message_fragment_store/message_fragment_store.hpp @@ -52,7 +52,9 @@ class MessageFragmentStore : public RegistryMessageModelEventI, public ObjectSto protected: Contact3Registry& _cr; RegistryMessageModelI& _rmm; + RegistryMessageModelI::SubscriptionReference _rmm_sr; ObjectStore2& _os; + ObjectStore2::SubscriptionReference _os_sr; StorageBackendI& _sb; MessageSerializerNJ& _scnj;