Skip to content

Commit

Permalink
MythBackend status: Add details about frontends and other backends.
Browse files Browse the repository at this point in the history
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 committed May 16, 2011
1 parent bf0d172 commit 5545696
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 1 deletion.
171 changes: 170 additions & 1 deletion mythtv/programs/mythbackend/httpstatus.cpp
Expand Up @@ -39,6 +39,7 @@
#include "mythsystem.h"
#include "exitcodes.h"
#include "jobqueue.h"
#include "upnp.h"

/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions mythtv/programs/mythbackend/httpstatus.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 5545696

Please sign in to comment.