Skip to content

Commit

Permalink
Fix notifications not using their allocated screen should the client …
Browse files Browse the repository at this point in the history
…unregistered before notifications queued could be processed.

Fix notification leaks should screen failing to be created...
  • Loading branch information
jyavenard committed Jul 9, 2013
1 parent 23b11ac commit 9665e95
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
63 changes: 50 additions & 13 deletions mythtv/libs/libmythui/mythuinotificationcenter.cpp
Expand Up @@ -489,6 +489,7 @@ NCPrivate::~NCPrivate()

QMutexLocker lock(&m_lock);

DeleteUnregistered();
DeleteAllRegistrations();
DeleteAllScreens();

Expand Down Expand Up @@ -550,6 +551,7 @@ void NCPrivate::ScreenDeleted(void)
{
// we're in the middle of being deleted
m_registrations.remove(screen->m_id);
m_unregistered.remove(screen->m_id);
}
else
{
Expand Down Expand Up @@ -648,6 +650,7 @@ void NCPrivate::ProcessQueue(void)
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("ProcessQueue: couldn't create required screen"));
delete n;
continue; // something is wrong ; ignore
}
if (id > 0)
Expand All @@ -667,6 +670,7 @@ void NCPrivate::ProcessQueue(void)
if (!screen->Create())
{
delete screen;
delete n;
continue;
}
created = true;
Expand All @@ -683,6 +687,8 @@ void NCPrivate::ProcessQueue(void)
delete n;
}
m_notifications.clear();

DeleteUnregistered();
}

/**
Expand Down Expand Up @@ -748,19 +754,9 @@ void NCPrivate::UnRegister(void *from, int id, bool closeimemdiately)
.arg(id));
}

if (m_registrations.contains(id))
{
MythUINotificationScreen *screen = m_registrations[id];
if (screen != NULL)
{
// mark the screen for deletion if no timer is set
if (screen->m_duration <= 0 || closeimemdiately)
{
m_deletedScreens.append(screen);
}
}
m_registrations.remove(id);
}
// queue the de-registration
m_unregistered[id] = closeimemdiately;

m_clients.remove(id);

// Tell the GUI thread we have something to process
Expand Down Expand Up @@ -793,6 +789,47 @@ void NCPrivate::DeleteAllScreens(void)
}
}

void NCPrivate::DeleteUnregistered(void)
{
QMap<int,bool>::iterator it = m_unregistered.begin();
bool needdelete = false;

for (; it != m_unregistered.end(); ++it)
{
int id = it.key();
bool closeimemdiately = it.value();
MythUINotificationScreen *screen = NULL;

if (m_registrations.contains(id))
{
screen = m_registrations[id];
if (screen != NULL && !m_suspended.contains(id))
{
// mark the screen for deletion if no timer is set
if (screen->m_duration <= 0 || closeimemdiately)
{
m_deletedScreens.append(screen);
needdelete = true;
}
}
m_registrations.remove(id);
}

if (m_suspended.contains(id))
{
// screen had been suspended, delete suspended screen
delete screen;
m_suspended.removeAll(id);
}
}
m_unregistered.clear();

if (needdelete)
{
DeleteAllScreens();
}
}

/**
* Insert screen into list of screens.
* Returns index in screens list.
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythui/mythuinotificationcenter_private.h
Expand Up @@ -108,6 +108,7 @@ public slots:
int id = -1);
void DeleteAllRegistrations(void);
void DeleteAllScreens(void);
void DeleteUnregistered(void);
int InsertScreen(MythUINotificationScreen *screen);
int RemoveScreen(MythUINotificationScreen *screen);
void RefreshScreenPosition(int from = 0);
Expand All @@ -118,6 +119,7 @@ public slots:
QList<MythUINotificationScreen*> m_deletedScreens;
QMap<int, MythUINotificationScreen*> m_registrations;
QList<int> m_suspended;
QMap<int,bool> m_unregistered;
QMap<int, void*> m_clients;
QMutex m_lock;
int m_currentId;
Expand Down

0 comments on commit 9665e95

Please sign in to comment.