Skip to content

Commit

Permalink
Rework the QUERY_RECORDINGS sort.
Browse files Browse the repository at this point in the history
Modify QUERY_RECORDINGS to allow retrieving sorted or unsorted lists.
The argument may be one of Recording (for in-progress recordings only,
unsorted), or Unsorted, Ascending, or Descending (where the latter 3
request all recordings and specify sort order, based on starttime).
This allows code that needs to sort the recording list itself, like the
PlaybackBox code, to request and unsorted list, while still allowing
bindings and MythXML users to get sorted lists.

Change includes a binary version change, so plugin rebuild is required.
Also includes a protocol version change, so all clients--frontends,
backends, MythWeb--need updating.
  • Loading branch information
sphery committed Mar 8, 2011
1 parent e949f5f commit e965e4b
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 28 deletions.
4 changes: 2 additions & 2 deletions mythtv/bindings/perl/MythTV.pm
Expand Up @@ -106,8 +106,8 @@ package MythTV;
# Note: as of July 21, 2010, this is actually a string, to account for proto
# versions of the form "58a". This will get used if protocol versions are
# changed on a fixes branch ongoing.
our $PROTO_VERSION = "64";
our $PROTO_TOKEN = "8675309J";
our $PROTO_VERSION = "65";
our $PROTO_TOKEN = "D2BB94C2";

# currentDatabaseVersion is defined in libmythtv in
# mythtv/libs/libmythtv/dbcheck.cpp and should be the current MythTV core
Expand Down
4 changes: 2 additions & 2 deletions mythtv/bindings/php/MythBackend.php
Expand Up @@ -11,8 +11,8 @@ class MythBackend {

// MYTH_PROTO_VERSION is defined in libmyth in mythtv/libs/libmyth/mythcontext.h
// and should be the current MythTV protocol version.
static $protocol_version = '64';
static $protocol_token = '8675309J';
static $protocol_version = '65';
static $protocol_token = 'D2BB94C2';

// The character string used by the backend to separate records
static $backend_separator = '[]:[]';
Expand Down
2 changes: 1 addition & 1 deletion mythtv/bindings/python/MythTV/methodheap.py
Expand Up @@ -189,7 +189,7 @@ def getRecordings(self):
"""
Returns a list of all Program objects which have already recorded
"""
return self._getSortedPrograms('QUERY_RECORDINGS Play')
return self._getSortedPrograms('QUERY_RECORDINGS Ascending')

def getExpiring(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions mythtv/bindings/python/MythTV/static.py
Expand Up @@ -8,8 +8,8 @@
SCHEMA_VERSION = 1269
NVSCHEMA_VERSION = 1007
MUSICSCHEMA_VERSION = 1018
PROTO_VERSION = '64'
PROTO_TOKEN = '8675309J'
PROTO_VERSION = '65'
PROTO_TOKEN = 'D2BB94C2'
BACKEND_SEP = '[]:[]'
INSTALL_PREFIX = '/usr/local'

Expand Down
2 changes: 1 addition & 1 deletion mythtv/contrib/maintenance/flush_deleted_recgroup.pl
Expand Up @@ -70,7 +70,7 @@
my $myth = new MythTV();

# Load all of the recordings
my %rows = $myth->backend_rows('QUERY_RECORDINGS Delete');
my %rows = $myth->backend_rows('QUERY_RECORDINGS Descending');

# Parse each recording, and delete anything in the "Deleted" recgroup
my $i = 0;
Expand Down
4 changes: 2 additions & 2 deletions mythtv/contrib/user_jobs/mythlink.pl
Expand Up @@ -318,7 +318,7 @@

}
else {
%rows = $Myth->backend_rows('QUERY_RECORDINGS DELETE');
%rows = $Myth->backend_rows('QUERY_RECORDINGS Descending');
}
foreach my $row (@{$rows{'rows'}}) {
my $show = new MythTV::Recording(@$row);
Expand Down Expand Up @@ -390,7 +390,7 @@
sub do_rename {
$q = 'UPDATE recorded SET basename=? WHERE chanid=? AND starttime=FROM_UNIXTIME(?)';
$sh = $dbh->prepare($q);
my %rows = $Myth->backend_rows('QUERY_RECORDINGS Delete');
my %rows = $Myth->backend_rows('QUERY_RECORDINGS Descending');
foreach my $row (@{$rows{'rows'}}) {
my $show = new MythTV::Recording(@$row);
# File doesn't exist locally
Expand Down
22 changes: 19 additions & 3 deletions mythtv/libs/libmyth/programinfo.cpp
Expand Up @@ -4277,13 +4277,28 @@ bool LoadFromOldRecorded(
return true;
}

/** \fn ProgramInfo::LoadFromRecorded(void)
* \brief Load a ProgramList from the recorded table.
* \param destination ProgramList to fill
* \param possiblyInProgressRecordingsOnly return only in-progress
* recordings or empty list
* \param inUseMap in-use programs map
* \param isJobRunning job map
* \param recMap recording map
* \param sort sort order, negative for descending, 0 for
* unsorted, positive for ascending
* \return true if it succeeds, false if it fails.
* \sa QueryInUseMap(void)
* QueryJobsRunning(int)
* Scheduler::GetRecording()
*/
bool LoadFromRecorded(
ProgramList &destination,
bool possiblyInProgressRecordingsOnly,
const QMap<QString,uint32_t> &inUseMap,
const QMap<QString,bool> &isJobRunning,
const QMap<QString, ProgramInfo*> &recMap,
bool sortDescending)
int sort)
{
destination.clear();

Expand All @@ -4297,8 +4312,9 @@ bool LoadFromRecorded(
if (possiblyInProgressRecordingsOnly)
thequery += "WHERE r.endtime >= NOW() AND r.starttime <= NOW() ";

thequery += "ORDER BY r.starttime ";
if (sortDescending)
if (sort)
thequery += "ORDER BY r.starttime ";
if (sort < 0)
thequery += "DESC ";

MSqlQuery query(MSqlQuery::InitCon());
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/programinfo.h
Expand Up @@ -699,7 +699,7 @@ MPUBLIC bool LoadFromRecorded(
const QMap<QString,uint32_t> &inUseMap,
const QMap<QString,bool> &isJobRunning,
const QMap<QString, ProgramInfo*> &recMap,
bool sortDescending = false);
int sort = 0);

template<typename TYPE>
bool LoadFromScheduler(
Expand Down
10 changes: 6 additions & 4 deletions mythtv/libs/libmyth/remoteutil.cpp
Expand Up @@ -12,13 +12,15 @@
#include "storagegroup.h"
#include "mythevent.h"

vector<ProgramInfo *> *RemoteGetRecordedList(bool deltype)
vector<ProgramInfo *> *RemoteGetRecordedList(int sort)
{
QString str = "QUERY_RECORDINGS ";
if (deltype)
str += "Delete";
if (sort < 0)
str += "Descending";
else if (sort > 0)
str += "Ascending";
else
str += "Play";
str += "Unsorted";

QStringList strlist(str);

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/remoteutil.h
Expand Up @@ -30,7 +30,7 @@ class MPUBLIC FileSystemInfo
int weight;
};

MPUBLIC vector<ProgramInfo *> *RemoteGetRecordedList(bool deltype);
MPUBLIC vector<ProgramInfo *> *RemoteGetRecordedList(int sort);
MPUBLIC vector<FileSystemInfo> RemoteGetFreeSpace(void);
MPUBLIC bool RemoteGetLoad(float load[3]);
MPUBLIC bool RemoteGetUptime(time_t &uptime);
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
#define MYTH_BINARY_VERSION "0.25.20110305-1"
#define MYTH_BINARY_VERSION "0.25.20110307-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand All @@ -35,8 +35,8 @@
* mythtv/bindings/python/MythTV/static.py (version number)
* mythtv/bindings/python/MythTV/mythproto.py (layout)
*/
#define MYTH_PROTO_VERSION "64"
#define MYTH_PROTO_TOKEN "8675309J"
#define MYTH_PROTO_VERSION "65"
#define MYTH_PROTO_TOKEN "D2BB94C2"

MBASE_PUBLIC const char *GetMythSourceVersion();

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -10582,7 +10582,7 @@ void TV::FillOSDMenuJumpRec(PlayerContext* ctx, const QString category,

QMutexLocker locker(&progListsLock);
progLists.clear();
vector<ProgramInfo*> *infoList = RemoteGetRecordedList(false);
vector<ProgramInfo*> *infoList = RemoteGetRecordedList(0);
bool LiveTVInAllPrograms = gCoreContext->GetNumSetting("LiveTVInAllPrograms",0);
if (infoList)
{
Expand Down
13 changes: 11 additions & 2 deletions mythtv/programs/mythbackend/mainserver.cpp
Expand Up @@ -1540,7 +1540,8 @@ void MainServer::SendResponse(MythSocket *socket, QStringList &commands)
/**
* \addtogroup myth_network_protocol
* \par QUERY_RECORDINGS \e type
* The \e type parameter can be either "Play", "Recording" or "Delete".
* The \e type parameter can be either "Recording", "Unsorted", "Ascending",
* or "Descending".
* Returns programinfo (title, subtitle, description, category, chanid,
* channum, callsign, channel.name, fileURL, \e et \e cetera)
*/
Expand All @@ -1557,10 +1558,18 @@ void MainServer::HandleQueryRecordings(QString type, PlaybackSock *pbs)
QMap<QString,bool> isJobRunning =
ProgramInfo::QueryJobsRunning(JOB_COMMFLAG);

int sort = 0;
// Allow "Play" and "Delete" for backwards compatibility with protocol
// version 56 and below.
if ((type == "Ascending") || (type == "Play"))
sort = 1;
else if ((type == "Descending") || (type == "Delete"))
sort = -1;

ProgramList destination;
LoadFromRecorded(
destination, (type == "Recording"),
inUseMap, isJobRunning, recMap, (type == "Delete"));
inUseMap, isJobRunning, recMap, sort);

QMap<QString,ProgramInfo*>::iterator mit = recMap.begin();
for (; mit != recMap.end(); mit = recMap.erase(mit))
Expand Down
5 changes: 4 additions & 1 deletion mythtv/programs/mythbackend/mythxml.cpp
Expand Up @@ -1012,6 +1012,9 @@ void MythXML::GetAlbumArt( HTTPRequest *pRequest )
void MythXML::GetRecorded( HTTPRequest *pRequest )
{
bool bDescending = pRequest->m_mapParams[ "Descending" ].toInt();
int sort = 1;
if (bDescending)
sort = -1;

QMap<QString,ProgramInfo*> recMap;
if (sched)
Expand All @@ -1022,7 +1025,7 @@ void MythXML::GetRecorded( HTTPRequest *pRequest )

ProgramList progList;
LoadFromRecorded( progList, false,
inUseMap, isJobRunning, recMap, bDescending );
inUseMap, isJobRunning, recMap, sort );

QMap<QString,ProgramInfo*>::iterator mit = recMap.begin();
for (; mit != recMap.end(); mit = recMap.erase(mit))
Expand Down
4 changes: 2 additions & 2 deletions mythtv/programs/mythfrontend/programinfocache.cpp
Expand Up @@ -73,9 +73,9 @@ void ProgramInfoCache::Load(const bool updateUI)

locker.unlock();
/**/
// the param to RemoteGetRecordedList doesn't actually matter
// Get an unsorted list (sort = 0) from RemoteGetRecordedList
// we sort the list later anyway.
vector<ProgramInfo*> *tmp = RemoteGetRecordedList(false);
vector<ProgramInfo*> *tmp = RemoteGetRecordedList(0);
/**/
locker.relock();

Expand Down

0 comments on commit e965e4b

Please sign in to comment.