Permalink
Browse files

Change logging/loggingserver from QTimer to MythSignalingTimer

Also fixed a few more uninitialized data issues in the LoggingItem, and added
isActive() to MythSignalingTimer class
  • Loading branch information...
1 parent 62f3c64 commit 2b189a9a2a3826128f7f9767990548bd5dd2a97e @Beirdo Beirdo committed Jun 18, 2012
@@ -11,7 +11,6 @@
#include <QMap>
#include <QRegExp>
#include <QVariantMap>
-#include <QTimer>
#include <iostream>
using namespace std;
@@ -24,6 +23,7 @@ using namespace std;
#include "mythdirs.h"
#include "mythcorecontext.h"
#include "mythsystem.h"
+#include "mythsignalingtimer.h"
#include "dbutil.h"
#include "exitcodes.h"
#include "compat.h"
@@ -144,7 +144,8 @@ LoggingItem::LoggingItem(const char *_file, const char *_function,
int _line, LogLevel_t _level, LoggingType _type) :
m_threadId((uint64_t)(QThread::currentThreadId())),
m_line(_line), m_type(_type), m_level(_level),
- m_file(strdup(_file)), m_function(strdup(_function)), m_threadName(NULL)
+ m_file(strdup(_file)), m_function(strdup(_function)),
+ m_threadName(NULL), m_appName(NULL), m_table(NULL), m_logFile(NULL)
{
loggingGetTimeStamp(&m_epoch, &m_usec);
@@ -252,7 +253,9 @@ LoggerThread::LoggerThread(QString filename, bool progress, bool quiet,
m_waitEmpty(new QWaitCondition()),
m_aborted(false), m_filename(filename), m_progress(progress),
m_quiet(quiet), m_appname(QCoreApplication::applicationName()),
- m_tablename(table), m_facility(facility), m_pid(getpid())
+ m_tablename(table), m_facility(facility), m_pid(getpid()),
+ m_zmqContext(NULL), m_zmqSocket(NULL), m_initialTimer(NULL),
+ m_heartbeatTimer(NULL)
{
char *debug = getenv("VERBOSE_THREADS");
if (debug != NULL)
@@ -269,6 +272,18 @@ LoggerThread::LoggerThread(QString filename, bool progress, bool quiet,
/// \brief LoggerThread destructor. Triggers the deletion of all loggers.
LoggerThread::~LoggerThread()
{
+ if (m_initialTimer)
+ {
+ m_initialTimer->stop();
+ delete m_initialTimer;
+ }
+
+ if (m_heartbeatTimer)
+ {
+ m_heartbeatTimer->stop();
+ delete m_heartbeatTimer;
+ }
+
stop();
wait();
@@ -318,17 +333,16 @@ void LoggerThread::run(void)
pingLogServer();
// wait up to 150ms for mythlogserver to respond
- QTimer::singleShot(150, this, SLOT(initialTimeout()));
+ m_initialTimer = new MythSignalingTimer(this, SLOT(initialTimeout()));
+ m_initialTimer->start(150);
}
else
LOG(VB_GENERAL, LOG_INFO, "Added logging to mythlogserver locally");
loggingGetTimeStamp(&m_epoch, NULL);
- QTimer *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(checkHeartBeat()),
- Qt::QueuedConnection);
- timer->start(1000);
+ m_heartbeatTimer = new MythSignalingTimer(this, SLOT(checkHeartBeat()));
+ m_heartbeatTimer->start(1000);
QMutexLocker qLock(&logQueueMutex);
@@ -356,8 +370,9 @@ void LoggerThread::run(void)
qLock.relock();
}
- timer->stop();
- delete timer;
+ m_heartbeatTimer->stop();
+ delete m_heartbeatTimer;
+ m_heartbeatTimer = NULL;
m_zmqSocket->setLinger(0);
m_zmqSocket->close();
@@ -376,6 +391,10 @@ void LoggerThread::run(void)
/// to show signs of life
void LoggerThread::initialTimeout(void)
{
+ m_initialTimer->stop();
+ delete m_initialTimer;
+ m_initialTimer = NULL;
+
if (m_initialWaiting)
{
// Got no response from mythlogserver, let's assume it's dead and
@@ -13,6 +13,7 @@
#include "mythbaseexp.h" // MBASE_PUBLIC , etc.
#include "verbosedefs.h"
+#include "mythsignalingtimer.h"
#include "mthread.h"
#include "nzmqt.hpp"
@@ -200,6 +201,9 @@ class LoggerThread : public QObject, public MThread
nzmqt::ZMQSocket *m_zmqSocket; ///< ZeroMQ socket to talk to
/// mythlogserver
+ MythSignalingTimer *m_initialTimer; ///< Timer for the initial startup
+ MythSignalingTimer *m_heartbeatTimer; ///< Timer for 1s heartbeats
+
protected:
bool logConsole(LoggingItem *item);
void launchLogServer(void);
@@ -10,7 +10,6 @@
#include <QStringList>
#include <QMap>
#include <QRegExp>
-#include <QTimer>
#include <QSocketNotifier>
#include <iostream>
@@ -22,6 +21,7 @@ using namespace std;
#include "mythconfig.h"
#include "mythdb.h"
#include "mythcorecontext.h"
+#include "mythsignalingtimer.h"
#include "dbutil.h"
#include "exitcodes.h"
#include "compat.h"
@@ -705,9 +705,7 @@ void LogServerThread::run(void)
// cerr << "unlock" << endl;
msgsSinceHeartbeat = 0;
- m_heartbeatTimer = new QTimer(this);
- connect(m_heartbeatTimer, SIGNAL(timeout()), this, SLOT(checkHeartBeats()),
- Qt::QueuedConnection);
+ m_heartbeatTimer = new MythSignalingTimer(this, SLOT(checkHeartBeats()));
m_heartbeatTimer->start(1000);
exec();
@@ -985,10 +983,8 @@ void LogForwardThread::run(void)
m_zmqPubSock = m_zmqContext->createSocket(nzmqt::ZMQSocket::TYP_PUB, this);
m_zmqPubSock->bindTo("inproc://loggers");
- m_shutdownTimer = new QTimer(this);
- m_shutdownTimer->setSingleShot(true);
- connect(m_shutdownTimer, SIGNAL(timeout()),
- this, SLOT(shutdownTimerExpired()), Qt::QueuedConnection);
+ m_shutdownTimer = new MythSignalingTimer(this,
+ SLOT(shutdownTimerExpired()));
LOG(VB_GENERAL, LOG_INFO, "Starting 5min shutdown timer");
m_shutdownTimer->start(5*60*1000);
@@ -1015,7 +1011,7 @@ void LogForwardThread::run(void)
// Force a processEvents every 128 messages so a busy queue
// doesn't preclude timer notifications, etc.
- if (processed & 127 == 0)
+ if ((processed & 127) == 0)
qApp->processEvents(QEventLoop::AllEvents, 10);
lock.relock();
@@ -13,6 +13,7 @@
#include "mythbaseexp.h" // MBASE_PUBLIC , etc.
#include "verbosedefs.h"
+#include "mythsignalingtimer.h"
#include "mthread.h"
#include "nzmqt.hpp"
@@ -147,8 +148,8 @@ class LogServerThread : public QObject, public MThread
nzmqt::ZMQContext *m_zmqContext; ///< ZeroMQ context
nzmqt::ZMQSocket *m_zmqInSock; ///< ZeroMQ feeding socket
- QTimer *m_heartbeatTimer; ///< 1s repeating timer for client
- /// heartbeats
+ MythSignalingTimer *m_heartbeatTimer; ///< 1s repeating timer for client
+ /// heartbeats
protected slots:
void receivedMessage(const QList<QByteArray>&);
@@ -177,7 +178,8 @@ class LogForwardThread : public QObject, public MThread
QSocketNotifier *m_sighupNotifier; ///< Notifier to synchronize to UNIX
/// signal SIGHUP safely
- QTimer *m_shutdownTimer; ///< 5 min timer to shut down if no clients
+ MythSignalingTimer *m_shutdownTimer; ///< 5 min timer to shut down if no
+ /// clients
void forwardMessage(LogMessage *msg);
void expireClients(void);
@@ -29,6 +29,8 @@ class MBASE_PUBLIC MythSignalingTimer : private QObject, private MThread
virtual bool blockSignals(bool block)
{ return QObject::blockSignals(block); }
+ bool isActive(void) const
+ { return dorun; }
signals:
void timeout(void);

0 comments on commit 2b189a9

Please sign in to comment.