Skip to content

Commit

Permalink
ServicesAPI: Add ability to Stop/Reactivate a recording.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoet committed Sep 23, 2016
1 parent d48c07c commit 38d9ba2
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 10 deletions.
8 changes: 7 additions & 1 deletion mythtv/libs/libmythservicecontracts/services/dvrServices.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
class SERVICE_PUBLIC DvrServices : public Service //, public QScriptable ???
{
Q_OBJECT
Q_CLASSINFO( "version" , "6.2" );
Q_CLASSINFO( "version" , "6.3" );
Q_CLASSINFO( "RemoveRecorded_Method", "POST" )
Q_CLASSINFO( "DeleteRecording_Method", "POST" )
Q_CLASSINFO( "UnDeleteRecording", "POST" )
Expand Down Expand Up @@ -107,6 +107,12 @@ class SERVICE_PUBLIC DvrServices : public Service //, public QScriptable ???
int ChanId,
const QDateTime &StartTime ) = 0;

virtual bool StopRecording ( int RecordedId ) = 0;

virtual bool ReactivateRecording ( int RecordedId ) = 0;

virtual bool RescheduleRecordings ( void ) = 0;

virtual bool UpdateRecordedWatchedStatus ( int RecordedId,
int ChanId,
const QDateTime &StartTime,
Expand Down
44 changes: 35 additions & 9 deletions mythtv/programs/mythbackend/mainserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
line = line.simplified();
QStringList tokens = line.split(' ', QString::SkipEmptyParts);
QString command = tokens[0];

if (command == "MYTH_PROTO_VERSION")
{
if (tokens.size() < 2)
Expand Down Expand Up @@ -1271,6 +1272,37 @@ void MainServer::customEvent(QEvent *e)
return;
}

if (me->Message().startsWith("STOP_RECORDING"))
{
QStringList tokens = me->Message().split(" ",
QString::SkipEmptyParts);


if (tokens.size() < 3 || tokens.size() > 3)
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("Bad STOP_RECORDING message: %1")
.arg(me->Message()));
return;
}

QDateTime startts = MythDate::fromString(tokens[2]);
RecordingInfo recInfo(tokens[1].toUInt(), startts);

if (recInfo.GetChanID())
{
DoHandleStopRecording(recInfo, NULL);
}
else
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("Cannot find program info for '%1' while "
"attempting to stop recording.").arg(me->Message()));
}

return;
}

if ((me->Message().startsWith("DELETE_RECORDING")) ||
(me->Message().startsWith("FORCE_DELETE_RECORDING")))
{
Expand Down Expand Up @@ -3103,17 +3135,12 @@ void MainServer::DoHandleUndeleteRecording(
void MainServer::HandleRescheduleRecordings(const QStringList &request,
PlaybackSock *pbs)
{
QStringList result;
if (m_sched)
{
m_sched->Reschedule(request);
result = QStringList( QString::number(1) );
}
else
result = QStringList( QString::number(0) );
ScheduledRecording::RescheduleMatch(0, 0, 0, QDateTime(),
"HandleRescheduleRecordings");

if (pbs)
{
QStringList result = QStringList( QString::number(1) );
MythSocket *pbssock = pbs->getSocket();
if (pbssock)
SendResponse(pbssock, result);
Expand Down Expand Up @@ -8117,4 +8144,3 @@ void MainServer::SendSlaveDisconnectedEvent(
}

/* vim: set expandtab tabstop=4 shiftwidth=4: */

56 changes: 56 additions & 0 deletions mythtv/programs/mythbackend/services/dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,62 @@ bool Dvr::UnDeleteRecording(int RecordedId,
//
/////////////////////////////////////////////////////////////////////////////

bool Dvr::StopRecording(int RecordedId)
{
if (RecordedId <= 0)
throw QString("Recorded ID is invalid.");

RecordingInfo ri = RecordingInfo(RecordedId);

if (ri.GetChanID())
{
QString cmd = QString("STOP_RECORDING %1 %2")
.arg(ri.GetChanID())
.arg(ri.GetRecordingStartTime(MythDate::ISODate));
MythEvent me(cmd);

gCoreContext->dispatch(me);
return true;
}
else
throw QString("RecordID %1 not found").arg(RecordedId);

return false;
}

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

bool Dvr::ReactivateRecording(int RecordedId)
{
if (RecordedId <= 0)
throw QString("Recorded ID is invalid.");

RecordingInfo ri = RecordingInfo(RecordedId);

ri.ReactivateRecording();

return true;
}

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

bool Dvr::RescheduleRecordings(void)
{
QString cmd = QString("RESCHEDULE_RECORDINGS");
MythEvent me(cmd);

gCoreContext->dispatch(me);
return true;
}

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

bool Dvr::UpdateRecordedWatchedStatus ( int RecordedId,
int chanid,
const QDateTime &recstarttsRaw,
Expand Down
6 changes: 6 additions & 0 deletions mythtv/programs/mythbackend/services/dvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class Dvr : public DvrServices
int ChanId,
const QDateTime &StartTime );

bool StopRecording ( int RecordedId );

bool ReactivateRecording ( int RecordedId );

bool RescheduleRecordings( void );

bool UpdateRecordedWatchedStatus ( int RecordedId,
int ChanId,
const QDateTime &StartTime,
Expand Down

0 comments on commit 38d9ba2

Please sign in to comment.