Diana Software
QDbWatchdogThread.cc
Go to the documentation of this file.
1 #include "QDbWatchdogThread.hh"
2 
3 #include "QError.hh"
4 #include "QDb.hh"
5 #include "QWatchdogTimer.hh"
6 #include <unistd.h>
7 
8 //_____________________________________________________________________________
10  QBaseThread()
11 {
12 }
13 
14 
16 {
17  if(NULL == fErr)
18  throw QError(QERR_UNDEFINED_STATUS, __FILE__, __LINE__,
19  "fErr is not set for this thread");
20 
21  if(NULL == fControlFlag)
22  {
23  fErr->Set(QERR_UNDEFINED_STATUS, __FILE__, __LINE__,
24  "fControlFlag is not set for this thread");
25  return;
26  }
27 
28  if(NULL == fTimer)
29  {
30  fErr->Set(QERR_UNDEFINED_STATUS, __FILE__, __LINE__,
31  "fTimer is not set for this thread");
32  return;
33  }
34 
35  if(NULL == fDb)
36  {
37  fErr->Set(QERR_UNDEFINED_STATUS, __FILE__, __LINE__,
38  "fDb is not set for this thread");
39  return;
40  }
41 
42 
43  while(0 == *fControlFlag) {
44  if(*fErr != QERR_SUCCESS)
45  return;
46 
47  bool elapsed = false;
48  *fErr = fTimer->TimeoutElapsed(elapsed);
49  if(*fErr != QERR_SUCCESS)
50  return;
51 
52  if(elapsed && fDb->IsConnected())
53  {
54  bool success = fDb->Disconnect();
55  if(!success) {
56  fErr->Set(QERR_UNDEFINED_STATUS, __FILE__, __LINE__,
57  "Disconnect failed()");
58  return;
59  }
60  }
61  usleep(500000);
62  }
63  return;
64 }
success
Definition: CheckOF.C:112
@ QERR_UNDEFINED_STATUS
Definition: QError.hh:51
@ QERR_SUCCESS
Definition: QError.hh:27
base abstract class for running a separate thread
Definition: QBaseThread.hh:21
const int * fControlFlag
Definition: QBaseThread.hh:32
QError * fErr
Definition: QBaseThread.hh:31
QWatchdogTimer * fTimer
virtual void operator()()
bool Disconnect()
Definition: QDb.cc:151
bool IsConnected() const
Definition: QDb.cc:66
error class with error type and description
Definition: QError.hh:115
void Set(QError_ e=QERR_SUCCESS, const std::string &descr="")
set to error code and description (default is SUCCESS)
Definition: QError.cc:157
QError TimeoutElapsed(bool &elapsed) const