Skip to content

Commit

Permalink
Change several functions to replace varags with a std::vector.
Browse files Browse the repository at this point in the history
These two functions take a variable umber of the same argument, and it
is easy to replace that with a vector and greatly simplify the
processing of the arguments.  These functions were pointed out by the
clang-tidy cert-dcl50-cpp check.

https://clang.llvm.org/extra/clang-tidy/checks/cert-dcl50-cpp.html
  • Loading branch information
linuxdude42 committed Jul 22, 2020
1 parent d6eb860 commit d1897ae
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 54 deletions.
22 changes: 5 additions & 17 deletions mythtv/libs/libmythbase/mythcorecontext.cpp
Expand Up @@ -1888,34 +1888,22 @@ MythScheduler *MythCoreContext::GetScheduler(void)
}

/**
* \fn void MythCoreContext::WaitUntilSignals(const char *signal1, ...)
* Wait until either of the provided signals have been received.
* signal1 being declared as SIGNAL(SignalName(args,..))
* Wait until any of the provided signals have been received.
* signals being declared as SIGNAL(SignalName(args,..))
*/
void MythCoreContext::WaitUntilSignals(const char *signal1, ...)
void MythCoreContext::WaitUntilSignals(std::vector<const char *> & sigs)
{
if (!signal1)
if (sigs.empty())
return;

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);
const char *s = va_arg(vl, const char *);
while (s)
for (const auto *s : sigs)
{
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 | QEventLoop::ExcludeSocketNotifiers);
}
Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythbase/mythcorecontext.h
@@ -1,6 +1,8 @@
#ifndef MYTHCORECONTEXT_H_
#define MYTHCORECONTEXT_H_

#include <vector>

#include <QObject>
#include <QString>
#include <QHostAddress>
Expand Down Expand Up @@ -246,7 +248,7 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
void setTestStringSettings(QMap<QString,QString>& overrides);

// signal related methods
void WaitUntilSignals(const char *signal1, ...);
void WaitUntilSignals(std::vector<const char *> & sigs);
void emitTVPlaybackStarted(void) { emit TVPlaybackStarted(); }
void emitTVPlaybackStopped(void) { emit TVPlaybackStopped(); }
void emitTVPlaybackSought(qint64 position) { emit TVPlaybackSought(position); }
Expand Down
38 changes: 20 additions & 18 deletions mythtv/libs/libmythtv/AirPlay/mythairplayserver.cpp
Expand Up @@ -3,6 +3,8 @@
// race on startup?
// http date format and locale

#include <vector>

#include <QTcpSocket>
#include <QNetworkInterface>
#include <QCoreApplication>
Expand Down Expand Up @@ -1212,9 +1214,9 @@ void MythAirplayServer::StartPlayback(const QString &pathname)
auto* me = new MythEvent(ACTION_HANDLEMEDIA, QStringList(pathname));
qApp->postEvent(GetMythMainWindow(), me);
// Wait until we receive that the play has started
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackStarted()),
SIGNAL(TVPlaybackAborted()),
nullptr);
std::vector<const char*> sigs { SIGNAL(TVPlaybackStarted()),
SIGNAL(TVPlaybackAborted()) };
gCoreContext->WaitUntilSignals(sigs);
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
QString("ACTION_HANDLEMEDIA completed"));
}
Expand All @@ -1231,9 +1233,9 @@ void MythAirplayServer::StopPlayback(void)
Qt::NoModifier, ACTION_STOP);
qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
// Wait until we receive that playback has stopped
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackStopped()),
SIGNAL(TVPlaybackAborted()),
nullptr);
std::vector<const char*> sigs { SIGNAL(TVPlaybackStopped()),
SIGNAL(TVPlaybackAborted()) };
gCoreContext->WaitUntilSignals(sigs);
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
QString("ACTION_STOP completed"));
}
Expand All @@ -1257,10 +1259,10 @@ void MythAirplayServer::SeekPosition(uint64_t position)
QStringList(QString::number(position)));
qApp->postEvent(GetMythMainWindow(), me);
// Wait until we receive that the seek has completed
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackSought(qint64)),
SIGNAL(TVPlaybackStopped()),
SIGNAL(TVPlaybackAborted()),
nullptr);
std::vector<const char*> sigs { SIGNAL(TVPlaybackSought(qint64)),
SIGNAL(TVPlaybackStopped()),
SIGNAL(TVPlaybackAborted()) };
gCoreContext->WaitUntilSignals(sigs);
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
QString("ACTION_SEEKABSOLUTE completed"));
}
Expand All @@ -1283,10 +1285,10 @@ void MythAirplayServer::PausePlayback(void)
Qt::NoModifier, ACTION_PAUSE);
qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
// Wait until we receive that playback has stopped
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackPaused()),
SIGNAL(TVPlaybackStopped()),
SIGNAL(TVPlaybackAborted()),
nullptr);
std::vector<const char*> sigs { SIGNAL(TVPlaybackPaused()),
SIGNAL(TVPlaybackStopped()),
SIGNAL(TVPlaybackAborted()) };
gCoreContext->WaitUntilSignals(sigs);
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
QString("ACTION_PAUSE completed"));
}
Expand All @@ -1309,10 +1311,10 @@ void MythAirplayServer::UnpausePlayback(void)
Qt::NoModifier, ACTION_PLAY);
qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
// Wait until we receive that playback has stopped
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackPlaying()),
SIGNAL(TVPlaybackStopped()),
SIGNAL(TVPlaybackAborted()),
nullptr);
std::vector<const char*> sigs { SIGNAL(TVPlaybackPlaying()),
SIGNAL(TVPlaybackStopped()),
SIGNAL(TVPlaybackAborted()) };
gCoreContext->WaitUntilSignals(sigs);
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
QString("ACTION_PLAY completed"));
}
Expand Down
23 changes: 5 additions & 18 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -207,21 +207,8 @@ int TV::ConfiguredTunerCards(void)
return count;
}

static void multi_lock(QMutex *mutex0, ...)
static void multi_lock(std::vector<QMutex *> mutex)
{
vector<QMutex*> mutex;
mutex.push_back(mutex0);

va_list argp;
va_start(argp, mutex0);
QMutex *cur = va_arg(argp, QMutex*);
while (cur)
{
mutex.push_back(cur);
cur = va_arg(argp, QMutex*);
}
va_end(argp);

for (bool success = false; !success;)
{
success = true;
Expand Down Expand Up @@ -5747,7 +5734,7 @@ bool TV::PIPAddPlayer(PlayerContext *mctx, PlayerContext *pipctx)
if (is_using_null)
{
addCondition = true;
multi_lock(&mctx->m_deletePlayerLock, &pipctx->m_deletePlayerLock, nullptr);
multi_lock( {&mctx->m_deletePlayerLock, &pipctx->m_deletePlayerLock} );
if (mctx->m_player && pipctx->m_player)
{
PIPLocation loc = mctx->m_player->GetNextPIPLocation();
Expand Down Expand Up @@ -5780,7 +5767,7 @@ bool TV::PIPRemovePlayer(PlayerContext *mctx, PlayerContext *pipctx)
return false;

bool ok = false;
multi_lock(&mctx->m_deletePlayerLock, &pipctx->m_deletePlayerLock, nullptr);
multi_lock( {&mctx->m_deletePlayerLock, &pipctx->m_deletePlayerLock} );
if (mctx->m_player && pipctx->m_player)
ok = mctx->m_player->RemovePIPPlayer(pipctx->m_player);
mctx->m_deletePlayerLock.unlock();
Expand Down Expand Up @@ -5983,7 +5970,7 @@ bool TV::ResizePIPWindow(PlayerContext *ctx)
{
QRect rect;

multi_lock(&mctx->m_deletePlayerLock, &ctx->m_deletePlayerLock, (QMutex*)nullptr);
multi_lock( {&mctx->m_deletePlayerLock, &ctx->m_deletePlayerLock} );
if (mctx->m_player && ctx->m_player)
{
PIPLocation loc = mctx->m_player->GetNextPIPLocation();
Expand Down Expand Up @@ -6197,7 +6184,7 @@ void TV::PxPSwap(PlayerContext *mctx, PlayerContext *pipctx)

m_lockTimerOn = false;

multi_lock(&mctx->m_deletePlayerLock, &pipctx->m_deletePlayerLock, nullptr);
multi_lock( {&mctx->m_deletePlayerLock, &pipctx->m_deletePlayerLock} );
if (!mctx->m_player || !mctx->m_player->IsPlaying() ||
!pipctx->m_player || !pipctx->m_player->IsPlaying())
{
Expand Down

0 comments on commit d1897ae

Please sign in to comment.