diff --git a/solanaceae/tox_contacts/tox_contact_model2.cpp b/solanaceae/tox_contacts/tox_contact_model2.cpp index 7843c8e..c8fa839 100644 --- a/solanaceae/tox_contacts/tox_contact_model2.cpp +++ b/solanaceae/tox_contacts/tox_contact_model2.cpp @@ -14,21 +14,23 @@ #include #include -ToxContactModel2::ToxContactModel2(Contact3Registry& cr, ToxI& t, ToxEventProviderI& tep) : _cr(cr), _t(t), _tep(tep) { - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_STATUS); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_NAME); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_STATUS_MESSAGE); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_REQUEST); +ToxContactModel2::ToxContactModel2(Contact3Registry& cr, ToxI& t, ToxEventProviderI& tep) : _cr(cr), _t(t), _tep_sr(tep.newSubRef(this)) { + _tep_sr + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS) + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_STATUS) + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_NAME) + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_STATUS_MESSAGE) + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_REQUEST) - // TODO: conf + // TODO: conf - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_INVITE); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_SELF_JOIN); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_JOIN); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_NAME); - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_TOPIC); + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_INVITE) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_SELF_JOIN) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_PEER_JOIN) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_PEER_NAME) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_TOPIC) + ; // add tox profile root _root = _cr.create(); diff --git a/solanaceae/tox_contacts/tox_contact_model2.hpp b/solanaceae/tox_contacts/tox_contact_model2.hpp index abb0e6b..dd0cbcf 100644 --- a/solanaceae/tox_contacts/tox_contact_model2.hpp +++ b/solanaceae/tox_contacts/tox_contact_model2.hpp @@ -12,7 +12,7 @@ struct ToxI; class ToxContactModel2 : public ContactModel3I, public ToxEventI { Contact3Registry& _cr; ToxI& _t; - ToxEventProviderI& _tep; + ToxEventProviderI::SubscriptionReference _tep_sr; Contact3 _root; Contact3 _friend_self; diff --git a/solanaceae/tox_messages/tox_message_manager.cpp b/solanaceae/tox_messages/tox_message_manager.cpp index 7e24f24..f9aafb6 100644 --- a/solanaceae/tox_messages/tox_message_manager.cpp +++ b/solanaceae/tox_messages/tox_message_manager.cpp @@ -13,23 +13,38 @@ #include #include -ToxMessageManager::ToxMessageManager(RegistryMessageModelI& rmm, Contact3Registry& cr, ToxContactModel2& tcm, ToxI& t, ToxEventProviderI& tep) : _rmm(rmm), _cr(cr), _tcm(tcm), _t(t) { - // TODO: system messages? - //tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_CONNECTION_STATUS); - //tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_STATUS); - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_MESSAGE); - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_READ_RECEIPT); +ToxMessageManager::ToxMessageManager( + RegistryMessageModelI& rmm, + Contact3Registry& cr, + ToxContactModel2& tcm, + ToxI& t, + ToxEventProviderI& tep +) : + _rmm(rmm), + _rmm_sr(_rmm.newSubRef(this)), + _cr(cr), + _tcm(tcm), + _t(t), + _tep_sr(tep.newSubRef(this)) +{ + _tep_sr + // TODO: system messages? + //.subscribe(Tox_Event::TOX_EVENT_FRIEND_CONNECTION_STATUS) + //.subscribe(Tox_Event::TOX_EVENT_FRIEND_STATUS) + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_MESSAGE) + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_READ_RECEIPT) - // TODO: conf + // TODO: conf - // TODO: system messages? - //tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_JOIN); - //tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_SELF_JOIN); - //tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_NAME); - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_MESSAGE); - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PRIVATE_MESSAGE); + // TODO: system messages? + //.subscribe(Tox_Event::TOX_EVENT_GROUP_PEER_JOIN) + //.subscribe(Tox_Event::TOX_EVENT_GROUP_SELF_JOIN) + //.subscribe(Tox_Event::TOX_EVENT_GROUP_PEER_NAME) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_MESSAGE) + .subscribe(Tox_Event_Type::TOX_EVENT_GROUP_PRIVATE_MESSAGE) + ; - _rmm.subscribe(this, RegistryMessageModel_Event::send_text); + _rmm_sr.subscribe(RegistryMessageModel_Event::send_text); } ToxMessageManager::~ToxMessageManager(void) { diff --git a/solanaceae/tox_messages/tox_message_manager.hpp b/solanaceae/tox_messages/tox_message_manager.hpp index 93e9fcb..2bdd2f9 100644 --- a/solanaceae/tox_messages/tox_message_manager.hpp +++ b/solanaceae/tox_messages/tox_message_manager.hpp @@ -10,9 +10,11 @@ struct ToxI; class ToxMessageManager : public RegistryMessageModelEventI, public ToxEventI { protected: RegistryMessageModelI& _rmm; + RegistryMessageModelI::SubscriptionReference _rmm_sr; Contact3Registry& _cr; ToxContactModel2& _tcm; ToxI& _t; + ToxEventProviderI::SubscriptionReference _tep_sr; public: ToxMessageManager(RegistryMessageModelI& rmm, Contact3Registry& cr, ToxContactModel2& tcm, ToxI& t, ToxEventProviderI& tep); diff --git a/solanaceae/tox_messages/tox_transfer_manager.cpp b/solanaceae/tox_messages/tox_transfer_manager.cpp index c6c0757..9db8d56 100644 --- a/solanaceae/tox_messages/tox_transfer_manager.cpp +++ b/solanaceae/tox_messages/tox_transfer_manager.cpp @@ -82,17 +82,21 @@ ToxTransferManager::ToxTransferManager( ToxI& t, ToxEventProviderI& tep, ObjectStore2& os -) : _rmm(rmm), _cr(cr), _tcm(tcm), _t(t), _os(os), _ftb(os) { - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS); - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FILE_RECV); - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FILE_RECV_CONTROL); - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FILE_RECV_CHUNK); - tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FILE_CHUNK_REQUEST); +) : _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _cr(cr), _tcm(tcm), _t(t), _tep_sr(tep.newSubRef(this)), _os(os), _os_sr(_os.newSubRef(this)), _ftb(os) { + _tep_sr + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS) + .subscribe(Tox_Event_Type::TOX_EVENT_FILE_RECV) + .subscribe(Tox_Event_Type::TOX_EVENT_FILE_RECV_CONTROL) + .subscribe(Tox_Event_Type::TOX_EVENT_FILE_RECV_CHUNK) + .subscribe(Tox_Event_Type::TOX_EVENT_FILE_CHUNK_REQUEST) + ; - _os.subscribe(this, ObjectStore_Event::object_update); - _os.subscribe(this, ObjectStore_Event::object_destroy); + _os_sr + .subscribe(ObjectStore_Event::object_update) + .subscribe(ObjectStore_Event::object_destroy) + ; - _rmm.subscribe(this, RegistryMessageModel_Event::send_file_path); + _rmm_sr.subscribe(RegistryMessageModel_Event::send_file_path); } ToxTransferManager::~ToxTransferManager(void) { diff --git a/solanaceae/tox_messages/tox_transfer_manager.hpp b/solanaceae/tox_messages/tox_transfer_manager.hpp index 45ab0dd..6fe4c88 100644 --- a/solanaceae/tox_messages/tox_transfer_manager.hpp +++ b/solanaceae/tox_messages/tox_transfer_manager.hpp @@ -24,10 +24,13 @@ class ToxTransferManager : public RegistryMessageModelEventI, public ObjectStore protected: RegistryMessageModelI& _rmm; + RegistryMessageModelI::SubscriptionReference _rmm_sr; Contact3Registry& _cr; ToxContactModel2& _tcm; ToxI& _t; + ToxEventProviderI::SubscriptionReference _tep_sr; ObjectStore2& _os; + ObjectStore2::SubscriptionReference _os_sr; Backends::ToxFTFilesystem _ftb; bool _in_obj_update_event {false};