Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove dispatchNow() and all that uses it, re-implementing using thre…
…ad-safe methods.

dispatchNow was marked has obsoleted years ago but was still in use. Should any listeners be in a different thread, it would have crashed (like starting playback when a preview generation was occurring)
Replaces the only two methods still using this mechanism: sendPlaybackStart and sendPlaybackEnd with their thread-safe equivalent. MythMusic will have to be adapted, changes to follow

Fixes #11671
  • Loading branch information
jyavenard committed Jul 14, 2013
1 parent 22e5fb0 commit 5201ed1
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 59 deletions.
7 changes: 0 additions & 7 deletions mythtv/libs/libmythbase/mythcorecontext.cpp
Expand Up @@ -1228,13 +1228,6 @@ void MythCoreContext::dispatch(const MythEvent &event)
MythObservable::dispatch(event);
}

void MythCoreContext::dispatchNow(const MythEvent &event)
{
LOG(VB_NETWORK, LOG_INFO, QString("MythEvent: %1").arg(event.Message()));

MythObservable::dispatchNow(event);
}

void MythCoreContext::SetLocalHostname(const QString &hostname)
{
QMutexLocker locker(&d->m_localHostLock);
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythbase/mythcorecontext.h
Expand Up @@ -162,7 +162,6 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
void ClearOverrideSettingForSession(const QString &key);

void dispatch(const MythEvent &event);
void dispatchNow(const MythEvent &event); // MDEPRECATED;

void InitLocale(void);
void ReInitLocale(void);
Expand Down
12 changes: 0 additions & 12 deletions mythtv/libs/libmythbase/mythmiscutil.cpp
Expand Up @@ -541,18 +541,6 @@ QString getSymlinkTarget(const QString &start_file,
return (!fi.isSymLink()) ? cur_file : QString::null;
}

void sendPlaybackStart(void)
{
MythEvent me(QString("PLAYBACK_START %1").arg(gCoreContext->GetHostName()));
gCoreContext->dispatchNow(me);
}

void sendPlaybackEnd(void)
{
MythEvent me(QString("PLAYBACK_END %1").arg(gCoreContext->GetHostName()));
gCoreContext->dispatchNow(me);
}

bool IsMACAddress(QString MAC)
{
QStringList tokens = MAC.split(':');
Expand Down
3 changes: 0 additions & 3 deletions mythtv/libs/libmythbase/mythmiscutil.h
Expand Up @@ -36,9 +36,6 @@ MBASE_PUBLIC QString getSymlinkTarget(const QString &start_file,
QStringList *intermediaries = NULL,
unsigned maxLinks = 255);

MBASE_PUBLIC void sendPlaybackStart();
MBASE_PUBLIC void sendPlaybackEnd();

MBASE_PUBLIC void wrapList(QStringList &list, int width);

inline float clamp(float val, float minimum, float maximum)
Expand Down
21 changes: 0 additions & 21 deletions mythtv/libs/libmythbase/mythobservable.cpp
Expand Up @@ -12,9 +12,6 @@
* events to listening QObjects.
*
* MythEvents can be dispatched to all listeners by calling dispatch
* or dispatchNow. The former is much preferred as it uses
* QCoreApplication::postEvent() while the latter uses the blocking
* QCoreApplication::sendEvent().
*
* The name MythObservable is 'wrong', since all the methods refer to
* the observers as listeners (ie. addListener), however,
Expand Down Expand Up @@ -85,21 +82,3 @@ void MythObservable::dispatch(const MythEvent &event)
for (; it != m_listeners.end() ; ++it)
QCoreApplication::postEvent(*it, event.clone());
}

/** \brief Dispatch an event to all listeners
*
* This sends an event using the current thread, this is
* almost always unsafe.
*
* \param event a MythEvent to dispatch.
* \deprecated Do not use in new code
*/
void MythObservable::dispatchNow(const MythEvent &event)
{
QMutexLocker locker(m_lock);

QSet<QObject*>::const_iterator it = m_listeners.begin();
for (; it != m_listeners.end() ; ++it)
QCoreApplication::sendEvent(*it, event.clone());
}

2 changes: 0 additions & 2 deletions mythtv/libs/libmythbase/mythobservable.h
Expand Up @@ -19,8 +19,6 @@ class MBASE_PUBLIC MythObservable

void dispatch(const MythEvent &event);

void dispatchNow(const MythEvent &event); // MDEPRECATED;

bool hasListeners(void) { return !m_listeners.isEmpty(); }

protected:
Expand Down
9 changes: 2 additions & 7 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -332,17 +332,13 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
curProgram->SetIgnoreBookmark(flags & kStartTVIgnoreBookmark);
}

// Must be before Init() otherwise we swallow the PLAYBACK_START event
// with the event filter
sendPlaybackStart();
GetMythMainWindow()->PauseIdleTimer(true);

// Initialize TV
if (!tv->Init())
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Failed initializing TV");
ReleaseTV(tv);
sendPlaybackEnd();
GetMythMainWindow()->PauseIdleTimer(false);
delete curProgram;
gCoreContext->emitTVPlaybackAborted();
Expand Down Expand Up @@ -454,10 +450,10 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
bool allowrerecord = tv->getAllowRerecord();
bool deleterecording = tv->requestDelete;

gCoreContext->emitTVPlaybackStopped();

ReleaseTV(tv);

gCoreContext->emitTVPlaybackStopped();

if (curProgram)
{
if (startSysEventSent)
Expand Down Expand Up @@ -495,7 +491,6 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
ss->AddScreen(dlg);
}

sendPlaybackEnd();
GetMythMainWindow()->PauseIdleTimer(false);

LOG(VB_PLAYBACK, LOG_INFO, LOC + "StartTV -- end");
Expand Down
4 changes: 2 additions & 2 deletions mythtv/programs/mythfrontend/main.cpp
Expand Up @@ -740,10 +740,10 @@ static void playDisc()
command_string =
command_string.replace(QRegExp("%d"), dvd_device);
}
sendPlaybackStart();
gCoreContext->emitTVPlaybackStarted();
GetMythMainWindow()->PauseIdleTimer(true);
myth_system(command_string);
sendPlaybackEnd();
gCoreContext->emitTVPlaybackStopped();
GetMythMainWindow()->PauseIdleTimer(false);
if (GetMythMainWindow())
{
Expand Down
8 changes: 4 additions & 4 deletions mythtv/programs/mythfrontend/videoplayercommand.cpp
Expand Up @@ -152,11 +152,7 @@ class VideoPlayMythSystem : public VideoPlayProc

bool Play() const
{
sendPlaybackStart();
GetMythMainWindow()->PauseIdleTimer(true);
myth_system(m_play_command);
sendPlaybackEnd();
GetMythMainWindow()->PauseIdleTimer(false);

return true;
}
Expand Down Expand Up @@ -416,7 +412,11 @@ void VideoPlayerCommand::Play() const
lcd->setFunctionLEDs(FUNC_TV, false);
lcd->setFunctionLEDs(FUNC_MOVIE, true);
}
gCoreContext->WantingPlayback(NULL);
GetMythMainWindow()->PauseIdleTimer(true);
m_d->Play();
gCoreContext->emitTVPlaybackStopped();
GetMythMainWindow()->PauseIdleTimer(false);
GetMythMainWindow()->raise();
GetMythMainWindow()->activateWindow();
if (GetMythMainWindow()->currentWidget())
Expand Down

0 comments on commit 5201ed1

Please sign in to comment.