This removes the two exits in tv_play.cpp

Like the tv_rec patch it removes the exit in the class initialization by moving the exiting code to the pre-existing Init class.
The HandleStateChange() exit is handled by setting an errored variable, but I'm not entirely sure this is handled correctly and would appreciate input from someone familiar with tv_play.cpp


-- Daniel
Index: libs/libmythtv/tv_play.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_play.cpp,v
retrieving revision 1.233
diff -u -r1.233 tv_play.cpp
--- libs/libmythtv/tv_play.cpp  24 Dec 2004 23:24:07 -0000      1.233
+++ libs/libmythtv/tv_play.cpp  28 Dec 2004 21:23:05 -0000
@@ -200,22 +200,6 @@
 TV::TV(void)
   : QObject()
 {
-    QString dbname = QString("tvplayback%1%2").arg(getpid()).arg(rand());
-
-    m_db = new MythSqlDatabase(dbname);
-
-    if (!m_db || !m_db->isOpen())
-    {
-        VERBOSE(VB_IMPORTANT, "TV: Couldn't open DB connection in player, 
exiting");
-        exit(-18);
-    }
-    
-    repoLevel = gContext->GetNumSetting("TVRepositionLevel", 2);
-    
-    if((repoLevel >= MAX_REPO_LEVEL) || (repoLevel < 0) )
-        repoLevel = MAX_REPO_LEVEL - 1;
-    
-    
     treeMenu = NULL;
     switchingCards = false;
     dialogname = "";
@@ -246,9 +230,8 @@
     udpnotify = NULL;
 
     normal_speed = 1.0;
+    errored = false;
     
-    baseFilters += gContext->GetSetting("CustomFilters");
-
     gContext->addListener(this);
 
     PrevChannelVector channame_vector(30);
@@ -269,8 +252,23 @@
     connect(sleepTimer, SIGNAL(timeout()), SLOT(SleepEndTimer()));
 }
 
-void TV::Init(bool createWindow)
+bool TV::Init(bool createWindow)
 {
+    QString dbname = QString("tvplayback%1%2").arg(getpid()).arg(rand());
+    m_db = new MythSqlDatabase(dbname);
+
+    if (!m_db || !m_db->isOpen())
+    {
+        VERBOSE(VB_IMPORTANT, "TV::Init(): Error, Couldn't open DB connection 
in player");
+        errored = true;
+        return false;
+    }
+    
+    repoLevel = gContext->GetNumSetting("TVRepositionLevel", 2);
+    if((repoLevel >= MAX_REPO_LEVEL) || (repoLevel < 0) )
+        repoLevel = MAX_REPO_LEVEL - 1;
+    
+    baseFilters += gContext->GetSetting("CustomFilters");
     fftime = gContext->GetNumSetting("FastForwardAmount", 30);
     rewtime = gContext->GetNumSetting("RewindAmount", 5);
     jumptime = gContext->GetNumSetting("JumpAmount", 10);
@@ -354,8 +352,10 @@
 
     pthread_create(&event, NULL, EventThread, this);
 
-    while (!runMainLoop)
+    while (!runMainLoop && !IsErrored())
         usleep(50);
+
+    return !IsErrored();
 }
 
 TV::~TV(void)
@@ -617,6 +617,12 @@
 
 void TV::HandleStateChange(void)
 {
+    if (IsErrored())
+    {
+        VERBOSE(VB_IMPORTANT, "TV: HandleStateChange() called after fatal 
error detected.");
+        return;
+    }
+
     bool changed = false;
 
     TVState tmpInternalState = internalState;
@@ -629,7 +635,8 @@
     if (nextState == kState_Error)
     {
         VERBOSE(VB_IMPORTANT, "TV: Attempting to set to an error state, 
exiting");
-        exit(-19);
+        errored = true;
+        return;
     }
 
     if (internalState == kState_None && nextState == kState_WatchingLiveTV)
@@ -1137,7 +1144,7 @@
             }
         }
 
-        if (recorder && recorder->GetErrorStatus())
+        if ((recorder && recorder->GetErrorStatus()) || IsErrored())
         {
             exitPlayer = true;
             wantsToQuit = true;
@@ -1227,8 +1234,10 @@
         }
     }
   
-    nextState = kState_None;
-    HandleStateChange();
+    if (!IsErrored()) {
+        nextState = kState_None;
+        HandleStateChange();
+    }
 }
 
 bool TV::eventFilter(QObject *o, QEvent *e)
Index: libs/libmythtv/tv_play.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_play.h,v
retrieving revision 1.82
diff -u -r1.82 tv_play.h
--- libs/libmythtv/tv_play.h    24 Dec 2004 23:24:07 -0000      1.82
+++ libs/libmythtv/tv_play.h    28 Dec 2004 21:23:05 -0000
@@ -34,7 +34,7 @@
 
     static void InitKeys(void);
 
-    void Init(bool createWindow = true);
+    bool Init(bool createWindow = true);
 
     int LiveTV(bool showDialogs = true);
     void StopLiveTV(void) { exitPlayer = true; }
@@ -90,6 +90,7 @@
 
     OSD *GetOSD(void);
 
+    bool IsErrored() { return errored; }
   public slots:
     void HandleOSDClosed(int osdType);
 
@@ -333,6 +334,7 @@
     
     QString baseFilters;
     int repoLevel;
+    bool errored;
 };
 
 #endif
Index: programs/mythfrontend/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/main.cpp,v
retrieving revision 1.178
diff -u -r1.178 main.cpp
--- programs/mythfrontend/main.cpp      8 Dec 2004 03:09:17 -0000       1.178
+++ programs/mythfrontend/main.cpp      28 Dec 2004 21:23:06 -0000
@@ -250,11 +250,15 @@
 void startTV(void)
 {
     TV *tv = new TV();
-
+ 
     QTime timer;
     timer.start();
 
-    tv->Init();
+    if (!tv->Init()) {
+        VERBOSE(VB_IMPORTANT, "Experienced fatal error initializing TV class 
in startTV().");
+        delete tv;
+        return;
+    }
 
     bool tryTV = false;
     bool tryRecorder = false;
@@ -593,10 +597,12 @@
 {
     int res = -1; 
     
-   
     TV *tv = new TV();
-
-    tv->Init();
+    if (!tv->Init()) {
+        VERBOSE(VB_IMPORTANT, "Experienced fatal error initializing TV class 
in internal_play_media().");
+        delete tv;
+        return res;
+    }
 
     ProgramInfo *pginfo = new ProgramInfo();
     pginfo->recstartts = QDateTime::currentDateTime().addSecs((0 - (lenMins + 
1)) * 60 );
Index: programs/mythfrontend/manualbox.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/manualbox.cpp,v
retrieving revision 1.13
diff -u -r1.13 manualbox.cpp
--- programs/mythfrontend/manualbox.cpp 15 Aug 2004 22:38:32 -0000      1.13
+++ programs/mythfrontend/manualbox.cpp 28 Dec 2004 21:23:06 -0000
@@ -204,7 +204,15 @@
         tvstarting = true;
 
         m_tv = new TV();
-        m_tv->Init(false);
+        if (!m_tv->Init(false)) {
+            VERBOSE(VB_IMPORTANT, "Experienced fatal error initialzing "
+                    "TV class in ManualBox::startPlayer().");
+            delete m_tv;
+            m_tv = 0;
+            tvstarting = false;
+            return;
+        }
+        
 
         m_tv->EmbedOutput(m_pixlabel->winId(), 0, 0, (int)(320 * wmult),
                                                      (int)(240 * hmult));
Index: programs/mythfrontend/playbackbox.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/playbackbox.cpp,v
retrieving revision 1.180
diff -u -r1.180 playbackbox.cpp
--- programs/mythfrontend/playbackbox.cpp       24 Dec 2004 23:24:07 -0000      
1.180
+++ programs/mythfrontend/playbackbox.cpp       28 Dec 2004 21:23:07 -0000
@@ -1445,14 +1445,22 @@
 
     if (fileExists(rec) == false)
     {
-        cerr << "Error: " << rec->pathname << " file not found\n";
+        QString msg = 
+            QString("PlaybackBox::play(): Error, %1 file not found").
+            arg(rec->pathname);
+        VERBOSE(VB_IMPORTANT, msg);
         return;
     }
 
     ProgramInfo *tvrec = new ProgramInfo(*rec);
 
     TV *tv = new TV();
-    tv->Init();
+    if (!tv->Init()) {
+        VERBOSE(VB_IMPORTANT, "PlaybackBox::play(): Error, initializing TV 
class.");
+        delete tv;
+        delete tvrec;
+        return;
+    }
 
     setEnabled(false);
     state = kKilling; // stop preview playback and don't restart it
Index: programs/mythtv/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythtv/main.cpp,v
retrieving revision 1.39
diff -u -r1.39 main.cpp
--- programs/mythtv/main.cpp    24 Dec 2004 23:24:07 -0000      1.39
+++ programs/mythtv/main.cpp    28 Dec 2004 21:23:07 -0000
@@ -86,7 +86,7 @@
     QString themedir = gContext->FindThemeDir(themename);
     if (themedir == "")
     {   
-        cerr << "Couldn't find theme " << themename << endl;
+        VERBOSE(VB_IMPORTANT, QString("Fatal Error 44: Couldn't find theme 
'%1'.").arg(themename));
         return 44; // exit(44)
     }
     
@@ -95,12 +95,12 @@
     QSqlDatabase *db = QSqlDatabase::addDatabase("QMYSQL3");
     if (!db)
     {
-        printf("Couldn't connect to database\n");
+        VERBOSE(VB_IMPORTANT, "Fatal Error 45: Couldn't connect to database.");
         return 45; // exit(45)
     }       
     if (!gContext->OpenDatabase(db))
     {
-        printf("couldn't open db\n");
+        VERBOSE(VB_IMPORTANT, "Fatal Error 46: Couldn't open the database.");
         return 46; // exit(46)
     }
 
@@ -109,7 +109,7 @@
     QString auddevice = gContext->GetSetting("AudioOutputDevice");
     if (auddevice == "" || auddevice == QString::null)
     {
-        cerr << "You need to run 'mythfrontend', not 'mythtv'.\n";
+        VERBOSE(VB_IMPORTANT, "Fatal Error 47: You need to run 'mythfrontend', 
not 'mythtv'.");
         return 47; // exit(47)
     }
 
@@ -122,7 +122,10 @@
     TV::InitKeys();
 
     TV *tv = new TV();
-    tv->Init();
+    if (!tv->Init()) {
+        VERBOSE(VB_IMPORTANT, "Fatal Error 51: Error initializing TV class.");
+        return 51; // exit(51)
+    }
 
     if (a.argc() > 1)
     {
_______________________________________________
mythtv-dev mailing list
[email protected]
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev

Reply via email to