--- ./programs/mythcommflag/main.cpp.hibernate 2006-08-17 09:53:41.000000000 -0400 +++ ./programs/mythcommflag/main.cpp 2006-09-25 22:19:00.000000000 -0400 @@ -52,6 +52,13 @@ int jobID = -1; int lastCmd = -1; +JobMonitor *currentJobMonitor; + +static void rebuild_status_callback(int, void *) +{ + if (currentJobMonitor) + currentJobMonitor->hibernate(); +} int BuildVideoMarkup(QString& filename) { @@ -82,7 +89,7 @@ program_info); nvp->SetRingBuffer(tmprbuf); - nvp->RebuildSeekTable(!quiet); + nvp->RebuildSeekTable(!quiet, rebuild_status_callback); cerr << "Rebuilt\n"; @@ -255,7 +262,9 @@ if (jobID != -1) { - int curCmd = JobQueue::GetJobCmd(jobID); + int curCmd = currentJobMonitor ? currentJobMonitor->GetJobCmd() + : JobQueue::GetJobCmd(jobID); + if (curCmd == lastCmd) return; @@ -397,6 +406,10 @@ program_info->SetCommFlagged(COMM_FLAG_PROCESSING); + JobMonitor monitor(jobID); + + currentJobMonitor= jobID == -1 ? NULL: &monitor; + CustomEventRelayer cer(incomingCustomEvent); SlotRelayer a(commDetectorBreathe); SlotRelayer b(commDetectorStatusUpdate); @@ -447,7 +460,7 @@ } delete commDetector; - + currentJobMonitor=NULL; return comms_found; } @@ -537,7 +550,7 @@ if (rebuildSeekTable) { - nvp->RebuildSeekTable(); + nvp->RebuildSeekTable(false, rebuild_status_callback); if (!quiet) cerr << "Rebuilt\n"; --- ./programs/mythtranscode/transcode.cpp.hibernate 2006-08-23 18:20:59.000000000 -0400 +++ ./programs/mythtranscode/transcode.cpp 2006-09-25 22:19:00.000000000 -0400 @@ -609,6 +609,8 @@ QTime flagTime; flagTime.start(); + JobMonitor monitor(jobID); + while (nvp->TranscodeGetNextFrame(dm_iter, &did_ff, &is_key, honorCutList)) { if (first_loop) @@ -885,7 +887,7 @@ if ((jobID >= 0) || (print_verbose_messages & VB_IMPORTANT)) { - if (JobQueue::GetJobCmd(jobID) == JOB_STOP) + if (monitor.GetJobCmd() == JOB_STOP) { unlink(outputname); delete newFrame; --- ./programs/mythtranscode/mpeg2fix.cpp.hibernate 2006-07-18 20:24:00.000000000 -0400 +++ ./programs/mythtranscode/mpeg2fix.cpp 2006-09-25 22:24:29.000000000 -0400 @@ -14,6 +14,7 @@ #include #include #include +#include "jobqueue.h" #ifndef O_LARGEFILE #define O_LARGEFILE 0 @@ -199,8 +200,11 @@ MPEG2fixup::MPEG2fixup(const char *inf, const char *outf, QMap *deleteMap, const char *fmt, int norp, int fixPTS, int maxf, - bool showprog, int otype) + bool showprog, int otype, int jobIDarg) + : rx(jobID) { + jobID=jobIDarg; + displayFrame = new QPtrListIterator (vFrame); infile = inf; @@ -429,13 +433,14 @@ return (rx->WaitBuffers()); } -MPEG2replex::MPEG2replex() +MPEG2replex::MPEG2replex(int jobIDarg) { memset(&vrbuf, 0, sizeof(ringbuffer)); memset(&index_vrbuf, 0, sizeof(ringbuffer)); memset(&extrbuf, 0, sizeof(ringbuffer) * N_AUDIO); memset(&index_extrbuf, 0, sizeof(ringbuffer) * N_AUDIO); ext_count = 0; + jobID=jobIDarg; } MPEG2replex::~MPEG2replex() @@ -1797,8 +1802,12 @@ InitReplex(); + JobMonitor monitor(jobID); + while (1) { + monitor.hibernate(); + /* read packet */ if (! file_end) { @@ -2432,6 +2441,8 @@ AVPacket pkt; int count = 0; + JobMonitor monitor(jobID); + /*============ initialise AV ===============*/ if (!InitAV(file.ascii(), NULL, 0)) return TRANSCODE_EXIT_UNKNOWN_ERROR; @@ -2440,6 +2451,8 @@ while (av_read_frame(inputFC, &pkt) >= 0) { + monitor.hibernate(); + if (pkt.stream_index == vid_id) { if (pkt.flags & PKT_FLAG_KEY) --- ./programs/mythtranscode/mpeg2fix.h.hibernate 2006-02-18 13:44:52.000000000 -0500 +++ ./programs/mythtranscode/mpeg2fix.h 2006-09-25 22:20:52.000000000 -0400 @@ -102,7 +102,7 @@ class MPEG2replex { public: - MPEG2replex(); + MPEG2replex(int jobID); ~MPEG2replex(); void Start(); int WaitBuffers(); @@ -124,6 +124,7 @@ private: multiplex_t *mplex; + int jobID; }; class MPEG2fixup @@ -131,7 +132,8 @@ public: MPEG2fixup(const char *inf, const char *outf, QMap *deleteMap, const char *fmt, int norp, - int fixPTS, int maxf, bool showprog, int otype); + int fixPTS, int maxf, bool showprog, int otype, + int jobID); ~MPEG2fixup(); int Start(); void AddRangeList(QStringList cutlist, int type); @@ -224,6 +226,8 @@ QMap delMap; QMap saveMap; + int jobID; + pthread_t thread; AVFormatContext *inputFC; --- ./programs/mythtranscode/main.cpp.hibernate 2006-07-15 15:39:26.000000000 -0400 +++ ./programs/mythtranscode/main.cpp 2006-09-25 22:22:04.000000000 -0400 @@ -468,7 +468,7 @@ MPEG2fixup *m2f = new MPEG2fixup(infile.ascii(), outfile.ascii(), &deleteMap, NULL, false, false, 20, - showprogress, otype); + showprogress, otype, jobID); if (build_index) { int err = BuildKeyframeIndex(m2f, infile, posMap, jobID); --- ./programs/mythfilldatabase/filldata.cpp.hibernate 2006-09-25 22:16:01.000000000 -0400 +++ ./programs/mythfilldatabase/filldata.cpp 2006-09-25 22:55:42.000000000 -0400 @@ -43,6 +43,7 @@ #include "cardutil.h" #include "sourceutil.h" #include "remoteutil.h" +#include "jobqueue.h" using namespace std; @@ -81,6 +82,8 @@ QString graboptions = ""; QString cardtype = QString::null; +JobMonitor *myMonitor; + class ChanInfo { public: @@ -241,6 +244,8 @@ int secs; QDateTime newFrom, newTo; + myMonitor->hibernate(); + MSqlQuery query(MSqlQuery::InitCon()); query.prepare("SELECT tmoffset FROM channel where chanid = :CHANID ;"); @@ -258,6 +263,8 @@ newFrom = from.addSecs(secs); newTo = to.addSecs(secs); + myMonitor->hibernate(); + query.prepare("DELETE FROM program " "WHERE starttime >= :FROM AND starttime < :TO " "AND chanid = :CHANID ;"); @@ -266,6 +273,8 @@ query.bindValue(":CHANID", chanid); query.exec(); + myMonitor->hibernate(); + query.prepare("DELETE FROM programrating " "WHERE starttime >= :FROM AND starttime < :TO " "AND chanid = :CHANID ;"); @@ -274,6 +283,8 @@ query.bindValue(":CHANID", chanid); query.exec(); + myMonitor->hibernate(); + query.prepare("DELETE FROM credits " "WHERE starttime >= :FROM AND starttime < :TO " "AND chanid = :CHANID ;"); @@ -282,6 +293,8 @@ query.bindValue(":CHANID", chanid); query.exec(); + myMonitor->hibernate(); + query.prepare("DELETE FROM programgenres " "WHERE starttime >= :FROM AND starttime < :TO " "AND chanid = :CHANID ;"); @@ -298,6 +311,8 @@ "sourceid = :SOURCE ;"); query.bindValue(":SOURCE", sourceid); + myMonitor->hibernate(); + if (!query.exec()) MythContext::DBError("Selecting channels per source", query); @@ -366,6 +381,8 @@ QString fileprefix = SetupIconCacheDirectory(); + myMonitor->hibernate(); + MSqlQuery query(MSqlQuery::InitCon()); query.prepare("SELECT ch.chanid, nim.url " "FROM (channel ch, callsignnetworkmap csm) " @@ -382,6 +399,8 @@ { while (query.next()) { + myMonitor->hibernate(); + QString icon_url = expandURLString(query.value(1).toString()); QFileInfo qfi(icon_url); QFile localfile(fileprefix + "/" + qfi.fileName()); @@ -566,6 +585,7 @@ QDomNode node = element.firstChild(); while (!node.isNull()) { + myMonitor->hibernate(); try { QDomElement e = nodeToElement(node); @@ -576,6 +596,7 @@ nm_query.bindValue(":NETWORK", net.stripWhiteSpace()); nm_query.bindValue(":URL", u.stripWhiteSpace()); + if (!nm_query.exec()) MythContext::DBError( "Inserting network->url mapping", nm_query); @@ -599,6 +620,8 @@ st += getNamedElementText(e, IM_BASE_STUB_TAG); QString u = getNamedElementText(e, IM_NET_URL_TAG); + myMonitor->hibernate(); + MSqlQuery qc(MSqlQuery::InitCon()); qc.prepare("SELECT COUNT(*) FROM settings " "WHERE value = :STUBNAME"); @@ -616,6 +639,8 @@ qr->bindValue(":STUBNAME", st); qr->bindValue(":URL", u); + myMonitor->hibernate(); + if (!qr->exec()) MythContext::DBError( "Inserting callsign->network mapping", *qr); @@ -667,6 +692,8 @@ QDomDocument iconmap; QDomElement roote = iconmap.createElement(IM_DOC_TAG); + myMonitor->hibernate(); + MSqlQuery query(MSqlQuery::InitCon()); query.exec("SELECT * FROM callsignnetworkmap ORDER BY callsign;"); @@ -674,6 +701,8 @@ { while (query.next()) { + myMonitor->hibernate(); + QDomElement cs2nettag = iconmap.createElement(IM_CS_TO_NET_TAG); QDomElement cstag = iconmap.createElement(IM_CS_TAG); QDomElement nettag = iconmap.createElement(IM_NET_TAG); @@ -692,11 +721,14 @@ } } + myMonitor->hibernate(); query.exec("SELECT * FROM networkiconmap ORDER BY network;"); if (query.isActive() && query.size() > 0) { while (query.next()) { + myMonitor->hibernate(); + QDomElement net2urltag = iconmap.createElement( IM_NET_TO_URL_TAG); QDomElement nettag = iconmap.createElement(IM_NET_TAG); @@ -716,6 +748,8 @@ } } + myMonitor->hibernate(); + query.prepare("SELECT value,data FROM settings WHERE value " "LIKE :URLMAP"); query.bindValue(":URLMAP", QString(BASEURLMAP_START) + "%"); @@ -725,6 +759,8 @@ QRegExp baseax("\\.([^\\.]+)$"); while (query.next()) { + myMonitor->hibernate(); + QString base_stub = query.value(0).toString(); if (baseax.search(base_stub) != -1) { @@ -760,6 +796,8 @@ void RunSimpleQuery(const QString &query) { + myMonitor->hibernate(); + MSqlQuery q(MSqlQuery::InitCon()); if (!q.exec(query)) MythContext::DBError("RunSimpleQuery ", q); @@ -770,6 +808,7 @@ MSqlQuery query(MSqlQuery::InitCon()); query.prepare("DELETE FROM settings WHERE value LIKE :URLMAPLIKE"); query.bindValue(":URLMAPLIKE", QString(BASEURLMAP_START) + '%'); + myMonitor->hibernate(); if (!query.exec()) MythContext::DBError("ResetIconMap", query); @@ -799,6 +838,8 @@ freq = get_center_frequency("atsc", "vsb8", "us", freqid); + myMonitor->hibernate(); + // Check if this is connected to an HDTV card. MSqlQuery query(MSqlQuery::DDCon()); query.prepare( @@ -899,6 +940,8 @@ { MSqlQuery query(MSqlQuery::DDCon()); + myMonitor->hibernate(); + //cerr << "Adding rows to main program table from view table..\n"; if (!query.exec("INSERT IGNORE INTO program (chanid, starttime, endtime, " "title, subtitle, description, " @@ -922,6 +965,8 @@ "WHERE dd_v_program.chanid = channel.chanid;")) MythContext::DBError("Inserting into program table", query); + myMonitor->hibernate(); + //cerr << "Finished adding rows to main program table...\n"; //cerr << "Adding program ratings...\n"; @@ -934,6 +979,8 @@ "channel.chanid")) MythContext::DBError("Inserting into programrating table", query); + myMonitor->hibernate(); + if (!query.exec("INSERT IGNORE INTO programrating (chanid, starttime, " "system, rating) SELECT dd_v_program.chanid, " "DATE_ADD(starttime, INTERVAL channel.tmoffset MINUTE), " @@ -945,6 +992,8 @@ //cerr << "Finished adding program ratings...\n"; //cerr << "Populating people table from production crew list...\n"; + myMonitor->hibernate(); + if (!query.exec("INSERT IGNORE INTO people (name) SELECT fullname " "FROM dd_productioncrew;")) MythContext::DBError("Inserting into people table", query); @@ -952,6 +1001,8 @@ //cerr << "Finished adding people...\n"; //cerr << "Adding credits entries from production crew list...\n"; + myMonitor->hibernate(); + if (!query.exec("INSERT IGNORE INTO credits (chanid, starttime, person, " "role) SELECT dd_v_program.chanid, " "DATE_ADD(starttime, INTERVAL channel.tmoffset MINUTE), " @@ -966,6 +1017,8 @@ //cerr << "Finished inserting credits...\n"; //cerr << "Adding genres...\n"; + myMonitor->hibernate(); + if (!query.exec("INSERT IGNORE INTO programgenres (chanid, starttime, " "relevance, genre) SELECT dd_v_program.chanid, " "DATE_ADD(starttime, INTERVAL channel.tmoffset MINUTE), " @@ -995,6 +1048,8 @@ MSqlQuery query(MSqlQuery::DDCon()); QString status = "currently running."; + myMonitor->hibernate(); + query.exec(QString("UPDATE settings SET data ='%1' " "WHERE value='mythfilldatabaseLastRunStart'") .arg(qdtNow.toString("yyyy-MM-dd hh:mm"))); @@ -1046,6 +1101,7 @@ .arg(ddprocessor.GetDDProgramsStartAt().toString()) .arg(ddprocessor.GetDDProgramsEndAt().toString())); + myMonitor->hibernate(); qdtNow = QDateTime::currentDateTime(); query.exec(QString("UPDATE settings SET data ='%1' " "WHERE value='mythfilldatabaseLastRunEnd'") @@ -1064,6 +1120,8 @@ DataDirectProcessor::UpdateProgramViewTable(source.id); //cerr << "Finished creating program view table...\n"; + myMonitor->hibernate(); + query.exec("SELECT count(*) from dd_v_program;"); if (query.isActive() && query.size() > 0) { @@ -1676,6 +1734,8 @@ } else if (e.tagName() == "programme") { + myMonitor->hibernate(); + ProgInfo *pginfo = parseProgram(e, localTimezoneOffset); if (pginfo->startts == pginfo->endts) @@ -1761,6 +1821,8 @@ QValueList::iterator cur; while (1) { + myMonitor->hibernate(); + cur = i; i++; // fill in miss stop times @@ -1947,6 +2009,8 @@ if ((*i).old_xmltvid != "") { + myMonitor->hibernate(); + querystr.sprintf("SELECT xmltvid FROM channel WHERE xmltvid = '%s'", (*i).old_xmltvid.ascii()); query.exec(querystr); @@ -1966,6 +2030,8 @@ } } + myMonitor->hibernate(); + querystr.sprintf("SELECT chanid,name,callsign,channum,finetune," "icon,freqid,tvformat FROM channel WHERE " "xmltvid = '%s' AND sourceid = %d;", @@ -1974,6 +2040,8 @@ query.exec(querystr); if (query.isActive() && query.size() > 0) { + myMonitor->hibernate(); + query.next(); QString chanid = query.value(0).toString(); @@ -2041,6 +2109,8 @@ subquery.bindValue(":XMLTVID", (*i).xmltvid); subquery.bindValue(":SOURCEID", id); + myMonitor->hibernate(); + if (!subquery.exec()) { cerr << "DB Error: Channel update failed, SQL query " @@ -2071,6 +2141,8 @@ subquery.bindValue(":ICON", localfile); subquery.bindValue(":CHANID", chanid); + myMonitor->hibernate(); + if (!subquery.exec()) MythContext::DBError("Channel icon change", subquery); } @@ -2217,6 +2289,8 @@ for (mapiter = proglist->begin(); mapiter != proglist->end(); ++mapiter) { + myMonitor->hibernate(); + MSqlQuery query(MSqlQuery::InitCon()), chanQuery(MSqlQuery::InitCon()); if (mapiter.key() == "") @@ -2256,6 +2330,8 @@ QValueList::iterator i = sortlist->begin(); for (; i != sortlist->end(); i++) { + myMonitor->hibernate(); + query.prepare("SELECT * FROM program WHERE " "chanid=:CHANID AND starttime=:START AND " "endtime=:END AND title=:TITLE AND " @@ -2306,6 +2382,8 @@ continue; } + myMonitor->hibernate(); + query.prepare("SELECT title,starttime,endtime FROM program " "WHERE chanid=:CHANID AND starttime>=:START AND " "starttime<:END;"); @@ -2334,6 +2412,8 @@ << (*i).end.toString() << endl << endl; } + myMonitor->hibernate(); + MSqlQuery subquery(MSqlQuery::InitCon()); subquery.prepare("DELETE FROM program WHERE " "chanid=:CHANID AND starttime>=:START " @@ -2401,6 +2481,9 @@ query.bindValue(":COLORCODE", (*i).colorcode); query.bindValue(":SYNDICATEDEPISODENUMBER", (*i).syndicatedepisodenumber); query.bindValue(":PROGRAMID", (*i).programid); + + myMonitor->hibernate(); + if (!query.exec()) MythContext::DBError("program insert", query); @@ -2417,6 +2500,8 @@ query.bindValue(":SYS", (*j).system.utf8()); query.bindValue(":RATING", (*j).rating.utf8()); + myMonitor->hibernate(); + if (!query.exec()) MythContext::DBError("programrating insert", query); } @@ -2424,6 +2509,8 @@ QValueList::iterator k = (*i).credits.begin(); for (; k != (*i).credits.end(); k++) { + myMonitor->hibernate(); + query.prepare("SELECT person FROM people WHERE " "name = :NAME;"); query.bindValue(":NAME", (*k).name.utf8()); @@ -2439,6 +2526,7 @@ if (personid < 0) { + myMonitor->hibernate(); query.prepare("INSERT INTO people (name) VALUES " "(:NAME);"); query.bindValue(":NAME", (*k).name.utf8()); @@ -2464,6 +2552,8 @@ continue; } + myMonitor->hibernate(); + query.prepare("INSERT INTO credits (chanid,starttime," "role,person) VALUES " "(:CHANID, :START, :ROLE, :PERSON);"); @@ -2680,6 +2770,8 @@ MSqlQuery query(MSqlQuery::InitCon()); QString status = "currently running."; + myMonitor->hibernate(); + query.exec(QString("UPDATE settings SET data ='%1' " "WHERE value='mythfilldatabaseLastRunStart'") .arg(qdtNow.toString("yyyy-MM-dd hh:mm"))); @@ -2755,6 +2847,8 @@ VERBOSE(VB_GENERAL, "Keeping 7 days of data."); } + myMonitor->hibernate(); + query.prepare("DELETE FROM oldprogram WHERE airdate < " "DATE_SUB(CURRENT_DATE, INTERVAL 320 DAY);"); query.exec(); @@ -2763,44 +2857,57 @@ "SELECT title,starttime FROM program " "WHERE starttime < NOW() AND manualid = 0 " "GROUP BY title;"); + myMonitor->hibernate(); + query.exec(); query.prepare("DELETE FROM program WHERE starttime <= " "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);"); query.bindValue(":OFFSET", offset); + myMonitor->hibernate(); + query.exec(); query.prepare("DELETE FROM programrating WHERE starttime <= " "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);"); query.bindValue(":OFFSET", offset); + myMonitor->hibernate(); + query.exec(); query.prepare("DELETE FROM programgenres WHERE starttime <= " "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);"); query.bindValue(":OFFSET", offset); + myMonitor->hibernate(); + query.exec(); query.prepare("DELETE FROM credits WHERE starttime <= " "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);"); query.bindValue(":OFFSET", offset); + myMonitor->hibernate(); + query.exec(); query.prepare("DELETE p FROM recordedprogram p " "LEFT JOIN recorded r ON " " p.chanid = r.chanid AND p.starttime = r.progstart " "WHERE r.chanid IS NULL;"); + myMonitor->hibernate(); query.exec(); query.prepare("DELETE p FROM recordedrating p " "LEFT JOIN recorded r ON " " p.chanid = r.chanid AND p.starttime = r.progstart " "WHERE r.chanid IS NULL;"); + myMonitor->hibernate(); query.exec(); query.prepare("DELETE p FROM recordedcredits p " "LEFT JOIN recorded r ON " " p.chanid = r.chanid AND p.starttime = r.progstart " "WHERE r.chanid IS NULL;"); + myMonitor->hibernate(); query.exec(); query.prepare("DELETE FROM record WHERE (type = :SINGLE " @@ -2809,8 +2916,11 @@ query.bindValue(":SINGLE", kSingleRecord); query.bindValue(":OVERRIDE", kOverrideRecord); query.bindValue(":DONTRECORD", kDontRecord); + myMonitor->hibernate(); query.exec(); + myMonitor->hibernate(); + MSqlQuery findq(MSqlQuery::InitCon()); findq.prepare("SELECT record.recordid FROM record " "LEFT JOIN oldfind ON oldfind.recordid = record.recordid " @@ -2822,16 +2932,23 @@ { while (findq.next()) { + myMonitor->hibernate(); + query.prepare("DELETE FROM record WHERE recordid = :RECORDID;"); query.bindValue(":RECORDID", findq.value(0).toInt()); query.exec(); } } + + myMonitor->hibernate(); + query.prepare("DELETE FROM oldfind WHERE findid < TO_DAYS(NOW()) - 14;"); query.exec(); int cleanOldRecorded = gContext->GetNumSetting( "CleanOldRecorded", 10); + myMonitor->hibernate(); + query.prepare("DELETE FROM oldrecorded WHERE " "recstatus <> :RECORDED AND duplicate = 0 AND " "endtime < DATE_SUB(CURRENT_DATE, INTERVAL :CLEAN DAY);"); @@ -2856,6 +2973,8 @@ int externally_handled = 0; int total_sources = sourcelist.size(); + myMonitor->hibernate(); + query.exec(QString("SELECT MAX(endtime) FROM program WHERE manualid=0;")); if (query.isActive() && query.size() > 0) { @@ -2951,6 +3070,8 @@ for (int i = 0; i < grabdays; i++) { + myMonitor->hibernate(); + // We need to check and see if the current date has changed // since we started in this loop. If it has, we need to adjust // the value of 'i' to compensate for this. @@ -3011,6 +3132,8 @@ "WHERE c.sourceid = %3 " "GROUP BY c.chanid;"; + myMonitor->hibernate(); + if (query.exec(querystr.arg(i-1).arg(i).arg((*it).id)) && query.isActive()) { @@ -3030,6 +3153,8 @@ .arg(query.value(1).toInt())); } + myMonitor->hibernate(); + if (query.exec(querystr.arg(i).arg(i+1).arg((*it).id)) && query.isActive()) { @@ -3132,6 +3257,8 @@ } else if (xmltv_grabber == "eitonly") { + myMonitor->hibernate(); + VERBOSE(VB_IMPORTANT, "Source configured to use only the " "broadcasted guide data. Skipping."); externally_handled++; @@ -3144,6 +3271,8 @@ xmltv_grabber == "none" || xmltv_grabber == "") { + myMonitor->hibernate(); + VERBOSE(VB_IMPORTANT, "Source configured with no grabber. Nothing to do."); externally_handled++; @@ -3168,6 +3297,8 @@ if (only_update_channels && !need_post_grab_proc) return true; + myMonitor->hibernate(); + query.exec(QString("SELECT MAX(endtime) FROM program WHERE manualid=0;")); if (query.isActive() && query.size() > 0) { @@ -3180,6 +3311,8 @@ if (failures == 0) { + myMonitor->hibernate(); + if ((GuideDataAfter == GuideDataBefore) && (total_sources != externally_handled)) status = "mythfilldatabase ran, but did not insert " @@ -3285,6 +3418,8 @@ QString chanid, starttime, endtime, querystr; MSqlQuery query1(MSqlQuery::InitCon()), query2(MSqlQuery::InitCon()); + myMonitor->hibernate(); + querystr = "SELECT chanid, starttime, endtime FROM program " "WHERE (DATE_FORMAT(endtime,'%H%i') = '0000') " "ORDER BY chanid, starttime;"; @@ -3302,6 +3437,8 @@ chanid = query1.value(0).toString(); endtime = query1.value(2).toString(); + myMonitor->hibernate(); + querystr = QString("SELECT chanid, starttime, endtime FROM program " "WHERE (DATE_FORMAT(starttime, '%%Y-%%m-%%d') = " "'%1') AND chanid = '%2' " @@ -3327,6 +3464,8 @@ .arg(endtime) .arg(chanid) .arg(starttime); + myMonitor->hibernate(); + if (!query2.exec(querystr)) { @@ -3811,7 +3950,11 @@ gContext->LogEntry("mythfilldatabase", LP_INFO, "Listings Download Started", ""); - + JobMonitor jobMonitor(-1); + + myMonitor= &jobMonitor; + myMonitor->hibernate(); + if (!grab_data) { } @@ -3821,6 +3964,8 @@ } else if (from_file) { + myMonitor->hibernate(); + QString status = "currently running."; QDateTime GuideDataBefore, GuideDataAfter; @@ -3829,10 +3974,14 @@ "WHERE value='mythfilldatabaseLastRunStart'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"))); + myMonitor->hibernate(); + query.exec(QString("UPDATE settings SET data ='%1' " "WHERE value='mythfilldatabaseLastRunStatus'") .arg(status)); + myMonitor->hibernate(); + query.exec(QString("SELECT MAX(endtime) FROM program;")); if (query.isActive() && query.size() > 0) { @@ -3846,12 +3995,18 @@ if (!grabDataFromFile(fromfile_id, fromfile_name)) return FILLDB_EXIT_GRAB_DATA_FAILED; + myMonitor->hibernate(); + clearOldDBEntries(); + myMonitor->hibernate(); + query.exec(QString("UPDATE settings SET data ='%1' " "WHERE value='mythfilldatabaseLastRunEnd'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"))); + myMonitor->hibernate(); + query.exec(QString("SELECT MAX(endtime) FROM program;")); if (query.isActive() && query.size() > 0) { @@ -3869,6 +4024,8 @@ else status = "Successful."; + myMonitor->hibernate(); + query.exec(QString("UPDATE settings SET data ='%1' " "WHERE value='mythfilldatabaseLastRunStatus'") .arg(status)); @@ -3894,6 +4051,8 @@ where = QString("WHERE sourceid = %1").arg(sourceid); } + myMonitor->hibernate(); + QString querystr = QString("SELECT sourceid,name,xmltvgrabber,userid," "password,lineupid " "FROM videosource ") + where + @@ -3955,24 +4114,34 @@ return FILLDB_EXIT_OK; } + myMonitor->hibernate(); + if (reset_iconmap) { ResetIconMap(reset_iconmap_icons); } + myMonitor->hibernate(); + if (import_iconmap) { ImportIconMap(import_icon_map_filename); } + myMonitor->hibernate(); + if (export_iconmap) { ExportIconMap(export_icon_map_filename); } + myMonitor->hibernate(); + if (update_icon_map) { MSqlQuery query(MSqlQuery::InitCon()); + myMonitor->hibernate(); + query.exec("SELECT sourceid FROM videosource ORDER BY sourceid;"); if (query.isActive() && query.size() > 0) { @@ -3983,6 +4152,8 @@ } } + myMonitor->hibernate(); + if (grab_data) { VERBOSE(VB_GENERAL, "Adjusting program database end times."); @@ -3997,6 +4168,8 @@ "Listings Download Finished", ""); } + myMonitor->hibernate(); + if (grab_data) { VERBOSE(VB_GENERAL, "Marking generic episodes."); @@ -4011,6 +4184,8 @@ QString(" Found %1").arg(query.numRowsAffected())); } + myMonitor->hibernate(); + if (mark_repeats) { VERBOSE(VB_GENERAL, "Marking repeats."); @@ -4042,11 +4217,15 @@ if (grab_data) { + myMonitor->hibernate(); + MSqlQuery updt(MSqlQuery::InitCon()); updt.exec("UPDATE program SET first = 0, last = 0;"); VERBOSE(VB_GENERAL, "Marking episode first showings."); + myMonitor->hibernate(); + MSqlQuery query(MSqlQuery::InitCon()); query.exec("SELECT MIN(starttime),programid FROM program " "WHERE programid > '' GROUP BY programid;"); @@ -4055,6 +4234,8 @@ { while(query.next()) { + myMonitor->hibernate(); + updt.prepare("UPDATE program set first = 1 " "WHERE starttime = :STARTTIME " " AND programid = :PROGRAMID;"); @@ -4065,6 +4246,8 @@ } int found = query.numRowsAffected(); + myMonitor->hibernate(); + query.exec("SELECT MIN(starttime),title,subtitle,description " "FROM program WHERE programid = '' " "GROUP BY title,subtitle,description;"); @@ -4082,7 +4265,9 @@ updt.bindValue(":TITLE", query.value(1).toString()); updt.bindValue(":SUBTITLE", query.value(2).toString()); updt.bindValue(":DESCRIPTION", query.value(3).toString()); - updt.exec(); + myMonitor->hibernate(); + + updt.exec(); } } found += query.numRowsAffected(); @@ -4090,6 +4275,8 @@ VERBOSE(VB_GENERAL, "Marking episode last showings."); + myMonitor->hibernate(); + query.exec("SELECT MAX(starttime),programid FROM program " "WHERE programid > '' GROUP BY programid;"); @@ -4102,11 +4289,14 @@ " AND programid = :PROGRAMID;"); updt.bindValue(":STARTTIME", query.value(0).toDateTime()); updt.bindValue(":PROGRAMID", query.value(1).toString()); + myMonitor->hibernate(); updt.exec(); } } found = query.numRowsAffected(); + myMonitor->hibernate(); + query.exec("SELECT MAX(starttime),title,subtitle,description " "FROM program WHERE programid = '' " "GROUP BY title,subtitle,description;"); @@ -4124,6 +4314,8 @@ updt.bindValue(":TITLE", query.value(1).toString()); updt.bindValue(":SUBTITLE", query.value(2).toString()); updt.bindValue(":DESCRIPTION", query.value(3).toString()); + + myMonitor->hibernate(); updt.exec(); } } @@ -4131,6 +4323,8 @@ VERBOSE(VB_GENERAL, QString(" Found %1").arg(found)); } + myMonitor->hibernate(); + if (1) // limit MSqlQuery's lifetime { MSqlQuery query(MSqlQuery::InitCon()); --- ./libs/libmythtv/jobqueue.cpp.hibernate 2006-07-30 15:53:33.000000000 -0400 +++ ./libs/libmythtv/jobqueue.cpp 2006-09-25 22:19:00.000000000 -0400 @@ -26,6 +26,10 @@ #define LOC QString("JobQueue: ") #define LOC_ERR QString("JobQueue Error: ") +#include +#include +#include + JobQueue::JobQueue(bool master) { isMaster = master; @@ -2168,4 +2172,122 @@ return JOB_NONE; } +long JobMonitor::bogomips=0; + +/* +** Add up all bogomips in /proc/cpuinfo +*/ + +long JobMonitor::getEstimatedBogoMips() +{ + if (bogomips) + return bogomips; + + FILE *fp=fopen("/proc/cpuinfo", "r"); + char linebuf[256]; + + while (fp && fgets(linebuf, sizeof(linebuf), fp)) + { + char *p=strtok(linebuf, " \t:"); + + if (!p) + continue; + + if (strcmp(p, "bogomips") == 0) + { + p=strtok(NULL, " \t:"); + + if (p) + bogomips += atol(p); + } + } + if (fp) fclose(fp); + + return bogomips; +} + + + +JobMonitor::JobMonitor(int jobIDArg) + : jobID(jobIDArg), jobLastChk(time(NULL)), counter(1), + doMonitor(gContext->GetNumSetting("JobHibernate", -1)) +{ + if (doMonitor < 0) + doMonitor= getEstimatedBogoMips() < 3000; +} + +JobMonitor::~JobMonitor() +{ +} + +int JobMonitor::GetJobCmd() +{ + int jobCmd; + + while ((jobCmd=JobQueue::GetJobCmd(jobID)) == JOB_RUN) + { + if (!doHibernateCheck()) + break; + } + + return jobCmd; +} + +void JobMonitor::hibernate() +{ + while (doHibernateCheck()) + ; +} + +bool JobMonitor::doHibernateCheck() +{ + if (!doMonitor) + return false; + + time_t t=time(NULL); + + if (t == jobLastChk) + return false; + + if (t < jobLastChk) + counter=0; // Time went backwards? + else if (t - jobLastChk > counter) + counter=0; + else + counter -= t - jobLastChk; + + jobLastChk=t; + + if (counter) + return false; + + counter=5; + + bool isActive=false; + + MSqlQuery query(MSqlQuery::InitCon()); + query.prepare("SELECT recusage FROM inuseprograms"); + if (query.exec() && query.isActive() && query.size() > 0) + while (query.next()) + { + QString usage= + query.value(0).toString().lower(); + + if (usage == "player" || + usage == "recorder" || + usage.left(7) == "preview") + isActive=true; + } + + if (!isActive) + return false; + counter=1; + if (jobID >= 0 && + !JobQueue::ChangeJobComment(jobID, + "waiting for record/playback to stop")) + return false; + sleep(5); + return true; +} + /* vim: set expandtab tabstop=4 shiftwidth=4: */ --- ./libs/libmythtv/datadirect.cpp.hibernate 2006-08-08 14:14:52.000000000 -0400 +++ ./libs/libmythtv/datadirect.cpp 2006-09-25 22:47:21.000000000 -0400 @@ -44,7 +44,8 @@ static void update_channel_basic(uint sourceid, bool insert, QString xmltvid, QString callsign, QString name, uint freqid, - QString chan_major, QString chan_minor); + QString chan_major, QString chan_minor, + JobMonitor &monitor); DataDirectStation::DataDirectStation(void) : stationid(""), callsign(""), @@ -224,6 +225,7 @@ query.bindValue(":AFFILIATE", curr_station.affiliate); query.bindValue(":FCCCHANNUM", curr_station.fccchannelnumber); + parent.monitor.hibernate(); if (!query.exec()) MythContext::DBError("Inserting into dd_station", query); } @@ -245,6 +247,7 @@ query.bindValue(":DEVICE", curr_lineup.device); query.bindValue(":POSTAL", curr_lineup.postal); + parent.monitor.hibernate(); if (!query.exec()) MythContext::DBError("Inserting into dd_lineup", query); } @@ -262,11 +265,13 @@ query.bindValue(":STATIONID", curr_lineupmap.stationid); query.bindValue(":CHANNEL", curr_lineupmap.channel); query.bindValue(":CHANNELMINOR",curr_lineupmap.channelMinor); + parent.monitor.hibernate(); if (!query.exec()) MythContext::DBError("Inserting into dd_lineupmap", query); } else if (pqname == "schedule") { + parent.monitor.hibernate(); QDateTime endtime = curr_schedule.time.addSecs( QTime().secsTo(curr_schedule.duration)); @@ -354,6 +359,7 @@ query.bindValue(":SYNDNUM", curr_program.syndicatedEpisodeNumber); query.bindValue(":ORIGAIRDATE", curr_program.originalAirDate); + parent.monitor.hibernate(); if (!query.exec()) MythContext::DBError("Inserting into dd_program", query); } @@ -377,6 +383,7 @@ query.bindValue(":SURNAME", curr_productioncrew.surname.utf8()); query.bindValue(":FULLNAME", fullname.utf8()); + parent.monitor.hibernate(); if (!query.exec()) MythContext::DBError("Inserting into dd_productioncrew", query); @@ -394,6 +401,7 @@ query.bindValue(":CLASS", curr_genre.gclass.utf8()); query.bindValue(":RELEVANCE", curr_genre.relevance); + parent.monitor.hibernate(); if (!query.exec()) MythContext::DBError("Inserting into dd_genre", query); } @@ -450,6 +458,7 @@ query.prepare(querystr); + parent.monitor.hibernate(); if (!query.exec()) { MythContext::DBError("Updating DataDirect Status Message", @@ -535,7 +544,8 @@ userid(user), password(pass), inputfilename(""), tmpPostFile(""), tmpResultFile(""), cookieFile(""), - cookieFileDT() + cookieFileDT(), + monitor(-1) { DataDirectURLs urls0( "Tribune Media Zap2It", @@ -560,7 +570,8 @@ void DataDirectProcessor::UpdateStationViewTable(QString lineupid) { MSqlQuery query(MSqlQuery::DDCon()); - + + monitor.hibernate(); if (!query.exec("TRUNCATE TABLE dd_v_station;")) MythContext::DBError("Truncating temporary table dd_v_station", query); @@ -578,6 +589,7 @@ query.bindValue(":LINEUP", lineupid); + monitor.hibernate(); if (!query.exec()) MythContext::DBError("Populating temporary table dd_v_station", query); } @@ -586,6 +598,7 @@ { MSqlQuery query(MSqlQuery::DDCon()); + monitor.hibernate(); if (!query.exec("TRUNCATE TABLE dd_v_program;")) MythContext::DBError("Truncating temporary table dd_v_program", query); @@ -617,9 +630,13 @@ if (!query.exec()) MythContext::DBError("Populating temporary table dd_v_program", query); + monitor.hibernate(); + if (!query.exec("ANALYZE TABLE dd_v_program;")) MythContext::DBError("Analyzing table dd_v_program", query); + monitor.hibernate(); + if (!query.exec("ANALYZE TABLE dd_productioncrew;")) MythContext::DBError("Analyzing table dd_productioncrew", query); } @@ -643,6 +660,7 @@ "WHERE channel.chanid IS NULL"); query.bindValue(":SOURCEID", sourceid); + monitor.hibernate(); if (!query.exec()) { MythContext::DBError("Selecting new channels", query); @@ -660,7 +678,7 @@ update_channel_basic(sourceid, insert_channels, xmltvid, callsign, name, freqid, - chan_major, chan_minor); + chan_major, chan_minor, monitor); if (!insert_channels) { @@ -675,6 +693,7 @@ bool DataDirectProcessor::UpdateChannelsUnsafe(uint sourceid) { + monitor.hibernate(); MSqlQuery dd_station_info(MSqlQuery::DDCon()); dd_station_info.prepare( "SELECT callsign, stationname, stationid," @@ -713,6 +732,7 @@ chan_update_q.bindValue(":MAJORCHAN", chan_major.toUInt()); chan_update_q.bindValue(":MINORCHAN", chan_minor.toUInt()); + monitor.hibernate(); if (!chan_update_q.exec()) { MythContext::DBError("Updating channel table", @@ -903,14 +923,17 @@ QString querystr = QString("UPDATE settings SET data = '%1' WHERE value = '%2';"); + monitor.hibernate(); query.prepare(querystr.arg(minhr).arg("MythFillMinHour")); if (!query.exec()) MythContext::DBError("Updating DataDirect MythFillMinHour", query); + monitor.hibernate(); query.prepare(querystr.arg(maxhr).arg("MythFillMaxHour")); if (!query.exec()) MythContext::DBError("Updating DataDirect MythFillMaxHour", query); + monitor.hibernate(); query.prepare(querystr.arg(NextSuggestedTime.toString(Qt::ISODate)) .arg("MythFillSuggestedRunTime")); @@ -978,6 +1001,8 @@ void DataDirectProcessor::CreateATempTable(const QString &ptablename, const QString &ptablestruct) { + monitor.hibernate(); + MSqlQuery query(MSqlQuery::DDCon()); QString querystr; querystr = "CREATE TEMPORARY TABLE IF NOT EXISTS " + ptablename + " " + @@ -988,6 +1013,7 @@ querystr = "TRUNCATE TABLE " + ptablename + ";"; + monitor.hibernate(); if (!query.exec(querystr)) MythContext::DBError("Truncating temporary table", query); } @@ -1404,6 +1430,7 @@ "WHERE sourceid = :SOURCEID"); query.bindValue(":SOURCEID", sourceid); + monitor.hibernate(); if (!query.exec() || !query.isActive()) { MythContext::DBError("Selecting existing channels", query); @@ -1798,7 +1825,8 @@ static void update_channel_basic(uint sourceid, bool insert, QString xmltvid, QString callsign, QString name, uint freqid, - QString chan_major, QString chan_minor) + QString chan_major, QString chan_minor, + JobMonitor &monitor) { callsign = (callsign.isEmpty()) ? name : callsign; @@ -1807,6 +1835,7 @@ sourceid, chan_major, chan_minor, tvformat, freqid); // First check if channel already in DB, but without xmltvid + monitor.hibernate(); MSqlQuery query(MSqlQuery::DDCon()); query.prepare("SELECT chanid FROM channel " "WHERE sourceid = :SOURCEID AND xmltvid = 0 AND " @@ -1835,6 +1864,7 @@ "SET xmltvid = :XMLTVID " "WHERE chanid = :CHANID AND sourceid = :SOURCEID"); + monitor.hibernate(); while (query.next()) { uint chanid = query.value(0).toInt(); @@ -1860,12 +1890,15 @@ get_atsc_stuff(channum, sourceid, freqid, majorC, minorC, freq); + monitor.hibernate(); if (minorC > 0 && freq >= 0) mplexid = ChannelUtil::CreateMultiplex(sourceid, "atsc", freq, "8vsb"); + monitor.hibernate(); if ((mplexid > 0) || (minorC == 0)) chanid = ChannelUtil::CreateChanID(sourceid, channum); + monitor.hibernate(); if (chanid > 0) { QString icon = ""; --- ./libs/libmythtv/jobqueue.h.hibernate 2006-07-15 16:13:46.000000000 -0400 +++ ./libs/libmythtv/jobqueue.h 2006-09-25 22:19:00.000000000 -0400 @@ -219,6 +219,30 @@ QMutex queueThreadCondLock; }; +#include + +class JobMonitor { + int jobID; + time_t jobLastChk; + int counter; + + int doMonitor; + + static long bogomips; + + public: + JobMonitor(int jobID); + ~JobMonitor(); + + int GetJobCmd(); + void hibernate(); + + static long getEstimatedBogoMips(); + + private: + bool doHibernateCheck(); +}; + #endif /* vim: set expandtab tabstop=4 shiftwidth=4: */ --- libs/libmythtv/datadirect.h.hibernate 2006-07-15 14:26:08.000000000 -0400 +++ libs/libmythtv/datadirect.h 2006-09-29 22:01:04.000000000 -0400 @@ -7,6 +7,9 @@ #include #include + +#include "jobqueue.h" + using namespace std; enum DD_PROVIDERS @@ -308,12 +311,12 @@ void SetInputFile(const QString &file) { inputfilename = file; } // static commands (these update temp DB tables) - static void UpdateStationViewTable(QString lineupid); - static void UpdateProgramViewTable(uint sourceid); + void UpdateStationViewTable(QString lineupid); + void UpdateProgramViewTable(uint sourceid); // static commands (these update regular DB tables from temp DB tables) - static int UpdateChannelsSafe(uint sourceid, bool insert_channels); - static bool UpdateChannelsUnsafe(uint sourceid); + int UpdateChannelsSafe(uint sourceid, bool insert_channels); + bool UpdateChannelsUnsafe(uint sourceid); private: void CreateTempTables(void); @@ -358,6 +361,9 @@ QString tmpResultFile; QString cookieFile; QDateTime cookieFileDT; + + public: + JobMonitor monitor; }; #endif