[mythtv] [patch] datadirect.cpp exit cleanup

Daniel Thor Kristjansson danielk at mrl.nyu.edu
Wed Dec 29 20:08:25 UTC 2004


This removes exit()'s in datadirect.cpp, and changes grabLineupsOnly(), 
grabData() and grabAllData() so that they return true on successful 
completion, and false on unsuccessful completion. It also adds checks 
for error conditions, where appropriate.

-- Daniel
-------------- next part --------------
Index: libs/libmythtv/datadirect.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/datadirect.h,v
retrieving revision 1.2
diff -u -r1.2 datadirect.h
--- libs/libmythtv/datadirect.h	24 Dec 2004 23:24:07 -0000	1.2
+++ libs/libmythtv/datadirect.h	29 Dec 2004 20:04:00 -0000
@@ -254,9 +254,9 @@
     void updateStationViewTable();
     void updateProgramViewTable(int sourceid);
 
-    void grabLineupsOnly();
-    void grabData(bool plineupsonly, QDateTime pstartdate, QDateTime penddate);
-    void grabAllData(void);
+    bool grabLineupsOnly();
+    bool grabData(bool plineupsonly, QDateTime pstartdate, QDateTime penddate);
+    bool grabAllData(void);
 
     void parseLineups();
     void parseStations();
Index: libs/libmythtv/datadirect.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/datadirect.cpp,v
retrieving revision 1.11
diff -u -r1.11 datadirect.cpp
--- libs/libmythtv/datadirect.cpp	24 Dec 2004 23:24:07 -0000	1.11
+++ libs/libmythtv/datadirect.cpp	29 Dec 2004 20:04:00 -0000
@@ -433,7 +433,7 @@
         MythContext::DBError("Analyzing table dd_productioncrew", query);
 }
 
-void DataDirectProcessor::grabData(bool plineupsOnly, QDateTime pstartDate, 
+bool DataDirectProcessor::grabData(bool plineupsOnly, QDateTime pstartDate, 
                                    QDateTime pendDate) 
 {
     QString ddurl = "http://datadirect.webservices.zap2it.com/tvlistings/xtvdService";
@@ -452,9 +452,9 @@
     char ctempfilename[] = "/tmp/mythpostXXXXXX";
     if (mkstemp(ctempfilename) == -1) 
     {
-         perror("mkstemp");
-         VERBOSE(VB_IMPORTANT, "DDP: error creating temp files");
-         exit(-12);
+        VERBOSE(VB_IMPORTANT, QString("DDP: error creating temp files -- %1").
+                arg(strerror(errno)));
+        return false;
     }
 
     QString tmpfilename = QString(ctempfilename);
@@ -494,9 +494,9 @@
     FILE* fp = popen(command.ascii(), "r");
     if (fp == NULL) 
     {
-        VERBOSE(VB_GENERAL, "Failed to get data");
-        perror(command.ascii());
-        return;
+        VERBOSE(VB_IMPORTANT, QString("DDP: Failed to get data (%1) -- %2").
+                arg(command.ascii()).arg(strerror(errno)));
+        return false;
     }
 
     QFile f;
@@ -504,7 +504,7 @@
     if (!f.open(IO_ReadOnly, fp)) 
     {
        VERBOSE(VB_GENERAL,"Error opening DataDirect file");
-       return;
+       return false;
     }
     
     DDStructureParser ddhandler(*this);
@@ -515,23 +515,26 @@
     xmlsimplereader.parse(xmlsource);
     f.close();
     postfile.remove();
+    return true;
 }
 
-void DataDirectProcessor::grabLineupsOnly() 
+bool DataDirectProcessor::grabLineupsOnly() 
 {
+    bool ok = true;
     if ((lastrunuserid != getUserID()) || (lastrunpassword != getPassword())) 
     {
         lastrunuserid = getUserID();
         lastrunpassword = getPassword();
-        grabData(true, QDateTime::currentDateTime(),
-                 QDateTime::currentDateTime());
-    }   
+        ok = grabData(true, QDateTime::currentDateTime(),
+                      QDateTime::currentDateTime());
+    }
+    return ok;
 }   
 
-void DataDirectProcessor::grabAllData() 
+bool DataDirectProcessor::grabAllData() 
 {
-    grabData(false, QDateTime(QDate::currentDate()).addDays(-2),
-             QDateTime(QDate::currentDate()).addDays(15));
+    return grabData(false, QDateTime(QDate::currentDate()).addDays(-2),
+                    QDateTime(QDate::currentDate()).addDays(15));
 }
 
 void DataDirectProcessor::createATempTable(const QString &ptablename, 
Index: libs/libmythtv/videosource.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/videosource.cpp,v
retrieving revision 1.52
diff -u -r1.52 videosource.cpp
--- libs/libmythtv/videosource.cpp	20 Nov 2004 05:54:23 -0000	1.52
+++ libs/libmythtv/videosource.cpp	29 Dec 2004 20:04:01 -0000
@@ -132,8 +132,11 @@
 
     pdlg.setProgress(1);
 
-    ddp.grabLineupsOnly();
-
+    if (!ddp.grabLineupsOnly())
+    {
+        VERBOSE(VB_IMPORTANT, "DDLS: fillSelections did not successfully load selections");
+        return;
+    }
     QValueList<DataDirectLineup> lineups = ddp.getLineups();
 
     QValueList<DataDirectLineup>::iterator it;
Index: programs/mythfilldatabase/filldata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfilldatabase/filldata.cpp,v
retrieving revision 1.140
diff -u -r1.140 filldata.cpp
--- programs/mythfilldatabase/filldata.cpp	27 Dec 2004 04:33:08 -0000	1.140
+++ programs/mythfilldatabase/filldata.cpp	29 Dec 2004 20:04:02 -0000
@@ -912,7 +912,11 @@
         {
             if (!quiet)
                 cout << "Grabbing ALL available data...\n";
-            ddprocessor.grabAllData();
+            if (!ddprocessor.grabAllData())
+            {
+                cerr << "Encountered error in grabbing data...\n";
+                return false;
+            }
         }
         else
         {


More information about the mythtv-dev mailing list