Skip to content

Commit

Permalink
Fixes #5583. Allow LIRC device to be set and allow LIRC to be reset e…
Browse files Browse the repository at this point in the history
…xternally. This makes setting up a machine with multiple LIRC devices a simpler affair.

git-svn-id: http://svn.mythtv.org/svn/trunk@19499 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
daniel-kristjansson committed Dec 30, 2008
1 parent 693a55c commit 2aa4aa5
Show file tree
Hide file tree
Showing 8 changed files with 629 additions and 168 deletions.
626 changes: 515 additions & 111 deletions mythtv/libs/libmythui/lirc.cpp

Large diffs are not rendered by default.

60 changes: 38 additions & 22 deletions mythtv/libs/libmythui/lirc.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
#ifndef LIRC_H_
#define LIRC_H_

#include <QThread>
#include <QByteArray>
#include <QString>
#include <QObject>
#include <QThread>
#include <QMutex>
#include <QList>

#include <lirc/lirc_client.h>
class LIRCPriv;

/** \class LircThread
* \brief Interface between mythtv and lircd
*
* Create connection to the lircd daemon and translate remote keypresses
* into custom events which are posted to the mainwindow.
*/
class LircThread : public QThread
class LIRC : public QThread
{
Q_OBJECT
public:
LircThread(QObject *main_window);
~LircThread();
int Init(const QString &config_file, const QString &program,
bool ignoreExtApp=false);
void Stop(void) { m_bStop = true; }
LIRC(QObject *main_window,
const QString &lircd_device,
const QString &our_program,
const QString &config_file,
const QString &external_app);
bool Init(void);

private:
void run(void);
void SpawnApp(void);
virtual void start(void);
virtual void deleteLater(void);

struct lirc_config *m_lircConfig;
QObject *m_mainWindow;
volatile bool m_bStop;
int m_fd;
private:
virtual ~LIRC();
void TeardownAll();

QString m_externalApp;
bool IsDoRunSet(void) const;
virtual void run(void);
void SpawnApp(void);
QList<QByteArray> GetCodes(void);
void Process(const QByteArray &data);

mutable QMutex lock;
static QMutex lirclib_lock;
QObject *m_mainWindow; ///< window to send key events to
QString lircdDevice; ///< device on which to receive lircd data
QString program; ///< program to extract from config file
QString configFile; ///< file containing LIRC->key mappings
QString m_externalApp; ///< external application for keys
bool doRun;
int lircd_socket;
uint buf_offset;
QByteArray buf;
uint eofCount;
uint retryCount;
LIRCPriv *d;
};

#endif
14 changes: 7 additions & 7 deletions mythtv/libs/libmythui/lircevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#include "mythmainwindow.h"
#include "lircevent.h"

LircEventLock::LircEventLock(bool lock_events)
: m_eventsLocked(false)
LircEventLock::LircEventLock(bool lock_events)
: events_locked(false)
{
if (lock_events)
lock();
}

LircEventLock::~LircEventLock()
{
if (m_eventsLocked)
if (events_locked)
unlock();
}

Expand All @@ -22,9 +22,9 @@ void LircEventLock::lock()
MythMainWindow *mw = GetMythMainWindow();
if (mw)
{
m_eventsLocked = true;
events_locked = true;
QApplication::postEvent((QObject *)mw,
new LircMuteEvent(m_eventsLocked));
new LircMuteEvent(events_locked));
}
}

Expand All @@ -33,8 +33,8 @@ void LircEventLock::unlock()
MythMainWindow *mw = GetMythMainWindow();
if (mw)
{
m_eventsLocked = false;
events_locked = false;
QApplication::postEvent((QObject *)mw,
new LircMuteEvent(m_eventsLocked));
new LircMuteEvent(events_locked));
}
}
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/lircevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LircEventLock
void unlock();

private:
bool m_eventsLocked;
bool events_locked;
};

#endif
56 changes: 34 additions & 22 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
#include <HIToolbox/Menus.h> // For GetMBarHeight()
#endif

#ifdef USE_LIRC
#include "lirc.h"
#include "lircevent.h"
#endif

#ifdef USING_APPLEREMOTE
#include "AppleRemoteListener.h"
#include "lircevent.h"
#endif

#ifdef USE_JOYSTICK_MENU
Expand Down Expand Up @@ -118,9 +115,7 @@ class MythMainWindowPrivate
bool ignore_lirc_keys;
bool ignore_joystick_keys;

#ifdef USE_LIRC
LircThread *lircThread;
#endif
LIRC *lircThread;

#ifdef USE_JOYSTICK_MENU
JoystickMenuThread *joystickThread;
Expand Down Expand Up @@ -336,16 +331,8 @@ MythMainWindow::MythMainWindow(const bool useDB)

installEventFilter(this);

#ifdef USE_LIRC
QString config_file = GetConfDir() + "/lircrc";
if (!QFile::exists(config_file))
config_file = QDir::homePath() + "/.lircrc";

d->lircThread = NULL;
d->lircThread = new LircThread(this);
if (!d->lircThread->Init(config_file, "mythtv"))
d->lircThread->start();
#endif
StartLIRC();

#ifdef USE_JOYSTICK_MENU
d->ignore_joystick_keys = false;
Expand Down Expand Up @@ -449,13 +436,7 @@ MythMainWindow::~MythMainWindow()
#ifdef USE_LIRC
if (d->lircThread)
{
if (d->lircThread->isRunning())
{
d->lircThread->Stop();
d->lircThread->wait();
}

delete d->lircThread;
d->lircThread->deleteLater();
d->lircThread = NULL;
}
#endif
Expand Down Expand Up @@ -1762,4 +1743,35 @@ QRect MythMainWindow::GetUIScreenRect(void)
return d->uiScreenRect;
}

void MythMainWindow::StartLIRC(void)
{
#ifdef USE_LIRC
if (d->lircThread)
{
d->lircThread->deleteLater();
d->lircThread = NULL;
}

QString config_file = GetConfDir() + "/lircrc";
if (!QFile::exists(config_file))
config_file = QDir::homePath() + "/.lircrc";

d->lircThread = new LIRC(
this,
GetMythDB()->GetSetting("LircSocket", "/dev/lircd"),
"mythtv", config_file,
GetMythDB()->GetSetting("LircKeyPressedApp", ""));

if (d->lircThread->Init())
{
d->lircThread->start();
}
else
{
d->lircThread->deleteLater();
d->lircThread = NULL;
}
#endif
}

/* vim: set expandtab tabstop=4 shiftwidth=4: */
2 changes: 2 additions & 0 deletions mythtv/libs/libmythui/mythmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class MPUBLIC MythMainWindow : public QWidget
int NormY(const int y);
int fonTweak;

void StartLIRC(void);

/* compatability functions, to go away once everything's mythui */
void attach(QWidget *child);
void detach(QWidget *child);
Expand Down
28 changes: 23 additions & 5 deletions mythtv/programs/mythfrontend/globalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2313,10 +2313,22 @@ static HostLineEdit *HaltCommand()
return ge;
}

static HostLineEdit *LircDaemonDevice()
{
HostLineEdit *ge = new HostLineEdit("LircSocket");
ge->setLabel(QObject::tr("LIRC Daemon Socket"));
ge->setValue("/dev/lircd");
QString help = QObject::tr(
"UNIX socket or IP address[:port] to connect in "
"order to communicate with the LIRC Daemon.");
ge->setHelpText(help);
return ge;
}

static HostLineEdit *LircKeyPressedApp()
{
HostLineEdit *ge = new HostLineEdit("LircKeyPressedApp");
ge->setLabel(QObject::tr("Keypress Application"));
ge->setLabel(QObject::tr("LIRC Keypress Application"));
ge->setValue("");
ge->setHelpText(QObject::tr("External application or script to run when "
"a keypress is received by LIRC."));
Expand All @@ -2326,7 +2338,7 @@ static HostLineEdit *LircKeyPressedApp()
static HostLineEdit *ScreenShotPath()
{
HostLineEdit *ge = new HostLineEdit("ScreenShotPath");
ge->setLabel(QObject::tr("ScreenShotPath"));
ge->setLabel(QObject::tr("Screen Shot Path"));
ge->setValue("/tmp/");
ge->setHelpText(QObject::tr("Path to screenshot storage location. Should be writable by the frontend"));
return ge;
Expand Down Expand Up @@ -4630,10 +4642,7 @@ MainGeneralSettings::MainGeneralSettings()
general->setLabel(QObject::tr("General"));
general->addChild(UseArrowAccels());
general->addChild(EnableXbox());
general->addChild(LircKeyPressedApp());
general->addChild(ScreenShotPath());
general->addChild(NetworkControlEnabled());
general->addChild(NetworkControlPort());
addChild(general);

VerticalConfigurationGroup *media =
Expand All @@ -4660,6 +4669,15 @@ MainGeneralSettings::MainGeneralSettings()
exit->addChild(shutdownSettings);
addChild(exit);

VerticalConfigurationGroup *remotecontrol =
new VerticalConfigurationGroup(false, true, false, false);
remotecontrol->setLabel(QObject::tr("Remote Control"));
remotecontrol->addChild(LircDaemonDevice());
remotecontrol->addChild(LircKeyPressedApp());
remotecontrol->addChild(NetworkControlEnabled());
remotecontrol->addChild(NetworkControlPort());
addChild(remotecontrol);

MythLogSettings *mythlog = new MythLogSettings();
addChild(mythlog);

Expand Down
9 changes: 9 additions & 0 deletions mythtv/programs/mythfrontend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,13 @@ void signal_USR1_handler(int){
gContext->ActivateSettingsCache(true);
}

void signal_USR2_handler(int)
{
VERBOSE(VB_GENERAL, "SIG USR2 received, restart LIRC handler");
GetMythMainWindow()->StartLIRC();
}


int internal_media_init()
{
REG_MEDIAPLAYER("Internal", "MythTV's native media player.",
Expand Down Expand Up @@ -1341,6 +1348,8 @@ int main(int argc, char **argv)

// Setup handler for USR1 signals to reload theme
signal(SIGUSR1, &signal_USR1_handler);
// Setup handler for USR2 signals to restart LIRC
signal(SIGUSR2, &signal_USR2_handler);

qApp->exec();

Expand Down

0 comments on commit 2aa4aa5

Please sign in to comment.