Permalink
Browse files

Merge branch 'master' of code.mythtv.org:mythtv

  • Loading branch information...
2 parents 2075e9f + 035ab81 commit bd82805d57c6fc4ff4248a33172ecd9e7b653268 @nriendeau nriendeau committed Jul 15, 2012
@@ -13,6 +13,7 @@
#include <QLocale>
#include <cmath>
+#include <cstdarg>
#include <queue>
#include <algorithm>
@@ -86,6 +87,9 @@ class MythCoreContextPrivate : public QObject
MythScheduler *m_scheduler;
bool m_blockingClient;
+
+ QMap<QObject *, QByteArray> m_playbackClients;
+ QMutex m_playbackLock;
};
MythCoreContextPrivate::MythCoreContextPrivate(MythCoreContext *lparent,
@@ -1329,4 +1333,105 @@ 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);
+}
+
+/**
+ * \fn void MythCoreContext::RegisterForPlayback(QObject *sender, const char *method)
+ * Register sender for TVPlaybackAboutToStart signal. Method will be called upon
+ * the signal being emitted.
+ * sender must call MythCoreContext::UnregisterForPlayback upon deletion
+ */
+void MythCoreContext::RegisterForPlayback(QObject *sender, const char *method)
+{
+ QMutexLocker lock(&d->m_playbackLock);
+
+ if (!d->m_playbackClients.contains(sender))
+ {
+ d->m_playbackClients.insert(sender, QByteArray(method));
+ connect(this, SIGNAL(TVPlaybackAboutToStart()),
+ sender, method,
+ Qt::BlockingQueuedConnection);
+ }
+}
+
+/**
+ * \fn void MythCoreContext::UnregisterForPlayback(QObject *sender)
+ * Unregister sender from being called when TVPlaybackAboutToStart signal
+ * is emitted
+ */
+void MythCoreContext::UnregisterForPlayback(QObject *sender)
+{
+ QMutexLocker lock(&d->m_playbackLock);
+
+ if (d->m_playbackClients.contains(sender))
+ {
+ QByteArray ba = d->m_playbackClients.value(sender);
+ const char *method = ba.constData();
+ disconnect(this, SIGNAL(TVPlaybackAboutToStart()),
+ sender, method);
+ d->m_playbackClients.remove(sender);
+ }
+}
+
+/**
+ * \fn void MythCoreContext::WantingPlayback(QObject *sender)
+ * All the objects that have registered using MythCoreContext::RegisterForPlayback
+ * but sender will be called. The objet's registered method will be called
+ * in a blocking fashion, each of them being called one after the other
+ */
+void MythCoreContext::WantingPlayback(QObject *sender)
+{
+ QMutexLocker lock(&d->m_playbackLock);
+ bool found = false;
+ QByteArray ba;
+ const char *method;
+
+ if (d->m_playbackClients.contains(sender))
+ {
+ found = true;
+ ba = d->m_playbackClients.value(sender);
+ method = ba.constData();
+ disconnect(this, SIGNAL(TVPlaybackAboutToStart()), sender, method);
+ }
+ emit TVPlaybackAboutToStart();
+ if (found)
+ {
+ connect(this, SIGNAL(TVPlaybackAboutToStart()),
+ sender, method,
+ Qt::BlockingQueuedConnection);
+ }
+}
+
/* vim: set expandtab tabstop=4 shiftwidth=4: */
@@ -45,8 +45,9 @@ class MythScheduler;
* It also contains support for database error printing, and
* database message logging.
*/
-class MBASE_PUBLIC MythCoreContext : public MythObservable, public MythSocketCBs
+class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, public MythSocketCBs
{
+ Q_OBJECT
public:
MythCoreContext(const QString &binversion, QObject *eventHandler);
virtual ~MythCoreContext();
@@ -168,6 +169,28 @@ class MBASE_PUBLIC MythCoreContext : public MythObservable, public MythSocketCBs
QString GetLanguageAndVariant(void);
void ResetLanguage(void);
+ void RegisterForPlayback(QObject *sender, const char *method);
+ void UnregisterForPlayback(QObject *sender);
+ void WantingPlayback(QObject *sender);
+
+ // 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); }
+ void emitTVPlaybackPaused(void) { emit TVPlaybackPaused(); }
+ void emitTVPlaybackUnpaused(void) { emit TVPlaybackUnpaused(); }
+ void emitTVPlaybackAborted(void) { emit TVPlaybackAborted(); }
+
+ signals:
+ void TVPlaybackStarted(void);
+ void TVPlaybackStopped(void);
+ void TVPlaybackSought(qint64 position);
+ void TVPlaybackPaused(void);
+ void TVPlaybackUnpaused(void);
+ void TVPlaybackAborted(void);
+ void TVPlaybackAboutToStart(void);
+
private:
MythCoreContextPrivate *d;
Oops, something went wrong.

0 comments on commit bd82805

Please sign in to comment.