Skip to content
Permalink
Browse files

Update the ProgramInfoUpdater to use recordedid

Uses recordeid instead of chanid/starttime.

The change affects the following events:
RECORDING_LIST_CHANGE (ADD|DELETE) - but not UPDATE
UPDATE_FILE_SIZE
UPDATE_MASTER_PROG_INFO - renamed to UPDATE_MASTER_REC_INFO

Bumps protocol version from 83 to 84
  • Loading branch information...
stuartm committed Jan 29, 2015
1 parent c7638ce commit b220116f77e782dd3cfb317a2152fbb9099699f1
@@ -108,7 +108,7 @@ package MythTV;
# versions of the form "58a". This will get used if protocol versions are
# changed on a fixes branch ongoing.
our $PROTO_VERSION = "83";
our $PROTO_TOKEN = "BreakingGlass";
our $PROTO_TOKEN = "CanaryCoalmine";

# currentDatabaseVersion is defined in libmythtv in
# mythtv/libs/libmythtv/dbcheck.cpp and should be the current MythTV core
@@ -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 = '83';
static $protocol_token = 'BreakingGlass';
static $protocol_version = '84';
static $protocol_token = 'CanaryCoalmine';
// The character string used by the backend to separate records
static $backend_separator = '[]:[]';
@@ -136,7 +136,7 @@ var MythRecordings = new function() {
{
wsClient = new parent.WebSocketEventClient();
wsClient.eventReceiver = function(event) { HandleMythEvent(event) };
wsClient.filters = ["MASTER_UPDATE_PROG_INFO", "RECORDING_LIST_CHANGE",
wsClient.filters = ["MASTER_UPDATE_REC_INFO", "RECORDING_LIST_CHANGE",
"UPDATE_FILE_SIZE"];
parent.globalWSHandler.AddListener(wsClient);
};
@@ -165,17 +165,19 @@ var MythRecordings = new function() {
return;
// TODO: Add some information to the event so we can decide whether
// the current page needs reloading.
if (tokens[0] == "MASTER_UPDATE_PROG_INFO")
if (tokens[0] == "MASTER_UPDATE_REC_INFO")
{
if (tokens.length < 3)
if (tokens.length < 2)
return;
var chanId = tokens[1];
var startTime = tokens[2];
var recordedId = tokens[1];
}
else if (tokens[0] == "RECORDING_LIST_CHANGE")
{
if (tokens.length < 4)
if (tokens.length < 3)
return;
var type = tokens[1];
var recordedId = tokens[2];

}
};
};
@@ -2599,6 +2599,8 @@ void ProgramInfo::SaveBookmark(uint64_t frame)
SaveMarkupMap(bookmarkmap);
}

set_flag(programflags, FL_BOOKMARK, is_valid);

if (IsRecording())
{
MSqlQuery query(MSqlQuery::InitCon());
@@ -2615,26 +2617,24 @@ void ProgramInfo::SaveBookmark(uint64_t frame)

if (!query.exec())
MythDB::DBError("bookmark flag update", query);
}

set_flag(programflags, FL_BOOKMARK, is_valid);

SendUpdateEvent();
SendUpdateEvent();
}
}

void ProgramInfo::SendUpdateEvent(void)
{
updater->insert(chanid, recstartts, kPIUpdate);
updater->insert(recordedid, kPIUpdate);
}

void ProgramInfo::SendAddedEvent(void) const
{
updater->insert(chanid, recstartts, kPIAdd);
updater->insert(recordedid, kPIAdd);
}

void ProgramInfo::SendDeletedEvent(void) const
{
updater->insert(chanid, recstartts, kPIDelete);
updater->insert(recordedid, kPIDelete);
}

/** \brief Queries Latest bookmark timestamp from the database.
@@ -2813,6 +2813,8 @@ void ProgramInfo::SaveWatched(bool watched)
MythDB::DBError("Set watched flag", query);
else
UpdateLastDelete(watched);

SendUpdateEvent();
}
else if (IsVideoFile())
{
@@ -2839,7 +2841,6 @@ void ProgramInfo::SaveWatched(bool watched)
}

set_flag(programflags, FL_WATCHED, watched);
SendUpdateEvent();
}

/** \brief Queries "recorded" table for its "editing" field
@@ -5790,7 +5791,7 @@ void ProgramInfo::SaveFilesize(uint64_t fsize)
if (!query.exec())
MythDB::DBError("File size update", query);

updater->insert(chanid, recstartts, kPIUpdateFileSize, fsize);
updater->insert(recordedid, kPIUpdateFileSize, fsize);
}

uint64_t ProgramInfo::GetFilesize(void) const
@@ -8,31 +8,24 @@

using std::vector;

uint qHash(const PIKey &k)
{
return qHash(k.chanid) ^ qHash(k.recstartts.toTime_t());
}

void ProgramInfoUpdater::insert(
uint chanid, const QDateTime &recstartts,
PIAction action, uint64_t filesize)
uint recordedid, PIAction action, uint64_t filesize)
{
QMutexLocker locker(&lock);
if (kPIUpdate == action || kPIUpdateFileSize == action)
{
PIKey key = PIKey(chanid, recstartts);
QHash<PIKey,PIKeyData>::iterator it = needsUpdate.find(key);
QHash<uint,PIKeyData>::iterator it = needsUpdate.find(recordedid);
// If there is no action in the set we can insert
// If it is the same type of action we can overwrite,
// If it the new action is a full update we can overwrite
if (it == needsUpdate.end())
needsUpdate.insert(key, PIKeyData(action, filesize));
needsUpdate.insert(recordedid, PIKeyData(action, filesize));
else if (((*it).action == action) || (kPIUpdate == action))
(*it) = PIKeyData(action, filesize);
}
else
{
needsAddDelete.push_back(PIKeyAction(chanid, recstartts, action));
needsAddDelete.push_back(PIKeyAction(recordedid, action));
}

// Start a new run() if one isn't already running..
@@ -68,9 +61,8 @@ void ProgramInfoUpdater::run(void)
continue;

QString type = (kPIAdd == (*ita).action) ? "ADD" : "DELETE";
QString msg = QString("RECORDING_LIST_CHANGE %1 %2 %3")
.arg(type).arg((*ita).chanid)
.arg((*ita).recstartts.toString(Qt::ISODate));
QString msg = QString("RECORDING_LIST_CHANGE %1 %2")
.arg(type).arg((*ita).recordedid);

workDone = true;
gCoreContext->SendMessage(msg);
@@ -79,23 +71,21 @@ void ProgramInfoUpdater::run(void)

// Send updates in any old order, we just need
// one per updated ProgramInfo.
QHash<PIKey,PIKeyData>::iterator itu = needsUpdate.begin();
QHash<uint,PIKeyData>::iterator itu = needsUpdate.begin();
for (; itu != needsUpdate.end(); ++itu)
{
QString msg;

if (kPIUpdateFileSize == (*itu).action)
{
msg = QString("UPDATE_FILE_SIZE %1 %2 %3")
.arg(itu.key().chanid)
.arg(itu.key().recstartts.toString(Qt::ISODate))
msg = QString("UPDATE_FILE_SIZE %1 %2")
.arg(itu.key())
.arg((*itu).filesize);
}
else
{
msg = QString("MASTER_UPDATE_PROG_INFO %1 %2")
.arg(itu.key().chanid)
.arg(itu.key().recstartts.toString(Qt::ISODate));
msg = QString("MASTER_UPDATE_REC_INFO %1")
.arg(itu.key());
}

workDone = true;
@@ -24,30 +24,20 @@ typedef enum PIAction {
kPIUpdateFileSize,
} PIAction;

class MPUBLIC PIKey
class MPUBLIC PIKeyAction
{
public:
PIKey(uint c, const QDateTime &r) : chanid(c), recstartts(r) {}
PIKeyAction(uint recordedid, PIAction a) :
recordedid(recordedid), action(a) { }

uint chanid;
QDateTime recstartts;
uint recordedid;
PIAction action;

bool operator==(const PIKey &other) const
bool operator==(const PIKeyAction &other) const
{
return (chanid == other.chanid &&
recstartts == other.recstartts);
return (recordedid == other.recordedid);
}
};
uint qHash(const PIKey &k);

class MPUBLIC PIKeyAction : public PIKey
{
public:
PIKeyAction(uint c, const QDateTime &r, PIAction a) :
PIKey(c, r), action(a) { }

PIAction action;
};

class MPUBLIC PIKeyData
{
@@ -62,7 +52,7 @@ class MPUBLIC ProgramInfoUpdater : public QRunnable
public:
ProgramInfoUpdater() : isRunning(false) { setAutoDelete(false); }

void insert(uint chanid, const QDateTime &recstartts,
void insert(uint recordedid,
PIAction action, uint64_t filesize = 0ULL);
void run(void);

@@ -71,7 +61,7 @@ class MPUBLIC ProgramInfoUpdater : public QRunnable
QWaitCondition moreWork;
bool isRunning;
std::vector<PIKeyAction> needsAddDelete;
QHash<PIKey,PIKeyData> needsUpdate;
QHash<uint,PIKeyData> needsUpdate;
};

#endif // _PROGRAM_INFO_UPDATER_H_
@@ -39,8 +39,8 @@
* http://www.mythtv.org/wiki/Category:Myth_Protocol_Commands
* http://www.mythtv.org/wiki/Category:Myth_Protocol
*/
#define MYTH_PROTO_VERSION "83"
#define MYTH_PROTO_TOKEN "BreakingGlass"
#define MYTH_PROTO_VERSION "84"
#define MYTH_PROTO_TOKEN "CanaryCoalmine"

/** \brief Increment this whenever the MythTV core database schema changes.
*
@@ -1618,7 +1618,7 @@ void RecordingInfo::SaveFilesize(uint64_t fsize)
GetRecordingFile()->m_fileSize = fsize;
GetRecordingFile()->Save(); // Ideally this would be called just the once when all metadata is gathered

updater->insert(chanid, recstartts, kPIUpdateFileSize, fsize);
updater->insert(recordedid, kPIUpdateFileSize, fsize);

ProgramInfo::SaveFilesize(fsize); // Temporary
}
@@ -1628,7 +1628,7 @@ void RecordingInfo::SetFilesize(uint64_t fsize)
if (!GetRecordingFile())
LoadRecordingFile();
GetRecordingFile()->m_fileSize = fsize;
updater->insert(chanid, recstartts, kPIUpdateFileSize, fsize);
updater->insert(recordedid, kPIUpdateFileSize, fsize);
//ProgramInfo::SetFilesize(fsize);
}

@@ -1380,18 +1380,14 @@ void MainServer::customEvent(QEvent *e)
return;

MythEvent mod_me("");
if (me->Message().startsWith("MASTER_UPDATE_PROG_INFO"))
if (me->Message().startsWith("MASTER_UPDATE_REC_INFO"))
{
QStringList tokens = me->Message().simplified().split(" ");
uint chanid = 0;
QDateTime recstartts;
if (tokens.size() >= 3)
{
chanid = tokens[1].toUInt();
recstartts = MythDate::fromString(tokens[2]);
}
uint recordedid = 0;
if (tokens.size() >= 2)
recordedid = tokens[1].toUInt();

ProgramInfo evinfo(chanid, recstartts);
ProgramInfo evinfo(recordedid);
if (evinfo.GetChanID())
{
QDateTime rectime = MythDate::current().addSecs(
@@ -2462,8 +2458,8 @@ void MainServer::DoDeleteInDB(DeleteStruct *ds)
sleep(1);

// Notify the frontend so it can requery for Free Space
QString msg = QString("RECORDING_LIST_CHANGE DELETE %1 %2")
.arg(ds->m_chanid).arg(ds->m_recstartts.toString(Qt::ISODate));
QString msg = QString("RECORDING_LIST_CHANGE DELETE %1")
.arg(ds->m_recordedid);
gCoreContext->SendEvent(MythEvent(msg));

// sleep a little to let frontends reload the recordings list

0 comments on commit b220116

Please sign in to comment.
You can’t perform that action at this time.