Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MythFEXML: Add a GetStatus request to the frontend http interface.

This is an initial proof of concept and the format and content are
likely to change extensively in the coming weeks.
  • Loading branch information...
commit 45130c1f0383892ee50dbc94c39b770b264b6df6 1 parent ec440d6
Mark Kendall authored
25 mythtv/libs/libmythtv/tv_play.cpp
View
@@ -1326,6 +1326,27 @@ TVState TV::GetState(int player_idx) const
return ret;
}
+void TV::GetStatus(void)
+{
+ const PlayerContext *ctx = GetPlayerReadLock(-1, __FILE__, __LINE__);
+
+ osdInfo status;
+ status.text.insert("state", StateToString(GetState(ctx)));
+ ctx->LockPlayingInfo(__FILE__, __LINE__);
+ if (ctx->playingInfo)
+ {
+ status.text.insert("title", ctx->playingInfo->GetTitle());
+ status.text.insert("subtitle", ctx->playingInfo->GetSubtitle());
+ }
+ ctx->UnlockPlayingInfo(__FILE__, __LINE__);
+ ctx->CalcPlayerSliderPosition(status);
+
+ ReturnPlayerLock(ctx);
+
+ MythInfoMapEvent info("STATUS_UPDATE", status.text);
+ gCoreContext->dispatch(info);
+}
+
/**
* \brief get tv state of active player context
*/
@@ -8278,6 +8299,10 @@ void TV::customEvent(QEvent *e)
}
ReturnPlayerLock(mctx);
}
+ else if (message == ACTION_GETSTATUS)
+ {
+ GetStatus();
+ }
else if (message.left(14) == "DONE_RECORDING")
{
// int seconds = 0;
1  mythtv/libs/libmythtv/tv_play.h
View
@@ -229,6 +229,7 @@ class MTV_PUBLIC TV : public QObject
int GetLastRecorderNum(int player_idx) const;
TVState GetState(int player_idx) const;
TVState GetState(const PlayerContext*) const;
+ void GetStatus(void);
// Non-const queries
OSD *GetOSDL(const char *, int);
7 mythtv/libs/libmythui/mythmainwindow.cpp
View
@@ -2309,6 +2309,13 @@ void MythMainWindow::customEvent(QEvent *ce)
}
ScreenShot(width, height, filename);
}
+ else if (message == ACTION_GETSTATUS)
+ {
+ QHash<QString,QString> status;
+ status.insert("state", "idle");
+ MythInfoMapEvent info("STATUS_UPDATE", status);
+ gCoreContext->dispatch(info);
+ }
}
else if ((MythEvent::Type)(ce->type()) == MythEvent::MythUserMessage)
{
1  mythtv/libs/libmythui/mythuiactions.h
View
@@ -24,4 +24,5 @@
#define ACTION_TVPOWEROFF "TVPOWEROFF"
#define ACTION_TVPOWERON "TVPOWERON"
+#define ACTION_GETSTATUS "GETSTATUS"
#endif // MYTHUI_ACTIONS_H
73 mythtv/programs/mythfrontend/mythfexml.cpp
View
@@ -31,7 +31,8 @@
/////////////////////////////////////////////////////////////////////////////
MythFEXML::MythFEXML( UPnpDevice *pDevice , const QString sSharePath)
- : Eventing( "MythFEXML", "MYTHTV_Event", sSharePath)
+ : Eventing( "MythFEXML", "MYTHTV_Event", sSharePath),
+ m_statusLock(new QMutex())
{
QString sUPnpDescPath =
@@ -43,6 +44,9 @@ MythFEXML::MythFEXML( UPnpDevice *pDevice , const QString sSharePath)
// Add our Service Definition to the device.
RegisterService( pDevice );
+
+ // listen for status updates
+ gCoreContext->addListener(this);
}
/////////////////////////////////////////////////////////////////////////////
@@ -51,6 +55,35 @@ MythFEXML::MythFEXML( UPnpDevice *pDevice , const QString sSharePath)
MythFEXML::~MythFEXML()
{
+ gCoreContext->removeListener(this);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+//
+/////////////////////////////////////////////////////////////////////////////
+
+void MythFEXML::customEvent(QEvent *e)
+{
+ if (e->type() != MythEvent::MythEventMessage)
+ return;
+
+ MythEvent *me = (MythEvent *)e;
+ if ("STATUS_UPDATE" == me->Message())
+ {
+ MythInfoMapEvent *info = (MythInfoMapEvent*)e;
+ if (info && info->InfoMap())
+ {
+ QMutexLocker lock(m_statusLock);
+ m_latestStatus.clear();
+ QHashIterator<QString,QString> it(*info->InfoMap());
+ while (it.hasNext())
+ {
+ it.next();
+ m_latestStatus.insert(it.key(), it.value());
+ }
+ m_statusWait.wakeAll();
+ }
+ }
}
/////////////////////////////////////////////////////////////////////////////
@@ -66,6 +99,7 @@ MythFEXMLMethod MythFEXML::GetMethod(const QString &sURI)
if (sURI == "GetActionList") return MFEXML_ActionList;
if (sURI == "GetActionTest") return MFEXML_ActionListTest;
if (sURI == "GetRemote") return MFEXML_GetRemote;
+ if (sURI == "GetStatus") return MFEXML_GetStatus;
return( MFEXML_Unknown );
}
@@ -117,6 +151,9 @@ bool MythFEXML::ProcessRequest( HTTPRequest *pRequest )
case MFEXML_GetRemote:
GetRemote(pRequest);
break;
+ case MFEXML_GetStatus:
+ GetStatus(pRequest);
+ break;
default:
UPnp::FormatErrorResponse(pRequest, UPnPResult_InvalidAction);
}
@@ -275,6 +312,40 @@ void MythFEXML::GetActionListTest(HTTPRequest *pRequest)
}
+void MythFEXML::GetStatus(HTTPRequest *pRequest)
+{
+ QMutexLocker lock(m_statusLock);
+
+ pRequest->m_eResponseType = ResponseTypeXML;
+ pRequest->m_mapHeaders[ "Cache-Control" ] = "no-cache=\"Ext\", max-age = 1";
+
+ QTime now = QTime::currentTime();
+ int since = m_lastUpdate.msecsTo(now);
+
+ if (m_latestStatus.isEmpty() || (since < 0) || (since > 500))
+ {
+ m_lastUpdate = now;
+ MythEvent *req = new MythEvent(ACTION_GETSTATUS);
+ qApp->postEvent(GetMythMainWindow(), req);
+ if (!m_statusWait.wait(m_statusLock, 1000))
+ {
+ LOG(VB_GENERAL, LOG_ERR,
+ "MythFEXML::GetStatus - failed to update status.");
+ }
+ }
+
+ QTextStream stream( &pRequest->m_response );
+ stream << "<mythstatus version=\"1\">\n";
+ QHashIterator<QString,QString> it(m_latestStatus);
+ while (it.hasNext())
+ {
+ it.next();
+ stream << " <";
+ stream << it.key() << ">" << it.value() << "</" << it.key() << ">\n";
+ }
+ stream << "</mythstatus>\n";
+}
+
void MythFEXML::GetActionList(HTTPRequest *pRequest)
{
InitActions();
10 mythtv/programs/mythfrontend/mythfexml.h
View
@@ -9,6 +9,7 @@
#define MYTHFEXML_H_
#include <QDateTime>
+#include <QWaitCondition>
#include "upnp.h"
#include "eventing.h"
@@ -24,6 +25,7 @@ typedef enum
MFEXML_ActionList,
MFEXML_ActionListTest,
MFEXML_GetRemote,
+ MFEXML_GetStatus,
} MythFEXMLMethod;
class MythFEXML : public Eventing
@@ -36,6 +38,11 @@ class MythFEXML : public Eventing
QStringList m_actionList;
QHash<QString,QStringList> m_actionDescriptions;
+ QHash<QString,QString> m_latestStatus;
+ QWaitCondition m_statusWait;
+ QMutex *m_statusLock;
+ QTime m_lastUpdate;
+
protected:
// Implement UPnpServiceImpl methods that we can
@@ -45,6 +52,8 @@ class MythFEXML : public Eventing
virtual QString GetServiceControlURL() { return m_sControlUrl.mid( 1 ); }
virtual QString GetServiceDescURL () { return m_sControlUrl.mid( 1 ) + "/GetServDesc"; }
+ virtual void customEvent(QEvent *event);
+
private:
MythFEXMLMethod GetMethod( const QString &sURI );
@@ -52,6 +61,7 @@ class MythFEXML : public Eventing
void GetScreenShot ( HTTPRequest *pRequest );
void SendMessage ( HTTPRequest *pRequest );
void SendAction ( HTTPRequest *pRequest );
+ void GetStatus ( HTTPRequest *pRequest );
void GetActionList ( HTTPRequest *pRequest );
void GetActionListTest( HTTPRequest *pRequest );
void GetRemote ( HTTPRequest *pRequest );
Please sign in to comment.
Something went wrong with that request. Please try again.