Skip to content

Commit

Permalink
Fix AppleRemote re-entrancy bug. The CFRunLoop didn't like being star…
Browse files Browse the repository at this point in the history
…ted,

stopped, and then re-started, so I have gone back to the original code.
(which never actually deleted the object -
 it just re-used the first-created instance). Refs #5501.


git-svn-id: http://svn.mythtv.org/svn/trunk@18133 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
NigelPearson committed Aug 11, 2008
1 parent b34ea3d commit 6be5ffd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 4 additions & 8 deletions mythtv/libs/libmythui/AppleRemote.cpp
Expand Up @@ -30,13 +30,13 @@ AppleRemote::Listener::~Listener()
{
}

AppleRemote&
AppleRemote::instance()
AppleRemote *
AppleRemote::Get()
{
if (_instance == 0)
_instance = new AppleRemote();

return *_instance;
return _instance;
}

AppleRemote::~AppleRemote()
Expand Down Expand Up @@ -103,11 +103,7 @@ void
AppleRemote::run()
{
CFRunLoopRun();
}

void
AppleRemote::quit()
{
exec(); // prevent QThread exiting, by entering its run loop
CFRunLoopStop(CFRunLoopGetCurrent());
}

Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythui/AppleRemote.h
Expand Up @@ -35,7 +35,7 @@ class AppleRemote : public QThread
virtual void appleRemoteButton(Event button, bool pressedDown) = 0;
};

static AppleRemote& instance();
static AppleRemote * Get();
~AppleRemote();

bool isListeningToRemote();
Expand All @@ -46,7 +46,6 @@ class AppleRemote : public QThread
void startListening();
void stopListening();
void run();
void quit();

protected:
AppleRemote(); // will be a singleton class
Expand Down
14 changes: 7 additions & 7 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -337,7 +337,7 @@ MythMainWindow::MythMainWindow(const bool useDB)

#ifdef USING_APPLEREMOTE
d->appleRemoteListener = new AppleRemoteListener(this);
d->appleRemote = &AppleRemote::instance();
d->appleRemote = AppleRemote::Get();

d->appleRemote->setListener(d->appleRemoteListener);
d->appleRemote->startListening();
Expand Down Expand Up @@ -430,16 +430,12 @@ MythMainWindow::~MythMainWindow()
#endif

#ifdef USING_APPLEREMOTE
// We don't delete this, just disable its plumbing. If we create another
// MythMainWindow later, AppleRemote::get() will retrieve the instance.
if (d->appleRemote->isRunning())
{
d->appleRemote->stopListening();
d->appleRemote->quit();
}
delete d->appleRemote;
d->appleRemote = NULL;

delete d->appleRemoteListener;
d->appleRemoteListener = NULL;
#endif

delete d;
Expand Down Expand Up @@ -1283,6 +1279,10 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
{
QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e);

// Work around weird GCC run-time bug. Only manifest on Mac OS X
if (!ke)
ke = (QKeyEvent *)e;

if (currentWidget())
{
ke->accept();
Expand Down

0 comments on commit 6be5ffd

Please sign in to comment.