71 lines
1.5 KiB
C++
Executable File
71 lines
1.5 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* SimpleCommand
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Fröbel, SLSE, 2017-07-11
|
|
*/
|
|
|
|
#include "simple_command.h"
|
|
#include "iava_comm.h"
|
|
#include "iava_command_done_observer.h"
|
|
#include "ivd_comm.h"
|
|
#include "ivd_command_done_observer.h"
|
|
#include <QtGlobal>
|
|
|
|
|
|
namespace AudioVideoManagement
|
|
{
|
|
|
|
namespace detail
|
|
{
|
|
|
|
template<class Comm, class DoneObserver>
|
|
SimpleCommand<Comm, DoneObserver>::SimpleCommand(const QString &commandDesc, Comm *comm, DoneObserver *observer, std::function<void (Comm *)> commandInvoker, int okCount)
|
|
: m_commandInvoker(std::move(commandInvoker))
|
|
, m_expectedOkCount(okCount)
|
|
, m_comm(comm)
|
|
, m_observer(observer)
|
|
, m_commandDesc(commandDesc)
|
|
{
|
|
Q_ASSERT(comm);
|
|
Q_ASSERT(observer);
|
|
Q_ASSERT(okCount > 0);
|
|
}
|
|
|
|
template<class Comm, class DoneObserver>
|
|
void SimpleCommand<Comm, DoneObserver>::send()
|
|
{
|
|
connect(m_comm, &Comm::ok, this, &SimpleCommand::onOk);
|
|
m_commandInvoker(m_comm);
|
|
}
|
|
|
|
template<class Comm, class DoneObserver>
|
|
void SimpleCommand<Comm, DoneObserver>::onOk()
|
|
{
|
|
Q_ASSERT(m_okCount < m_expectedOkCount);
|
|
++m_okCount;
|
|
if (m_okCount == m_expectedOkCount)
|
|
done();
|
|
}
|
|
|
|
template<class Comm, class DoneObserver>
|
|
void SimpleCommand<Comm, DoneObserver>::done()
|
|
{
|
|
m_comm->disconnect(this);
|
|
m_observer->done(this);
|
|
}
|
|
|
|
/**
|
|
* Explicit template instantiations.
|
|
*/
|
|
///@{
|
|
template class SimpleCommand<IAvaComm, IAvaCommandDoneObserver>;
|
|
template class SimpleCommand<IVdComm, IVdCommandDoneObserver>;
|
|
///@}
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace AudioVideoManagement
|