Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AvmExerciseContext
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLSE, 2018-07-30
|
||||
*/
|
||||
|
||||
#include "avm_exercise_context.h"
|
||||
#include <AudioVideoManagement/stream_name_mapping.h>
|
||||
#include <AudioVideoManagement/avm_dtc.h>
|
||||
#include <AudioVideoManagement/avm_ftc.h>
|
||||
#include <ExerciseManagement/exm_dtc.h>
|
||||
#include <OperatorManagement/opm_dtc.h>
|
||||
#include <InfrastructureManagement/ism_dtc.h>
|
||||
#include <LtsSession/lts_session_data_dds.h>
|
||||
#include <ConnectDialog/connect_dialog_nt.h>
|
||||
#include <QObject>
|
||||
#include <QtGlobal>
|
||||
#include <utility>
|
||||
|
||||
namespace AudioVideoManagement
|
||||
{
|
||||
|
||||
/**
|
||||
* Small composite that just holds all entities bound to the Exercise context.
|
||||
*/
|
||||
struct AvmExerciseContextManager::ExerciseContext
|
||||
{
|
||||
explicit ExerciseContext(LtsSession::LtsSessionDataDds *session)
|
||||
{
|
||||
static const int TIMEOUT_MS = 1000;
|
||||
|
||||
Q_ASSERT(session);
|
||||
session->createTopicClient(dtc, ftc);
|
||||
opmDtc = OperatorManagement::Interface::Dtc::create(session->ddsConnectorGlobal());
|
||||
exmDtc = ExerciseManagement::Interface::Dtc::create(session->ddsConnectorGlobal());
|
||||
ismDtc = InfrastructureManagement::Interface::Dtc::create(session->ddsConnectorGlobal());
|
||||
if (session->exerciseId() > 0)
|
||||
streamNameMapping.reset(StreamNameMapping::create(dtc.get()));
|
||||
|
||||
opmDtc->enableUser();
|
||||
opmDtc->waitForHistoricalDataUser(TIMEOUT_MS); // TODO: FIXME: solange man hier keinen ConnectingDialogNT benutzen kann, kein Assert
|
||||
|
||||
exmDtc->enableExercise();
|
||||
exmDtc->waitForHistoricalDataExercise(TIMEOUT_MS);
|
||||
|
||||
ismDtc->enableMountingPointAsset();
|
||||
ismDtc->waitForHistoricalDataMountingPointAsset(TIMEOUT_MS);
|
||||
|
||||
dtc->enableCnrConfig();
|
||||
dtc->enableTvcConfig();
|
||||
dtc->enableCnrTvcProfile();
|
||||
dtc->enableMenuStruct();
|
||||
dtc->waitForHistoricalDataCnrConfig(TIMEOUT_MS);
|
||||
dtc->waitForHistoricalDataTvcConfig(TIMEOUT_MS);
|
||||
dtc->waitForHistoricalDataCnrTvcProfile(TIMEOUT_MS);
|
||||
dtc->waitForHistoricalDataMenuStruct(TIMEOUT_MS);
|
||||
}
|
||||
|
||||
std::shared_ptr<Interface::Dtc> dtc;
|
||||
std::shared_ptr<Interface::Ftc> ftc;
|
||||
std::shared_ptr<OperatorManagement::Interface::Dtc> opmDtc;
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> exmDtc;
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Dtc> ismDtc;
|
||||
std::unique_ptr<StreamNameMapping> streamNameMapping;
|
||||
};
|
||||
|
||||
|
||||
AvmExerciseContextManager::RefCountedContext::RefCountedContext(std::unique_ptr<AvmExerciseContextManager::ExerciseContext> &&context)
|
||||
: context(std::move(context))
|
||||
{}
|
||||
|
||||
AvmExerciseContextManager::RefCountedContext::RefCountedContext(AvmExerciseContextManager::RefCountedContext &&) noexcept = default;
|
||||
|
||||
AvmExerciseContextManager::RefCountedContext::~RefCountedContext() = default;
|
||||
|
||||
|
||||
AvmExerciseContextManager::~AvmExerciseContextManager()
|
||||
{
|
||||
// cfroebel 2018-07-31: Workaround for Bug REGG-4775
|
||||
// All contexts should have been destroyed by now.
|
||||
// But due to the bug there is one last context for Ex 0.
|
||||
|
||||
// Q_ASSERT(m_activeContexts.empty()); TODO: reactivate after fix
|
||||
if (m_activeContexts.empty())
|
||||
return;
|
||||
|
||||
Q_ASSERT(m_activeContexts.size() == 1);
|
||||
//Q_ASSERT(m_activeContexts.begin()->first == 0); TODO: reactivate after fix
|
||||
}
|
||||
|
||||
AvmExerciseContextManager::ExerciseContext *AvmExerciseContextManager::acquire(int exerciseId, LtsSession::LtsSessionDataDds *session)
|
||||
{
|
||||
auto found = m_activeContexts.find(exerciseId);
|
||||
if (found != m_activeContexts.end())
|
||||
{
|
||||
++found->second.refCount;
|
||||
return found->second.context.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<ExerciseContext> composite(new ExerciseContext(session));
|
||||
auto insertResult = m_activeContexts.insert(std::make_pair(exerciseId, RefCountedContext(std::move(composite))));
|
||||
Q_ASSERT(insertResult.second);
|
||||
return insertResult.first->second.context.get();
|
||||
}
|
||||
|
||||
void AvmExerciseContextManager::release(int exerciseId, AvmExerciseContextManager::ExerciseContext *composite)
|
||||
{
|
||||
auto found = m_activeContexts.find(exerciseId);
|
||||
Q_ASSERT(found != m_activeContexts.end());
|
||||
Q_ASSERT(found->second.context.get() == composite);
|
||||
|
||||
--found->second.refCount;
|
||||
if (found->second.refCount == 0)
|
||||
m_activeContexts.erase(found);
|
||||
}
|
||||
|
||||
|
||||
AvmExerciseContextHandle::AvmExerciseContextHandle() = default;
|
||||
|
||||
AvmExerciseContextHandle::AvmExerciseContextHandle(AvmExerciseContextManager *context, int exerciseId, LtsSession::LtsSessionDataDds *session)
|
||||
: m_context(context->acquire(exerciseId, session), [exerciseId, context](AvmExerciseContextManager::ExerciseContext *composite) { context->release(exerciseId, composite); })
|
||||
{
|
||||
Q_ASSERT(context);
|
||||
Q_ASSERT(m_context);
|
||||
}
|
||||
|
||||
StreamNameMapping *AvmExerciseContextHandle::streamNameMapping() const
|
||||
{
|
||||
Q_ASSERT(m_context);
|
||||
Q_ASSERT(m_context->streamNameMapping);
|
||||
return m_context->streamNameMapping.get();
|
||||
}
|
||||
|
||||
const std::shared_ptr<Interface::Dtc> &AvmExerciseContextHandle::dtc() const
|
||||
{
|
||||
Q_ASSERT(m_context);
|
||||
return m_context->dtc;
|
||||
}
|
||||
|
||||
const std::shared_ptr<Interface::Ftc> &AvmExerciseContextHandle::ftc() const
|
||||
{
|
||||
Q_ASSERT(m_context);
|
||||
return m_context->ftc;
|
||||
}
|
||||
|
||||
OperatorManagement::Interface::Dtc *AvmExerciseContextHandle::opmDtc() const
|
||||
{
|
||||
Q_ASSERT(m_context);
|
||||
return m_context->opmDtc.get();
|
||||
}
|
||||
|
||||
ExerciseManagement::Interface::Dtc *AvmExerciseContextHandle::exmDtc() const
|
||||
{
|
||||
Q_ASSERT(m_context);
|
||||
return m_context->exmDtc.get();
|
||||
}
|
||||
|
||||
InfrastructureManagement::Interface::Dtc *AvmExerciseContextHandle::ismDtc() const
|
||||
{
|
||||
Q_ASSERT(m_context);
|
||||
return m_context->ismDtc.get();
|
||||
}
|
||||
|
||||
} // namespace AudioVideoManagement
|
||||
Reference in new issue
Block a user