Skip to content

Commit 45130c1

Browse files
author
Mark Kendall
committed
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.
1 parent ec440d6 commit 45130c1

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

mythtv/libs/libmythtv/tv_play.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,27 @@ TVState TV::GetState(int player_idx) const
13261326
return ret;
13271327
}
13281328

1329+
void TV::GetStatus(void)
1330+
{
1331+
const PlayerContext *ctx = GetPlayerReadLock(-1, __FILE__, __LINE__);
1332+
1333+
osdInfo status;
1334+
status.text.insert("state", StateToString(GetState(ctx)));
1335+
ctx->LockPlayingInfo(__FILE__, __LINE__);
1336+
if (ctx->playingInfo)
1337+
{
1338+
status.text.insert("title", ctx->playingInfo->GetTitle());
1339+
status.text.insert("subtitle", ctx->playingInfo->GetSubtitle());
1340+
}
1341+
ctx->UnlockPlayingInfo(__FILE__, __LINE__);
1342+
ctx->CalcPlayerSliderPosition(status);
1343+
1344+
ReturnPlayerLock(ctx);
1345+
1346+
MythInfoMapEvent info("STATUS_UPDATE", status.text);
1347+
gCoreContext->dispatch(info);
1348+
}
1349+
13291350
/**
13301351
* \brief get tv state of active player context
13311352
*/
@@ -8278,6 +8299,10 @@ void TV::customEvent(QEvent *e)
82788299
}
82798300
ReturnPlayerLock(mctx);
82808301
}
8302+
else if (message == ACTION_GETSTATUS)
8303+
{
8304+
GetStatus();
8305+
}
82818306
else if (message.left(14) == "DONE_RECORDING")
82828307
{
82838308
// int seconds = 0;

mythtv/libs/libmythtv/tv_play.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class MTV_PUBLIC TV : public QObject
229229
int GetLastRecorderNum(int player_idx) const;
230230
TVState GetState(int player_idx) const;
231231
TVState GetState(const PlayerContext*) const;
232+
void GetStatus(void);
232233

233234
// Non-const queries
234235
OSD *GetOSDL(const char *, int);

mythtv/libs/libmythui/mythmainwindow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,13 @@ void MythMainWindow::customEvent(QEvent *ce)
23092309
}
23102310
ScreenShot(width, height, filename);
23112311
}
2312+
else if (message == ACTION_GETSTATUS)
2313+
{
2314+
QHash<QString,QString> status;
2315+
status.insert("state", "idle");
2316+
MythInfoMapEvent info("STATUS_UPDATE", status);
2317+
gCoreContext->dispatch(info);
2318+
}
23122319
}
23132320
else if ((MythEvent::Type)(ce->type()) == MythEvent::MythUserMessage)
23142321
{

mythtv/libs/libmythui/mythuiactions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
#define ACTION_TVPOWEROFF "TVPOWEROFF"
2525
#define ACTION_TVPOWERON "TVPOWERON"
2626

27+
#define ACTION_GETSTATUS "GETSTATUS"
2728
#endif // MYTHUI_ACTIONS_H

mythtv/programs/mythfrontend/mythfexml.cpp

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
/////////////////////////////////////////////////////////////////////////////
3232

3333
MythFEXML::MythFEXML( UPnpDevice *pDevice , const QString sSharePath)
34-
: Eventing( "MythFEXML", "MYTHTV_Event", sSharePath)
34+
: Eventing( "MythFEXML", "MYTHTV_Event", sSharePath),
35+
m_statusLock(new QMutex())
3536
{
3637

3738
QString sUPnpDescPath =
@@ -43,6 +44,9 @@ MythFEXML::MythFEXML( UPnpDevice *pDevice , const QString sSharePath)
4344
// Add our Service Definition to the device.
4445

4546
RegisterService( pDevice );
47+
48+
// listen for status updates
49+
gCoreContext->addListener(this);
4650
}
4751

4852
/////////////////////////////////////////////////////////////////////////////
@@ -51,6 +55,35 @@ MythFEXML::MythFEXML( UPnpDevice *pDevice , const QString sSharePath)
5155

5256
MythFEXML::~MythFEXML()
5357
{
58+
gCoreContext->removeListener(this);
59+
}
60+
61+
/////////////////////////////////////////////////////////////////////////////
62+
//
63+
/////////////////////////////////////////////////////////////////////////////
64+
65+
void MythFEXML::customEvent(QEvent *e)
66+
{
67+
if (e->type() != MythEvent::MythEventMessage)
68+
return;
69+
70+
MythEvent *me = (MythEvent *)e;
71+
if ("STATUS_UPDATE" == me->Message())
72+
{
73+
MythInfoMapEvent *info = (MythInfoMapEvent*)e;
74+
if (info && info->InfoMap())
75+
{
76+
QMutexLocker lock(m_statusLock);
77+
m_latestStatus.clear();
78+
QHashIterator<QString,QString> it(*info->InfoMap());
79+
while (it.hasNext())
80+
{
81+
it.next();
82+
m_latestStatus.insert(it.key(), it.value());
83+
}
84+
m_statusWait.wakeAll();
85+
}
86+
}
5487
}
5588

5689
/////////////////////////////////////////////////////////////////////////////
@@ -66,6 +99,7 @@ MythFEXMLMethod MythFEXML::GetMethod(const QString &sURI)
6699
if (sURI == "GetActionList") return MFEXML_ActionList;
67100
if (sURI == "GetActionTest") return MFEXML_ActionListTest;
68101
if (sURI == "GetRemote") return MFEXML_GetRemote;
102+
if (sURI == "GetStatus") return MFEXML_GetStatus;
69103

70104
return( MFEXML_Unknown );
71105
}
@@ -117,6 +151,9 @@ bool MythFEXML::ProcessRequest( HTTPRequest *pRequest )
117151
case MFEXML_GetRemote:
118152
GetRemote(pRequest);
119153
break;
154+
case MFEXML_GetStatus:
155+
GetStatus(pRequest);
156+
break;
120157
default:
121158
UPnp::FormatErrorResponse(pRequest, UPnPResult_InvalidAction);
122159
}
@@ -275,6 +312,40 @@ void MythFEXML::GetActionListTest(HTTPRequest *pRequest)
275312

276313
}
277314

315+
void MythFEXML::GetStatus(HTTPRequest *pRequest)
316+
{
317+
QMutexLocker lock(m_statusLock);
318+
319+
pRequest->m_eResponseType = ResponseTypeXML;
320+
pRequest->m_mapHeaders[ "Cache-Control" ] = "no-cache=\"Ext\", max-age = 1";
321+
322+
QTime now = QTime::currentTime();
323+
int since = m_lastUpdate.msecsTo(now);
324+
325+
if (m_latestStatus.isEmpty() || (since < 0) || (since > 500))
326+
{
327+
m_lastUpdate = now;
328+
MythEvent *req = new MythEvent(ACTION_GETSTATUS);
329+
qApp->postEvent(GetMythMainWindow(), req);
330+
if (!m_statusWait.wait(m_statusLock, 1000))
331+
{
332+
LOG(VB_GENERAL, LOG_ERR,
333+
"MythFEXML::GetStatus - failed to update status.");
334+
}
335+
}
336+
337+
QTextStream stream( &pRequest->m_response );
338+
stream << "<mythstatus version=\"1\">\n";
339+
QHashIterator<QString,QString> it(m_latestStatus);
340+
while (it.hasNext())
341+
{
342+
it.next();
343+
stream << " <";
344+
stream << it.key() << ">" << it.value() << "</" << it.key() << ">\n";
345+
}
346+
stream << "</mythstatus>\n";
347+
}
348+
278349
void MythFEXML::GetActionList(HTTPRequest *pRequest)
279350
{
280351
InitActions();

mythtv/programs/mythfrontend/mythfexml.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define MYTHFEXML_H_
1010

1111
#include <QDateTime>
12+
#include <QWaitCondition>
1213

1314
#include "upnp.h"
1415
#include "eventing.h"
@@ -24,6 +25,7 @@ typedef enum
2425
MFEXML_ActionList,
2526
MFEXML_ActionListTest,
2627
MFEXML_GetRemote,
28+
MFEXML_GetStatus,
2729
} MythFEXMLMethod;
2830

2931
class MythFEXML : public Eventing
@@ -36,6 +38,11 @@ class MythFEXML : public Eventing
3638
QStringList m_actionList;
3739
QHash<QString,QStringList> m_actionDescriptions;
3840

41+
QHash<QString,QString> m_latestStatus;
42+
QWaitCondition m_statusWait;
43+
QMutex *m_statusLock;
44+
QTime m_lastUpdate;
45+
3946
protected:
4047

4148
// Implement UPnpServiceImpl methods that we can
@@ -45,13 +52,16 @@ class MythFEXML : public Eventing
4552
virtual QString GetServiceControlURL() { return m_sControlUrl.mid( 1 ); }
4653
virtual QString GetServiceDescURL () { return m_sControlUrl.mid( 1 ) + "/GetServDesc"; }
4754

55+
virtual void customEvent(QEvent *event);
56+
4857
private:
4958

5059
MythFEXMLMethod GetMethod( const QString &sURI );
5160

5261
void GetScreenShot ( HTTPRequest *pRequest );
5362
void SendMessage ( HTTPRequest *pRequest );
5463
void SendAction ( HTTPRequest *pRequest );
64+
void GetStatus ( HTTPRequest *pRequest );
5565
void GetActionList ( HTTPRequest *pRequest );
5666
void GetActionListTest( HTTPRequest *pRequest );
5767
void GetRemote ( HTTPRequest *pRequest );

0 commit comments

Comments
 (0)