Skip to content
Permalink
Browse files

Add a new MythUDPListener class to libmythui.

To test:- mythtvosd --template=alert --alert_text='Hello world!'

This replaces the old udpnotify class in libmythtv and the new object is
owned by MythMainWindow. The UDP port setting is reinstated and moved
from the Playback screen to the General settings pages.

I've retained the XML functionality to ensure we don't pick up stray UDP
broadcast messages and to make the most of the eXtensibility once we've
settled on a general framework and UI for messaging (e.g. to add timeout
settings).

For the time being, mythtvosd will work as above but I will replace it
with a new command line utility (mythmessage?) with the template
handling removed.
  • Loading branch information
Mark Kendall
Mark Kendall committed Dec 23, 2010
1 parent 200d3bf commit 7b4f59ae03d1ffd9a3051649d57d3b06d70e9668
@@ -29,7 +29,7 @@ HEADERS += themeinfo.h mythxdisplay.h DisplayRes.h DisplayResScreen.h
HEADERS += mythgenerictree.h mythuibuttontree.h mythuiutils.h
HEADERS += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h
HEADERS += mythrender_base.h mythfontmanager.h mythuieditbar.h
HEADERS += mythdisplay.h mythuivideo.h
HEADERS += mythdisplay.h mythuivideo.h mythudplistener.h

SOURCES = mythmainwindow.cpp mythpainter.cpp mythimage.cpp mythrect.cpp
SOURCES += myththemebase.cpp mythpainter_qimage.cpp mythpainter_yuva.cpp
@@ -46,7 +46,7 @@ SOURCES += themeinfo.cpp mythxdisplay.cpp DisplayRes.cpp DisplayResScreen.cpp
SOURCES += mythgenerictree.cpp mythuibuttontree.cpp mythuiutils.cpp
SOURCES += mythvirtualkeyboard.cpp mythuishape.cpp mythuiguidegrid.cpp
SOURCES += mythfontmanager.cpp mythuieditbar.cpp
SOURCES += mythdisplay.cpp mythuivideo.cpp
SOURCES += mythdisplay.cpp mythuivideo.cpp mythudplistener.cpp


inc.path = $${PREFIX}/include/mythtv/libmythui/
@@ -50,6 +50,7 @@ using namespace std;
#include "screensaver.h"
#include "lirc.h"
#include "lircevent.h"
#include "mythudplistener.h"

#ifdef USING_APPLEREMOTE
#include "AppleRemoteListener.h"
@@ -254,6 +255,7 @@ class MythMainWindowPrivate
bool m_drawEnabled;

MythThemeBase *m_themeBase;
MythUDPListener *m_udpListener;
};

// Make keynum in QKeyEvent be equivalent to what's in QKeySequence
@@ -457,6 +459,8 @@ MythMainWindow::MythMainWindow(const bool useDB)
d->appleRemote->start();
#endif

d->m_udpListener = new MythUDPListener();

InitKeys();

d->gestureTimer = new QTimer(this);
@@ -0,0 +1,123 @@
#include <QCoreApplication>
#include <QUdpSocket>
#include <QDomDocument>

#include "mythcorecontext.h"
#include "mythverbose.h"
#include "mythmainwindow.h"
#include "mythudplistener.h"

#define LOC QString("UDPListener: ")
#define ERR QString("UPDListener Error: ")

MythUDPListener::MythUDPListener()
{
uint udp_port = gCoreContext->GetNumSetting("UDPNotifyPort", 0);
m_socket = new QUdpSocket(this);
connect(m_socket, SIGNAL(readyRead()),
this, SLOT(ReadPending()));
if (m_socket->bind(udp_port))
{
VERBOSE(VB_GENERAL, LOC + QString("bound to port %1").arg(udp_port));
}
else
{
VERBOSE(VB_GENERAL, LOC +
QString("failed to bind to port %1").arg(udp_port));
}
}

void MythUDPListener::deleteLater(void)
{
TeardownAll();
disconnect();
QObject::deleteLater();
}

void MythUDPListener::TeardownAll(void)
{
if (!m_socket)
return;

VERBOSE(VB_GENERAL, LOC + "Disconnecting");

m_socket->disconnect();
m_socket->close();
m_socket->deleteLater();
m_socket = NULL;
}

void MythUDPListener::ReadPending(void)
{
QByteArray buf;
while (m_socket->hasPendingDatagrams())
{
buf.resize(m_socket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;

m_socket->readDatagram(buf.data(), buf.size(),
&sender, &senderPort);

Process(buf);
}
}

void MythUDPListener::Process(const QByteArray &buf)
{
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
QDomDocument doc;
if (!doc.setContent(buf, false, &errorMsg, &errorLine, &errorColumn))
{
VERBOSE(VB_IMPORTANT, ERR +
QString("Parsing xml:\n\t\t\t at line: %1 column: %2\n\t\t\t%3")
.arg(errorLine).arg(errorColumn).arg(errorMsg));

return;
}

QDomElement docElem = doc.documentElement();
if (!docElem.isNull())
{
if (docElem.tagName() != "mythnotify")
{
VERBOSE(VB_IMPORTANT, ERR +
"Unknown UDP packet (not <mythnotify> XML)");
return;
}

QString version = docElem.attribute("version", "");
if (version.isEmpty())
{
VERBOSE(VB_IMPORTANT, ERR +
"<mythnotify> missing 'version' attribute");
return;
}
}

QDomNode n = docElem.firstChild();
while (!n.isNull())
{
QDomElement e = n.toElement();
if (!e.isNull())
{
if (e.tagName() == "container")
{
QString msg = e.text();
VERBOSE(VB_GENERAL, LOC + msg);
MythMainWindow *window = GetMythMainWindow();
MythEvent* me = new MythEvent(MythEvent::MythUserMessage, msg);
qApp->postEvent(window, me);
}
else
{
VERBOSE(VB_IMPORTANT, ERR + QString("Unknown element: %1")
.arg(e.tagName()));
return;
}
}
n = n.nextSibling();
}
}
@@ -0,0 +1,33 @@
#ifndef MYTHUDPLISTENER_H
#define MYTHUDPLISTENER_H

#include <QObject>

class QByteArray;
class QUdpSocket;
class QDomElement;

class MythUDPListener : public QObject
{
Q_OBJECT

public:
MythUDPListener();

public slots:
virtual void deleteLater(void);

private slots:
void ReadPending(void);

private:
~MythUDPListener(void) { TeardownAll(); }

void Process(const QByteArray &buf);
void TeardownAll(void);

private:
QUdpSocket *m_socket;
};

#endif // MYTHUDPLISTENER_H
@@ -1525,21 +1525,6 @@ static HostCheckBox *AltClearSavedPosition()
return gc;
}

// This currently does not work
/*
static HostLineEdit *UDPNotifyPort()
{
HostLineEdit *ge = new HostLineEdit("UDPNotifyPort");
ge->setLabel(QObject::tr("UDP notify port"));
ge->setValue("6948");
ge->setHelpText(QObject::tr("During playback, MythTV will listen for "
"connections from the \"mythtvosd\" or \"mythudprelay\" "
"programs on this port. For additional information, see "
"http://www.mythtv.org/wiki/MythNotify ."));
return ge;
}
*/

static HostComboBox *PlaybackExitPrompt()
{
HostComboBox *gc = new HostComboBox("PlaybackExitPrompt");
@@ -2730,6 +2715,18 @@ static HostSpinBox *NetworkControlPort()
return gs;
}

static HostLineEdit *UDPNotifyPort()
{
HostLineEdit *ge = new HostLineEdit("UDPNotifyPort");
ge->setLabel(QObject::tr("UDP notify port"));
ge->setValue("6948");
ge->setHelpText(QObject::tr("MythTV will listen for "
"connections from the \"mythtvosd\" or \"mythudprelay\" "
"programs on this port. For additional information, see "
"http://www.mythtv.org/wiki/MythNotify ."));
return ge;
}

static HostCheckBox *RealtimePriority()
{
HostCheckBox *gc = new HostCheckBox("RealtimePriority");
@@ -3380,6 +3377,7 @@ MainGeneralSettings::MainGeneralSettings()
remotecontrol->addChild(LircDaemonDevice());
remotecontrol->addChild(NetworkControlEnabled());
remotecontrol->addChild(NetworkControlPort());
remotecontrol->addChild(UDPNotifyPort());
addChild(remotecontrol);
}

@@ -3540,7 +3538,6 @@ OSDSettings::OSDSettings()
osd->addChild(SubtitleFont());
osd->addChild(OSDCC708TextZoomPercentage());
osd->addChild(SubtitleCodec());
//osd->addChild(UDPNotifyPort());
addChild(osd);

//VerticalConfigurationGroup *cc = new VerticalConfigurationGroup(false);

0 comments on commit 7b4f59a

Please sign in to comment.
You can’t perform that action at this time.