Permalink
Browse files

Add MythCoreContext::WaitUntilSignals convenience method.

This will simplify the definition and use of Qt signals.
  • Loading branch information...
1 parent a519a4d commit 8626774c0e02405e03fe4d783f87f9ba7d2459bb @jyavenard jyavenard committed Jul 15, 2012
Showing with 38 additions and 2 deletions.
  1. +35 −0 mythtv/libs/libmythbase/mythcorecontext.cpp
  2. +3 −2 mythtv/libs/libmythbase/mythcorecontext.h
@@ -13,6 +13,7 @@
#include <QLocale>
#include <cmath>
+#include <cstdarg>
#include <queue>
#include <algorithm>
@@ -1329,4 +1330,38 @@ MythScheduler *MythCoreContext::GetScheduler(void)
return d->m_scheduler;
}
+/**
+ * \fn void MythCoreContext::WaitUntilSignals(const char *signal1, ...)
+ * Wait until either of the provided signals have been received.
+ * signal1 being declared as SIGNAL(SignalName(args,..))
+ */
+void MythCoreContext::WaitUntilSignals(const char *signal1, ...)
+{
+ if (!signal1)
+ return;
+
+ const char *s;
+ QEventLoop eventLoop;
+ va_list vl;
+
+ LOG(VB_GENERAL, LOG_DEBUG, LOC +
+ QString("Waiting for signal %1")
+ .arg(signal1));
+ connect(this, signal1, &eventLoop, SLOT(quit()));
+
+ va_start(vl, signal1);
+ s = va_arg(vl, const char *);
+ while (s)
+ {
+ LOG(VB_GENERAL, LOG_DEBUG, LOC +
+ QString("Waiting for signal %1")
+ .arg(s));
+ connect(this, s, &eventLoop, SLOT(quit()));
+ s = va_arg(vl, const char *);
+ }
+ va_end(vl);
+
+ eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
+}
+
/* vim: set expandtab tabstop=4 shiftwidth=4: */
@@ -168,8 +168,9 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
QString GetLanguage(void);
QString GetLanguageAndVariant(void);
void ResetLanguage(void);
-
+
// signal related methods
+ void WaitUntilSignals(const char *signal1, ...);
void emitTVPlaybackStarted(void) { emit TVPlaybackStarted(); }
void emitTVPlaybackStopped(void) { emit TVPlaybackStopped(); }
void emitTVPlaybackSought(qint64 position) { emit TVPlaybackSought(position); }
@@ -184,7 +185,7 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
void TVPlaybackPaused(void);
void TVPlaybackUnpaused(void);
void TVPlaybackAborted(void);
-
+
private:
MythCoreContextPrivate *d;

0 comments on commit 8626774

Please sign in to comment.