[mythtv] [patch] exit cleanup of tv_rec.{cpp,h}
Daniel Thor Kristjansson
danielk at mrl.nyu.edu
Mon Jan 24 20:17:27 EST 2005
On Tue, 28 Dec 2004, Daniel Thor Kristjansson wrote:
]This removes the two exit's in tv_rec.cpp.
]
]The first is removed by moving some initialization to the pre-existing Init()
]function, and changing it to return a boolean for success of failure and
]checking it for failure in the mythbackend main() function.
]
]The second is eliminated by creating a 'errored' variable and setting it to
]true if an error is encountered in HandleEvent. This is then checked for in the
]RunTV loop, and we exit it if this the error condition is ever set. This
]changes the behavior somewhat in that instead of exiting, any other TVRec cards
]continue working. We should have a monitor thread that restarts a RunTV thread
]if it ever exits. But I'm considering this a feature that can be added later.
](And it should probably wait as I'm likely to find other things that should be
]monitored in my random exit removal project.)
Updated patch to latest CVS.
This patch is also available at: http://www.mrl.nyu.edu/~danielk/mythtv/
-- Daniel
-------------- next part --------------
Index: libs/libmythtv/tv_rec.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_rec.h,v
retrieving revision 1.60
diff -u -r1.60 tv_rec.h
--- libs/libmythtv/tv_rec.h 23 Jan 2005 22:45:30 -0000 1.60
+++ libs/libmythtv/tv_rec.h 25 Jan 2005 00:49:06 -0000
@@ -47,7 +47,7 @@
TVRec(int capturecardnum);
~TVRec(void);
- void Init(void);
+ bool Init(void); // returns true if init is successful
void RecordPending(ProgramInfo *rcinfo, int secsleft);
int StartRecording(ProgramInfo *rcinfo);
@@ -140,6 +140,7 @@
int GetCaptureCardNum(void) { return m_capturecardnum; }
+ bool IsErrored() { return errored; }
protected:
void RunTV(void);
static void *EventThread(void *param);
@@ -233,6 +234,8 @@
dvb_options_t dvb_options;
+ bool errored;
+
char requestBuffer[256001];
#ifdef USING_DVB
Index: libs/libmythtv/tv_rec.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_rec.cpp,v
retrieving revision 1.169
diff -u -r1.169 tv_rec.cpp
--- libs/libmythtv/tv_rec.cpp 23 Jan 2005 22:45:30 -0000 1.169
+++ libs/libmythtv/tv_rec.cpp 25 Jan 2005 00:49:07 -0000
@@ -78,14 +78,17 @@
ConnectDB(capturecardnum);
- QString chanorder = gContext->GetSetting("ChannelOrdering", "channum + 0");
-
audiosamplerate = -1;
skip_btaudio = false;
+ errored = false;
+}
+bool TVRec::Init(void)
+{
+ QString chanorder = gContext->GetSetting("ChannelOrdering", "channum + 0");
QString inputname, startchannel;
- GetDevices(capturecardnum, videodev, vbidev, audiodev, audiosamplerate,
+ GetDevices(m_capturecardnum, videodev, vbidev, audiodev, audiosamplerate,
inputname, startchannel, cardtype, dvb_options, skip_btaudio);
if (cardtype == "DVB")
@@ -107,11 +110,14 @@
if (dvb_options.dvb_on_demand)
((DVBChannel *)channel)->CloseDVB();
#else
- VERBOSE(VB_IMPORTANT, "ERROR: DVB Card configured, "
- "but no DVB support compiled in!");
- VERBOSE(VB_IMPORTANT, "Remove the card from configuration, "
- "or recompile MythTV.");
- exit(-20);
+ QString msg = QString(
+ "ERROR: DVB Card configured on %1, but MythTV was not compiled\n"
+ "with DVB support. Please, recompile MythTV with DVB support\n"
+ "or remove the card from configuration and recompile MythTV.")
+ .arg(videodev);
+ VERBOSE(VB_IMPORTANT, msg);
+ errored = true;
+ return false;
#endif
}
else if ((cardtype == "MPEG") && (videodev.lower().left(5) == "file:"))
@@ -132,10 +138,7 @@
channel->SetChannelOrdering(chanorder);
channel->Close();
}
-}
-void TVRec::Init(void)
-{
inoverrecord = false;
overrecordseconds = gContext->GetNumSetting("RecordOverTime");
@@ -160,6 +163,8 @@
curRecording = NULL;
prevRecording = NULL;
pendingRecording = NULL;
+
+ return true;
}
TVRec::~TVRec(void)
@@ -425,7 +430,8 @@
if (nextState == kState_Error)
{
VERBOSE(VB_IMPORTANT, "TVRec: Attempting to set to an error state, exiting");
- exit(-21);
+ errored = true;
+ return;
}
if (tmpInternalState == kState_None && nextState == kState_WatchingLiveTV)
@@ -878,6 +884,13 @@
{
if (changeState)
HandleStateChange();
+ if (IsErrored())
+ {
+ VERBOSE(VB_IMPORTANT, "TVRec: RunTV encountered "
+ "fatal error, exiting event thread.");
+ runMainLoop = false;
+ return;
+ }
usleep(1000);
Index: programs/mythbackend/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/main.cpp,v
retrieving revision 1.79
diff -u -r1.79 main.cpp
--- programs/mythbackend/main.cpp 21 Jan 2005 18:53:48 -0000 1.79
+++ programs/mythbackend/main.cpp 25 Jan 2005 00:49:08 -0000
@@ -112,7 +112,13 @@
if (host == localhostname)
{
TVRec *tv = new TVRec(cardid);
- tv->Init();
+ if (!tv->Init())
+ {
+ VERBOSE(VB_IMPORTANT,
+ "mythbackend: Unable to initialize "
+ "slave TVRec class, exiting.");
+ exit(51);
+ }
EncoderLink *enc = new EncoderLink(cardid, tv);
tvList[cardid] = enc;
}
@@ -122,7 +128,13 @@
if (host == localhostname)
{
TVRec *tv = new TVRec(cardid);
- tv->Init();
+ if (!tv->Init())
+ {
+ VERBOSE(VB_IMPORTANT,
+ "mythbackend: Unable to initialize "
+ "master TVRec() class, exiting.");
+ exit(52);
+ }
EncoderLink *enc = new EncoderLink(cardid, tv);
tvList[cardid] = enc;
}
More information about the mythtv-dev
mailing list