[mythtv] [patch] tv_play exit cleanup
Daniel Thor Kristjansson
danielk at mrl.nyu.edu
Wed Mar 2 22:05:46 UTC 2005
This is a resubmit of the tv_play exit cleanup patch.
I've cleaned up the formatting so that lines never exceed 80 columns,
and "if" statements have a return before the open brace "{".
Also I've updated it to use MSqlQuery.
As a reminder this patch removes the exit() calls in tv_play.cpp, it
does this by moving the portion of initialization that can fail
to the Init() function, and returning false from it if there
is a failure. It also replaces some cerr redirects and printf's
with VB_IMPORTANT VERBOSE macros in the effected files.
-- Daniel
-------------- next part --------------
Index: libs/libmythtv/tv_play.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_play.cpp,v
retrieving revision 1.244
diff -u -r1.244 tv_play.cpp
--- libs/libmythtv/tv_play.cpp 27 Feb 2005 21:54:36 -0000 1.244
+++ libs/libmythtv/tv_play.cpp 1 Mar 2005 22:13:27 -0000
@@ -202,20 +202,6 @@
TV::TV(void)
: QObject()
{
-
- MSqlQuery query(MSqlQuery::InitCon());
- if (!query.isConnected())
- {
- 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 +232,8 @@
udpnotify = NULL;
normal_speed = 1.0;
+ errored = false;
- baseFilters += gContext->GetSetting("CustomFilters");
-
gContext->addListener(this);
PrevChannelVector channame_vector(30);
@@ -269,8 +254,22 @@
connect(sleepTimer, SIGNAL(timeout()), SLOT(SleepEndTimer()));
}
-void TV::Init(bool createWindow)
+bool TV::Init(bool createWindow)
{
+ MSqlQuery query(MSqlQuery::InitCon());
+ if (!query.isConnected())
+ {
+ VERBOSE(VB_IMPORTANT, "TV::Init(): Error, could "
+ "not 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 +353,10 @@
pthread_create(&event, NULL, EventThread, this);
- while (!runMainLoop)
+ while (!runMainLoop && !IsErrored())
usleep(50);
+
+ return !IsErrored();
}
TV::~TV(void)
@@ -614,6 +615,13 @@
void TV::HandleStateChange(void)
{
+ if (IsErrored())
+ {
+ VERBOSE(VB_IMPORTANT, "TV::HandleStateChange() Error, "
+ "called after fatal error detected.");
+ return;
+ }
+
bool changed = false;
TVState tmpInternalState = internalState;
@@ -625,8 +633,10 @@
if (nextState == kState_Error)
{
- VERBOSE(VB_IMPORTANT, "TV: Attempting to set to an error state, exiting");
- exit(-19);
+ VERBOSE(VB_IMPORTANT, "TV::HandleStateChange() Error, "
+ "attempting to set to an error state, exiting");
+ errored = true;
+ return;
}
if (internalState == kState_None && nextState == kState_WatchingLiveTV)
@@ -1125,7 +1135,7 @@
}
}
- if (recorder && recorder->GetErrorStatus())
+ if ((recorder && recorder->GetErrorStatus()) || IsErrored())
{
exitPlayer = true;
wantsToQuit = true;
@@ -1215,8 +1225,11 @@
}
}
- 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.84
diff -u -r1.84 tv_play.h
--- libs/libmythtv/tv_play.h 23 Feb 2005 05:04:36 -0000 1.84
+++ libs/libmythtv/tv_play.h 1 Mar 2005 22:13:28 -0000
@@ -33,7 +33,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; }
@@ -89,6 +89,7 @@
OSD *GetOSD(void);
+ bool IsErrored() { return errored; }
public slots:
void HandleOSDClosed(int osdType);
@@ -330,6 +331,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.185
diff -u -r1.185 main.cpp
--- programs/mythfrontend/main.cpp 23 Feb 2005 05:04:36 -0000 1.185
+++ programs/mythfrontend/main.cpp 1 Mar 2005 22:13:29 -0000
@@ -242,7 +242,13 @@
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;
@@ -580,7 +586,13 @@
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.14
diff -u -r1.14 manualbox.cpp
--- programs/mythfrontend/manualbox.cpp 23 Feb 2005 05:04:37 -0000 1.14
+++ programs/mythfrontend/manualbox.cpp 1 Mar 2005 22:13:29 -0000
@@ -204,7 +204,16 @@
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.200
diff -u -r1.200 playbackbox.cpp
--- programs/mythfrontend/playbackbox.cpp 27 Feb 2005 21:54:37 -0000 1.200
+++ programs/mythfrontend/playbackbox.cpp 1 Mar 2005 22:13:31 -0000
@@ -1606,14 +1606,24 @@
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 false;
}
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 false;
+ }
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.42
diff -u -r1.42 main.cpp
--- programs/mythtv/main.cpp 23 Feb 2005 05:04:37 -0000 1.42
+++ programs/mythtv/main.cpp 1 Mar 2005 22:13:42 -0000
@@ -89,7 +89,9 @@
QString themedir = gContext->FindThemeDir(themename);
if (themedir == "")
{
- cerr << "Couldn't find theme " << themename << endl;
+ QString msg = QString("Fatal Error 44: Couldn't find theme '%1'.")
+ .arg(themename);
+ VERBOSE(VB_IMPORTANT, msg);
return 44; // exit(44)
}
@@ -103,7 +105,7 @@
if (!MSqlQuery::testDBConnection())
{
- printf("couldn't open db\n");
+ VERBOSE(VB_IMPORTANT, "Fatal Error 46: Couldn't open the database.");
return 46; // exit(46)
}
@@ -112,7 +114,8 @@
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)
}
@@ -125,7 +128,11 @@
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)
{
More information about the mythtv-dev
mailing list