[mythtv] [PATCH] MythVideo - Support for timeout on GetMovieListing

dan dan at milkcarton.com
Fri May 30 17:10:57 EDT 2003


I found that during peak times (Or when my cable modem is acting up) the 
InetGrabber thread sometimes wouldn't be able to connect to the imdb 
server and everything would appear hung until you press "Esc".  So, I 
added in a timer (Currently set to 5 seconds) to cycle the thread (Max 
of three times) if it wasn't able to contact the imdb server.

Let me know if anything needs to be done to get this accepted.

-dan
-------------- next part --------------
Index: mythvideo/videomanager.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videomanager.cpp,v
retrieving revision 1.2
diff -u -d -r1.2 videomanager.cpp
--- mythvideo/videomanager.cpp	28 May 2003 02:26:30 -0000	1.2
+++ mythvideo/videomanager.cpp	30 May 2003 23:52:25 -0000
@@ -51,6 +51,9 @@
     listCountMovie = 0;
     dataCountMovie = 0;

+    GetMovieListingTimeoutCounter = 0;
+    stopProcessing = false;
+
     m_state = 0;
     InetGrabber = NULL;

@@ -84,6 +87,9 @@

     connect(this, SIGNAL(killTheApp()), this, SLOT(accept()));

+    urlTimer = new QTimer(this);
+    connect(urlTimer, SIGNAL(timeout()), SLOT(GetMovieListingTimeOut()));
+
     theme = new XMLParse();
     theme->SetWMult(wmult);
     theme->SetHMult(hmult);
@@ -556,13 +563,14 @@
 {
     int ret = -1;
     QString host = "us.imdb.com";
+    theMovieName = movieName;

     QUrl url("http://" + host + "/Tsearch?title=" + movieName + "&type=fuzzy&from_year=1890"
            + "&to_year=2010&sort=smart&tv=off&x=12&y=14"
 	   + " HTTP/1.1\nHost: us.imdb.com\nUser-Agent: Mozilla/9.876 (X11; U; Linux 2.2.12-20 i686, en)"
 	   + " Gecko/25250101 Netscape/5.432b1\n");

-    //cout << "Grabbing Listing From: " << url.toString() << endl;
+    cout << "Grabbing Listing From: " << url.toString() << endl;

     if (InetGrabber)
     {
@@ -572,11 +580,22 @@

     InetGrabber = new INETComms(url);

+    //Start the timer so we can send the request again (Up to three times) if it failes
+    urlTimer->stop();
+    urlTimer->start(5000);
+
+    stopProcessing = false;
     while (!InetGrabber->isDone())
     {
         qApp->processEvents();
+        //Check if we reached the max timeouts
+        if(stopProcessing)
+            return 1;
     }

+    //Stop the timer
+    urlTimer->stop();
+
     QString res;
     res = InetGrabber->getData();

@@ -1152,6 +1171,7 @@
         backup.end();
         update(fullRect());
         noUpdate = false;
+        urlTimer->stop();
     }
     else
         emit killTheApp();
@@ -1586,4 +1606,27 @@
 {
     QRect r(0, 0, (int)(800*wmult), (int)(600*hmult));
     return r;
+}
+
+void VideoManager::GetMovieListingTimeOut()
+{
+    //Increment the counter and check were not over the limit
+    if(++GetMovieListingTimeoutCounter != 3)
+    {
+        //Try again
+        GetMovieListing(theMovieName);
+    }
+    else
+    {
+        GetMovieListingTimeoutCounter = 0;
+        cerr << "Failed to contact  server" << endl;
+
+        //Set the stopProcessing var so the other thread knows what to do
+        stopProcessing = true;
+
+        //Let the exitWin method take care of closing the dialog screen
+        exitWin();
+    }
+
+    return;
 }
Index: mythvideo/videomanager.h
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videomanager.h,v
retrieving revision 1.1
diff -u -d -r1.1 videomanager.h
--- mythvideo/videomanager.h	27 May 2003 21:09:33 -0000	1.1
+++ mythvideo/videomanager.h	30 May 2003 23:52:25 -0000
@@ -10,6 +10,7 @@
 #include "metadata.h"
 #include <mythtv/mythwidgets.h>
 #include <qdom.h>
+#include <qtimer.h>
 #include <mythtv/uitypes.h>
 #include <mythtv/xmlparse.h>
 
@@ -39,6 +40,7 @@
     void pageDown() { cursorDown(true); }
     void pageUp() { cursorUp(true); }
     void exitWin();
+    void GetMovieListingTimeOut();
 
   protected:
     void paintEvent(QPaintEvent *);
@@ -138,8 +140,11 @@
     QString movieRating;
     int movieRuntime;
     QString movieNumber;
-
 
+    QTimer *urlTimer;
+    int GetMovieListingTimeoutCounter;
+    bool stopProcessing;
+    QString theMovieName;
 };
 
 #endif


More information about the mythtv-dev mailing list