From 9fa08b101701e2a91f023180d9d847e532fc3818 Mon Sep 17 00:00:00 2001 From: pewpew Date: Sun, 16 Jul 2023 20:38:37 -0500 Subject: [PATCH] Pretty much match MxNotificationManager::FlushPending. (#91) --- LEGO1/mxnotificationmanager.cpp | 46 +++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/LEGO1/mxnotificationmanager.cpp b/LEGO1/mxnotificationmanager.cpp index 593572bb..b7d001aa 100644 --- a/LEGO1/mxnotificationmanager.cpp +++ b/LEGO1/mxnotificationmanager.cpp @@ -111,10 +111,52 @@ void MxNotificationManager::Unregister(MxCore *p_listener) } } -// OFFSET: LEGO1 0x100ac990 STUB +// OFFSET: LEGO1 0x100ac990 void MxNotificationManager::FlushPending(MxCore *p_listener) { - // TODO + MxNotificationPtrList pending; + MxNotification *notif; + + { + MxAutoLocker lock(&m_lock); + + // Find all notifications from, and addressed to, p_listener. + if (m_sendList != NULL) { + MxNotificationPtrList::iterator it = m_sendList->begin(); + while (it != m_sendList->end()) { + notif = *it; + if ((notif->GetTarget()->GetId() == p_listener->GetId()) || + (notif->GetParam()->GetSender()) && (notif->GetParam()->GetSender()->GetId() == p_listener->GetId())) { + m_sendList->erase(it++); + pending.push_back(notif); + } + else { + it++; + } + } + } + + MxNotificationPtrList::iterator it = m_queue->begin(); + while (it != m_queue->end()) { + notif = *it; + if ((notif->GetTarget()->GetId() == p_listener->GetId()) || + (notif->GetParam()->GetSender()) && (notif->GetParam()->GetSender()->GetId() == p_listener->GetId())) { + m_queue->erase(it++); + pending.push_back(notif); + } + else { + it++; + } + } + } + + // Deliver those notifications. + while (pending.size() != 0) { + notif = pending.front(); + pending.pop_front(); + notif->GetTarget()->Notify(*notif->GetParam()); + delete notif; + } } // OFFSET: LEGO1 0x100ac6c0