From c7485c4577e2210bd11f43f30e4745c9cedf74a0 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 24 Oct 2024 14:00:16 +0200 Subject: [PATCH] use sr --- solanaceae/ngc_ext/ngcext.cpp | 8 +++-- solanaceae/ngc_ext/ngcext.hpp | 1 + solanaceae/ngc_ft1/ngcft1.cpp | 18 +++++----- solanaceae/ngc_ft1/ngcft1.hpp | 2 ++ solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp | 47 ++++++++++++++++--------- solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp | 5 +++ 6 files changed, 53 insertions(+), 28 deletions(-) diff --git a/solanaceae/ngc_ext/ngcext.cpp b/solanaceae/ngc_ext/ngcext.cpp index 34e3850..55e2044 100644 --- a/solanaceae/ngc_ext/ngcext.cpp +++ b/solanaceae/ngc_ext/ngcext.cpp @@ -3,9 +3,11 @@ #include #include -NGCEXTEventProvider::NGCEXTEventProvider(ToxI& t, ToxEventProviderI& tep) : _t(t), _tep(tep) { - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_CUSTOM_PACKET); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET); +NGCEXTEventProvider::NGCEXTEventProvider(ToxI& t, ToxEventProviderI& tep) : _t(t), _tep(tep), _tep_sr(_tep.newSubRef(this)) { + _tep_sr + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_CUSTOM_PACKET) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET) + ; } #define _DATA_HAVE(x, error) if ((data_size - curser) < (x)) { error; } diff --git a/solanaceae/ngc_ext/ngcext.hpp b/solanaceae/ngc_ext/ngcext.hpp index 61b20b9..aafc3fb 100644 --- a/solanaceae/ngc_ext/ngcext.hpp +++ b/solanaceae/ngc_ext/ngcext.hpp @@ -314,6 +314,7 @@ using NGCEXTEventProviderI = EventProviderI; class NGCEXTEventProvider : public ToxEventI, public NGCEXTEventProviderI { ToxI& _t; ToxEventProviderI& _tep; + ToxEventProviderI::SubscriptionReference _tep_sr; public: NGCEXTEventProvider(ToxI& t, ToxEventProviderI& tep); diff --git a/solanaceae/ngc_ft1/ngcft1.cpp b/solanaceae/ngc_ft1/ngcft1.cpp index 3683252..b5b16d3 100644 --- a/solanaceae/ngc_ft1/ngcft1.cpp +++ b/solanaceae/ngc_ft1/ngcft1.cpp @@ -251,16 +251,18 @@ NGCFT1::NGCFT1( ToxI& t, ToxEventProviderI& tep, NGCEXTEventProvider& neep -) : _t(t), _tep(tep), _neep(neep) +) : _t(t), _tep(tep), _tep_sr(_tep.newSubRef(this)), _neep(neep), _neep_sr(_neep.newSubRef(this)) { - _neep.subscribe(this, NGCEXT_Event::FT1_REQUEST); - _neep.subscribe(this, NGCEXT_Event::FT1_INIT); - _neep.subscribe(this, NGCEXT_Event::FT1_INIT_ACK); - _neep.subscribe(this, NGCEXT_Event::FT1_DATA); - _neep.subscribe(this, NGCEXT_Event::FT1_DATA_ACK); - _neep.subscribe(this, NGCEXT_Event::FT1_MESSAGE); + _neep_sr + .subscribe(NGCEXT_Event::FT1_REQUEST) + .subscribe(NGCEXT_Event::FT1_INIT) + .subscribe(NGCEXT_Event::FT1_INIT_ACK) + .subscribe(NGCEXT_Event::FT1_DATA) + .subscribe(NGCEXT_Event::FT1_DATA_ACK) + .subscribe(NGCEXT_Event::FT1_MESSAGE) + ; - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT); + _tep_sr.subscribe(Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT); } float NGCFT1::iterate(float time_delta) { diff --git a/solanaceae/ngc_ft1/ngcft1.hpp b/solanaceae/ngc_ft1/ngcft1.hpp index 2c81a03..dd0a0d6 100644 --- a/solanaceae/ngc_ft1/ngcft1.hpp +++ b/solanaceae/ngc_ft1/ngcft1.hpp @@ -132,7 +132,9 @@ using NGCFT1EventProviderI = EventProviderI; class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProviderI { ToxI& _t; ToxEventProviderI& _tep; + ToxEventProviderI::SubscriptionReference _tep_sr; NGCEXTEventProvider& _neep; // not the interface? + NGCEXTEventProvider::SubscriptionReference _neep_sr; std::default_random_engine _rng{std::random_device{}()}; diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index e04aad0..1e249bb 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -201,36 +201,49 @@ SHA1_NGCFT1::SHA1_NGCFT1( NGCEXTEventProvider& neep ) : _os(os), + _os_sr(_os.newSubRef(this)), _cr(cr), _rmm(rmm), + _rmm_sr(_rmm.newSubRef(this)), _nft(nft), + _nft_sr(_nft.newSubRef(this)), _tcm(tcm), _tep(tep), + _tep_sr(_tep.newSubRef(this)), _neep(neep), + _neep_sr(_neep.newSubRef(this)), _mfb(os) { + _os_sr // TODO: also create and destroy - //_os.subscribe(this, ObjectStore_Event::object_construct); - _os.subscribe(this, ObjectStore_Event::object_update); - //_os.subscribe(this, ObjectStore_Event::object_destroy); + // .subscribe(ObjectStore_Event::object_construct) + .subscribe(ObjectStore_Event::object_update) + // .subscribe(ObjectStore_Event::object_destroy) + ; - _nft.subscribe(this, NGCFT1_Event::recv_request); - _nft.subscribe(this, NGCFT1_Event::recv_init); - _nft.subscribe(this, NGCFT1_Event::recv_data); - _nft.subscribe(this, NGCFT1_Event::send_data); - _nft.subscribe(this, NGCFT1_Event::recv_done); - _nft.subscribe(this, NGCFT1_Event::send_done); - _nft.subscribe(this, NGCFT1_Event::recv_message); + _nft_sr + .subscribe(NGCFT1_Event::recv_request) + .subscribe(NGCFT1_Event::recv_init) + .subscribe(NGCFT1_Event::recv_data) + .subscribe(NGCFT1_Event::send_data) + .subscribe(NGCFT1_Event::recv_done) + .subscribe(NGCFT1_Event::send_done) + .subscribe(NGCFT1_Event::recv_message) + ; - _rmm.subscribe(this, RegistryMessageModel_Event::send_file_path); + _rmm_sr.subscribe(RegistryMessageModel_Event::send_file_path); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_JOIN); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT); + _tep_sr + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_PEER_JOIN) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT) + ; - _neep.subscribe(this, NGCEXT_Event::FT1_HAVE); - _neep.subscribe(this, NGCEXT_Event::FT1_BITSET); - _neep.subscribe(this, NGCEXT_Event::FT1_HAVE_ALL); - _neep.subscribe(this, NGCEXT_Event::PC1_ANNOUNCE); + _neep_sr + .subscribe(NGCEXT_Event::FT1_HAVE) + .subscribe(NGCEXT_Event::FT1_BITSET) + .subscribe(NGCEXT_Event::FT1_HAVE_ALL) + .subscribe(NGCEXT_Event::PC1_ANNOUNCE) + ; } float SHA1_NGCFT1::iterate(float delta) { diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp index 01f0a4b..5ccc28e 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp @@ -22,13 +22,18 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public ObjectStoreEventI, public NGCFT1EventI, public NGCEXTEventI { ObjectStore2& _os; + ObjectStore2::SubscriptionReference _os_sr; // TODO: backend abstraction Contact3Registry& _cr; RegistryMessageModelI& _rmm; + RegistryMessageModelI::SubscriptionReference _rmm_sr; NGCFT1& _nft; + NGCFT1::SubscriptionReference _nft_sr; ToxContactModel2& _tcm; ToxEventProviderI& _tep; + ToxEventProviderI::SubscriptionReference _tep_sr; NGCEXTEventProvider& _neep; + NGCEXTEventProvider::SubscriptionReference _neep_sr; Backends::SHA1MappedFilesystem _mfb;