Skip to content
Permalink
Browse files

MythBackend status: Add details about frontends and other backends.

As for the mythfrontend status updates, this uses the UPnP SSDP cache
and hence may not be entirely accurate for multiple frontends/backends
on the same IP and filtering out of the current slave backend may not
always work.
  • Loading branch information
Mark Kendall
Mark Kendall committed May 16, 2011
1 parent bf0d172 commit 5545696cb3e33a3fffc6630fe0bc821bd4b53471
Showing with 172 additions and 1 deletion.
  1. +170 −1 mythtv/programs/mythbackend/httpstatus.cpp
  2. +2 −0 mythtv/programs/mythbackend/httpstatus.h
@@ -39,6 +39,7 @@
#include "mythsystem.h"
#include "exitcodes.h"
#include "jobqueue.h"
#include "upnp.h"

/////////////////////////////////////////////////////////////////////////////
//
@@ -284,6 +285,84 @@ void HttpStatus::FillStatusXML( QDomDocument *pDoc )

scheduled.setAttribute("count", iNumRecordings);

// Add known frontends

QDomElement frontends = pDoc->createElement("Frontends");
root.appendChild(frontends);

SSDPCacheEntries* fes = SSDP::Find("urn:schemas-mythtv-org:service:MythFrontend:1");
if (fes)
{
fes->AddRef();
fes->Lock();
EntryMap* map = fes->GetEntryMap();
frontends.setAttribute( "count", map->size() );
QMapIterator< QString, DeviceLocation * > i(*map);
while (i.hasNext())
{
i.next();
QDomElement fe = pDoc->createElement("Frontend");
frontends.appendChild(fe);
QUrl url(i.value()->m_sLocation);
fe.setAttribute("name", url.host());
fe.setAttribute("url", i.value()->m_sLocation);
}
fes->Unlock();
fes->Release();
}

// Other backends

QDomElement backends = pDoc->createElement("Backends");
root.appendChild(backends);

int numbes = 0;
if (!gCoreContext->IsMasterBackend())
{
numbes++;
QString masterhost = gCoreContext->GetMasterHostName();
QString masterip = gCoreContext->GetSetting("MasterServerIP");
QString masterport = gCoreContext->GetSettingOnHost("BackendStatusPort", masterhost, "6544");

QDomElement mbe = pDoc->createElement("Backend");
backends.appendChild(mbe);
mbe.setAttribute("type", "Master");
mbe.setAttribute("name", masterhost);
mbe.setAttribute("url" , masterip + ":" + masterport);
}

SSDPCacheEntries* sbes = SSDP::Find("urn:schemas-mythtv-org:device:SlaveMediaServer:1");
if (sbes)
{

QString ipaddress = QString();
if (!UPnp::g_IPAddrList.isEmpty())
ipaddress = UPnp::g_IPAddrList.at(0);

sbes->AddRef();
sbes->Lock();
EntryMap* map = sbes->GetEntryMap();
QMapIterator< QString, DeviceLocation * > i(*map);
while (i.hasNext())
{
i.next();
QUrl url(i.value()->m_sLocation);
if (url.host() != ipaddress)
{
numbes++;
QDomElement mbe = pDoc->createElement("Backend");
backends.appendChild(mbe);
mbe.setAttribute("type", "Slave");
mbe.setAttribute("name", url.toString(QUrl::RemovePath));
mbe.setAttribute("url" , i.value()->m_sLocation);
}
}
sbes->Unlock();
sbes->Release();
}

backends.setAttribute("count", numbes);

// Add Job Queue Entries

QDomElement jobqueue = pDoc->createElement("JobQueue");
@@ -579,14 +658,27 @@ void HttpStatus::PrintStatus( QTextStream &os, QDomDocument *pDoc )
if (!node.isNull())
PrintScheduled( os, node.toElement());

// Frontends

node = docElem.namedItem( "Frontends" );

if (!node.isNull())
PrintFrontends (os, node.toElement());

// Backends

node = docElem.namedItem( "Backends" );

if (!node.isNull())
PrintBackends (os, node.toElement());

// Job Queue Entries -----------------------

node = docElem.namedItem( "JobQueue" );

if (!node.isNull())
PrintJobQueue( os, node.toElement());


// Machine information ---------------------

node = docElem.namedItem( "MachineInfo" );
@@ -881,6 +973,83 @@ int HttpStatus::PrintScheduled( QTextStream &os, QDomElement scheduled )
//
/////////////////////////////////////////////////////////////////////////////

int HttpStatus::PrintFrontends( QTextStream &os, QDomElement frontends )
{
if (frontends.isNull())
return( 0 );

int nNumFES= frontends.attribute( "count", "0" ).toInt();

if (nNumFES < 1)
return( 0 );


os << " <div class=\"content\">\r\n"
<< " <h2 class=\"status\">Frontends</h2>\r\n";

QDomNode node = frontends.firstChild();
while (!node.isNull())
{
QDomElement e = node.toElement();

if (!e.isNull())
{
QString name = e.attribute( "name" , "" );
QString url = e.attribute( "url" , "" );
os << name << "&nbsp(<a href=\"" << url << "\">Status page</a>)<br />";
}

node = node.nextSibling();
}

os << " </div>\r\n\r\n";

return nNumFES;
}

/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

int HttpStatus::PrintBackends( QTextStream &os, QDomElement backends )
{
if (backends.isNull())
return( 0 );

int nNumBES= backends.attribute( "count", "0" ).toInt();

if (nNumBES < 1)
return( 0 );


os << " <div class=\"content\">\r\n"
<< " <h2 class=\"status\">Other Backends</h2>\r\n";

QDomNode node = backends.firstChild();
while (!node.isNull())
{
QDomElement e = node.toElement();

if (!e.isNull())
{
QString type = e.attribute( "type", "" );
QString name = e.attribute( "name" , "" );
QString url = e.attribute( "url" , "" );
os << type << ": " << name << "&nbsp(<a href=\"" << url << "\">Status page</a>)<br />";
}

node = node.nextSibling();
}

os << " </div>\r\n\r\n";

return nNumBES;
}

/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

int HttpStatus::PrintJobQueue( QTextStream &os, QDomElement jobs )
{
QString shortdateformat = gCoreContext->GetSetting("ShortDateFormat", "M/d");
@@ -63,6 +63,8 @@ class HttpStatus : public HttpServerExtension
void PrintStatus ( QTextStream &os, QDomDocument *pDoc );
int PrintEncoderStatus( QTextStream &os, QDomElement encoders );
int PrintScheduled ( QTextStream &os, QDomElement scheduled );
int PrintFrontends ( QTextStream &os, QDomElement frontends );
int PrintBackends ( QTextStream &os, QDomElement backends );
int PrintJobQueue ( QTextStream &os, QDomElement jobs );
int PrintMachineInfo ( QTextStream &os, QDomElement info );
int PrintMiscellaneousInfo ( QTextStream &os, QDomElement info );

0 comments on commit 5545696

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