From 92740c8dbe2dd2f6fe900c78c021e5250db28db4 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 25 Oct 2024 13:46:00 +0200 Subject: [PATCH] use sr --- .github/workflows/ci.yml | 9 ++++---- external/solanaceae_object_store | 2 +- external/solanaceae_tox | 2 +- external/solanaceae_toxcore | 2 +- external/solanaceae_util | 2 +- src/auto_dirty.cpp | 27 ++++++++++------------- src/auto_dirty.hpp | 3 +-- src/frame_streams/stream_manager.cpp | 10 +++++---- src/frame_streams/stream_manager.hpp | 1 + src/main_screen.cpp | 3 ++- src/main_screen.hpp | 2 +- src/media_meta_info_loader.cpp | 8 ++++--- src/media_meta_info_loader.hpp | 1 + src/tox_av_voip_model.cpp | 20 +++++++++-------- src/tox_av_voip_model.hpp | 1 + src/tox_avatar_manager.cpp | 8 ++++--- src/tox_avatar_manager.hpp | 1 + src/tox_friend_faux_offline_messaging.cpp | 4 ++-- src/tox_friend_faux_offline_messaging.hpp | 2 +- 19 files changed, 59 insertions(+), 49 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f8d8eaf..703c9f5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,9 +61,9 @@ jobs: distribution: 'temurin' java-version: '17' - - name: update vcpkg - run: | - git clone https://github.com/microsoft/vcpkg.git + #- name: update vcpkg + # run: | + # git clone https://github.com/microsoft/vcpkg.git - name: Install Dependencies (host) run: sudo apt update && sudo apt -y install cmake pkg-config nasm @@ -71,7 +71,8 @@ jobs: - name: Install Dependencies (target) env: ANDROID_NDK_HOME: ${{steps.setup_ndk.outputs.ndk-path}} - run: vcpkg install --triplet ${{matrix.platform.vcpkg_toolkit}} --overlay-ports=vcpkg/ports libsodium opus libvpx libpng libjpeg-turbo + #run: vcpkg install --triplet ${{matrix.platform.vcpkg_toolkit}} --overlay-ports=vcpkg/ports libsodium opus libvpx libpng libjpeg-turbo + run: vcpkg install --triplet ${{matrix.platform.vcpkg_toolkit}} libsodium opus libvpx libpng libjpeg-turbo # vcpkg scripts root /usr/local/share/vcpkg/scripts - name: Configure CMake diff --git a/external/solanaceae_object_store b/external/solanaceae_object_store index 2801fc21..ed640ba0 160000 --- a/external/solanaceae_object_store +++ b/external/solanaceae_object_store @@ -1 +1 @@ -Subproject commit 2801fc21fbd6f69479f6638ab1725d00238698f8 +Subproject commit ed640ba08cf8452e202ed567cad48ad396b8e1db diff --git a/external/solanaceae_tox b/external/solanaceae_tox index a0c3336f..30146fc5 160000 --- a/external/solanaceae_tox +++ b/external/solanaceae_tox @@ -1 +1 @@ -Subproject commit a0c3336f375c8eb3a146fd183850418a216c8e7e +Subproject commit 30146fc5a56ed671c8862437f8658cfe4fbb1fac diff --git a/external/solanaceae_toxcore b/external/solanaceae_toxcore index 7cd6a2b0..49fda84a 160000 --- a/external/solanaceae_toxcore +++ b/external/solanaceae_toxcore @@ -1 +1 @@ -Subproject commit 7cd6a2b0de13820a75b9028ae90595cd48a2231c +Subproject commit 49fda84aff7a3466cd244013fbf67624c6b71450 diff --git a/external/solanaceae_util b/external/solanaceae_util index 9a4df12d..a38c3a33 160000 --- a/external/solanaceae_util +++ b/external/solanaceae_util @@ -1 +1 @@ -Subproject commit 9a4df12d68373cd19adddde2364843eeac51c28d +Subproject commit a38c3a33055e91c9d9ceed507c0e3c2f63dc7fa4 diff --git a/src/auto_dirty.cpp b/src/auto_dirty.cpp index 55647164..43088f5a 100644 --- a/src/auto_dirty.cpp +++ b/src/auto_dirty.cpp @@ -2,21 +2,18 @@ #include "./tox_client.hpp" -// TODO: add more events - -void AutoDirty::subscribe(void) { - _tc.subscribe(this, Tox_Event_Type::TOX_EVENT_SELF_CONNECTION_STATUS); - _tc.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS); - _tc.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_REQUEST); - _tc.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_INVITE); - _tc.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_SELF_JOIN); - _tc.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_JOIN); - _tc.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT); - _tc.subscribe(this, Tox_Event_Type::TOX_EVENT_CONFERENCE_INVITE); -} - -AutoDirty::AutoDirty(ToxClient& tc) : _tc(tc) { - subscribe(); +AutoDirty::AutoDirty(ToxClient& tc) : _tc(tc), _tep_sr(_tc.newSubRef(this)) { + // TODO: add more events + _tep_sr + .subscribe(Tox_Event_Type::TOX_EVENT_SELF_CONNECTION_STATUS) + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS) + .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_REQUEST) + .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_CONFERENCE_INVITE) + ; } bool AutoDirty::onToxEvent(const Tox_Event_Self_Connection_Status*) { diff --git a/src/auto_dirty.hpp b/src/auto_dirty.hpp index 27409c07..95d2dfab 100644 --- a/src/auto_dirty.hpp +++ b/src/auto_dirty.hpp @@ -8,8 +8,7 @@ class ToxClient; // sets ToxClient dirty on some events class AutoDirty : public ToxEventI { ToxClient& _tc; - - void subscribe(void); // private + ToxEventProviderI::SubscriptionReference _tep_sr; public: AutoDirty(ToxClient& tc); diff --git a/src/frame_streams/stream_manager.cpp b/src/frame_streams/stream_manager.cpp index a39f9e8e..1c4be134 100644 --- a/src/frame_streams/stream_manager.cpp +++ b/src/frame_streams/stream_manager.cpp @@ -27,10 +27,12 @@ StreamManager::Connection::Connection( } } -StreamManager::StreamManager(ObjectStore2& os) : _os(os) { - _os.subscribe(this, ObjectStore_Event::object_construct); - //_os.subscribe(this, ObjectStore_Event::object_update); - _os.subscribe(this, ObjectStore_Event::object_destroy); +StreamManager::StreamManager(ObjectStore2& os) : _os(os), _os_sr(_os.newSubRef(this)) { + _os_sr + .subscribe(ObjectStore_Event::object_construct) + //.subscribe(ObjectStore_Event::object_update) + .subscribe(ObjectStore_Event::object_destroy) + ; } StreamManager::~StreamManager(void) { diff --git a/src/frame_streams/stream_manager.hpp b/src/frame_streams/stream_manager.hpp index e91d3763..7350036a 100644 --- a/src/frame_streams/stream_manager.hpp +++ b/src/frame_streams/stream_manager.hpp @@ -57,6 +57,7 @@ namespace Components { class StreamManager : protected ObjectStoreEventI { friend class StreamManagerUI; // TODO: make this go away ObjectStore2& _os; + ObjectStore2::SubscriptionReference _os_sr; struct Connection { ObjectHandle src; diff --git a/src/main_screen.cpp b/src/main_screen.cpp index 82c465f7..fbb02e34 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -24,6 +24,7 @@ MainScreen::MainScreen(SimpleConfigModel&& conf_, SDL_Renderer* renderer_, Theme mts(rmm), sm(os), tc(save_path, save_password), + tel(tc, std::cout), tpi(tc.getTox()), ad(tc), tcm(cr, tc, tc), @@ -50,7 +51,7 @@ MainScreen::MainScreen(SimpleConfigModel&& conf_, SDL_Renderer* renderer_, Theme smui(os, sm), dvt(os, sm, sdlrtu) { - tel.subscribeAll(tc); + tel.subscribeAll(); registerMessageComponents(msnj); registerToxMessageComponents(msnj); diff --git a/src/main_screen.hpp b/src/main_screen.hpp index 7519d61d..59d3b7af 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -65,8 +65,8 @@ struct MainScreen final : public Screen { StreamManager sm; - ToxEventLogger tel{std::cout}; ToxClient tc; + ToxEventLogger tel; ToxPrivateImpl tpi; AutoDirty ad; ToxContactModel2 tcm; diff --git a/src/media_meta_info_loader.cpp b/src/media_meta_info_loader.cpp index e85d3f84..93939c85 100644 --- a/src/media_meta_info_loader.cpp +++ b/src/media_meta_info_loader.cpp @@ -120,15 +120,17 @@ void MediaMetaInfoLoader::handleMessage(const Message3Handle& m) { _rmm.throwEventUpdate(m); } -MediaMetaInfoLoader::MediaMetaInfoLoader(RegistryMessageModelI& rmm) : _rmm(rmm) { +MediaMetaInfoLoader::MediaMetaInfoLoader(RegistryMessageModelI& rmm) : _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)) { // HACK: make them be added externally? _image_loaders.push_back(std::make_unique()); _image_loaders.push_back(std::make_unique()); _image_loaders.push_back(std::make_unique()); _image_loaders.push_back(std::make_unique()); - _rmm.subscribe(this, RegistryMessageModel_Event::message_construct); - _rmm.subscribe(this, RegistryMessageModel_Event::message_updated); + _rmm_sr + .subscribe(RegistryMessageModel_Event::message_construct) + .subscribe(RegistryMessageModel_Event::message_updated) + ; } MediaMetaInfoLoader::~MediaMetaInfoLoader(void) { diff --git a/src/media_meta_info_loader.hpp b/src/media_meta_info_loader.hpp index 39b85798..dc80ab44 100644 --- a/src/media_meta_info_loader.hpp +++ b/src/media_meta_info_loader.hpp @@ -14,6 +14,7 @@ namespace Message::Components { class MediaMetaInfoLoader : public RegistryMessageModelEventI { protected: RegistryMessageModelI& _rmm; + RegistryMessageModelI::SubscriptionReference _rmm_sr; std::vector> _image_loaders; diff --git a/src/tox_av_voip_model.cpp b/src/tox_av_voip_model.cpp index 5f32ff1b..e0ea233d 100644 --- a/src/tox_av_voip_model.cpp +++ b/src/tox_av_voip_model.cpp @@ -491,16 +491,18 @@ void ToxAVVoIPModel::handleEvent(const Events::FriendCallState& e) { } ToxAVVoIPModel::ToxAVVoIPModel(ObjectStore2& os, ToxAVI& av, Contact3Registry& cr, ToxContactModel2& tcm) : - _os(os), _av(av), _cr(cr), _tcm(tcm) + _os(os), _av(av), _av_sr(_av.newSubRef(this)), _cr(cr), _tcm(tcm) { - _av.subscribe(this, ToxAV_Event::friend_call); - _av.subscribe(this, ToxAV_Event::friend_call_state); - _av.subscribe(this, ToxAV_Event::friend_audio_bitrate); - _av.subscribe(this, ToxAV_Event::friend_video_bitrate); - _av.subscribe(this, ToxAV_Event::friend_audio_frame); - _av.subscribe(this, ToxAV_Event::friend_video_frame); - _av.subscribe(this, ToxAV_Event::iterate_audio); - _av.subscribe(this, ToxAV_Event::iterate_video); + _av_sr + .subscribe(ToxAV_Event::friend_call) + .subscribe(ToxAV_Event::friend_call_state) + .subscribe(ToxAV_Event::friend_audio_bitrate) + .subscribe(ToxAV_Event::friend_video_bitrate) + .subscribe(ToxAV_Event::friend_audio_frame) + .subscribe(ToxAV_Event::friend_video_frame) + .subscribe(ToxAV_Event::iterate_audio) + .subscribe(ToxAV_Event::iterate_video) + ; // attach to all tox friend contacts diff --git a/src/tox_av_voip_model.hpp b/src/tox_av_voip_model.hpp index fd024a38..632ae246 100644 --- a/src/tox_av_voip_model.hpp +++ b/src/tox_av_voip_model.hpp @@ -18,6 +18,7 @@ struct ToxAVCallVideoSink; class ToxAVVoIPModel : protected ToxAVEventI, public VoIPModelI { ObjectStore2& _os; ToxAVI& _av; + ToxAVI::SubscriptionReference _av_sr; Contact3Registry& _cr; ToxContactModel2& _tcm; diff --git a/src/tox_avatar_manager.cpp b/src/tox_avatar_manager.cpp index 70f3abce..c39f13da 100644 --- a/src/tox_avatar_manager.cpp +++ b/src/tox_avatar_manager.cpp @@ -33,9 +33,11 @@ ToxAvatarManager::ToxAvatarManager( ObjectStore2& os, Contact3Registry& cr, ConfigModelI& conf -) : /*_rmm(rmm)*/ _os(os), _cr(cr), _conf(conf) { - _os.subscribe(this, ObjectStore_Event::object_construct); - _os.subscribe(this, ObjectStore_Event::object_update); +) : /*_rmm(rmm)*/ _os(os), _os_sr(_os.newSubRef(this)), _cr(cr), _conf(conf) { + _os_sr + .subscribe(ObjectStore_Event::object_construct) + .subscribe(ObjectStore_Event::object_update) + ; if (!_conf.has_string("ToxAvatarManager", "save_path")) { // or on linux: $HOME/.config/tox/avatars/ diff --git a/src/tox_avatar_manager.hpp b/src/tox_avatar_manager.hpp index 69a96d0f..7863b443 100644 --- a/src/tox_avatar_manager.hpp +++ b/src/tox_avatar_manager.hpp @@ -14,6 +14,7 @@ struct ToxKey; class ToxAvatarManager : public ObjectStoreEventI { ObjectStore2& _os; + ObjectStore2::SubscriptionReference _os_sr; Contact3Registry& _cr; ConfigModelI& _conf; diff --git a/src/tox_friend_faux_offline_messaging.cpp b/src/tox_friend_faux_offline_messaging.cpp index 9769548f..10f2f194 100644 --- a/src/tox_friend_faux_offline_messaging.cpp +++ b/src/tox_friend_faux_offline_messaging.cpp @@ -30,8 +30,8 @@ ToxFriendFauxOfflineMessaging::ToxFriendFauxOfflineMessaging( ToxContactModel2& tcm, ToxI& t, ToxEventProviderI& tep -) : _cr(cr), _rmm(rmm), _tcm(tcm), _t(t), _tep(tep) { - _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS); +) : _cr(cr), _rmm(rmm), _tcm(tcm), _t(t), _tep_sr(tep.newSubRef(this)) { + _tep_sr.subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS); } float ToxFriendFauxOfflineMessaging::tick(float time_delta) { diff --git a/src/tox_friend_faux_offline_messaging.hpp b/src/tox_friend_faux_offline_messaging.hpp index 3a326aac..b13ebff1 100644 --- a/src/tox_friend_faux_offline_messaging.hpp +++ b/src/tox_friend_faux_offline_messaging.hpp @@ -18,7 +18,7 @@ class ToxFriendFauxOfflineMessaging : public ToxEventI { RegistryMessageModelI& _rmm; ToxContactModel2& _tcm; ToxI& _t; - ToxEventProviderI& _tep; + ToxEventProviderI::SubscriptionReference _tep_sr; float _interval_timer{0.f};