Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+256
@@ -0,0 +1,256 @@
|
||||
/**
|
||||
* Handler for all exercise objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2015-09-03
|
||||
*/
|
||||
|
||||
#include "handler_video_team.h"
|
||||
#include "object_video_team.h"
|
||||
#include "default_av_menus.h"
|
||||
|
||||
#include "avm_db.h"
|
||||
#include "active_exercises.h"
|
||||
#include "exercise_context.h"
|
||||
|
||||
namespace AudioVideoManagement
|
||||
{
|
||||
|
||||
class HandlerVideoTeam::DeviceConfig
|
||||
{
|
||||
public:
|
||||
DeviceConfig(HandlerVideoTeam *handler, DatabaseInterface *db, LOGGER_T logger)
|
||||
: m_handler(handler)
|
||||
, m_db(db)
|
||||
, m_logger(logger)
|
||||
{
|
||||
Q_ASSERT(handler);
|
||||
Q_ASSERT(db);
|
||||
}
|
||||
|
||||
void create(const VideoTeam &videoTeam)
|
||||
{
|
||||
Q_ASSERT(!m_cache.contains(videoTeam.id()));
|
||||
|
||||
Database::AvmDeviceConfig deviceConfig = toDeviceConfig(videoTeam);
|
||||
|
||||
if (!m_db->insert(deviceConfig))
|
||||
ERROR_LOG(m_logger) << "Error while inserting device config into database";
|
||||
|
||||
m_cache.insert(videoTeam.id(), deviceConfig);
|
||||
emit m_handler->avDbReloadNeeded();
|
||||
}
|
||||
|
||||
void update(const VideoTeam &videoTeam)
|
||||
{
|
||||
Q_ASSERT(m_cache.contains(videoTeam.id()));
|
||||
|
||||
Database::AvmDeviceConfig deviceConfig = toDeviceConfig(videoTeam);
|
||||
|
||||
const Database::AvmDeviceConfig &oldDeviceConfig = m_cache[videoTeam.id()];
|
||||
deviceConfig.id = oldDeviceConfig.id;
|
||||
|
||||
if (!m_db->update(deviceConfig))
|
||||
ERROR_LOG(m_logger) << "Error while updating device config";
|
||||
|
||||
m_cache[videoTeam.id()] = deviceConfig;
|
||||
emit m_handler->avDbReloadNeeded();
|
||||
}
|
||||
|
||||
void createOrUpdate(const VideoTeam &videoTeam)
|
||||
{
|
||||
if (m_cache.contains(videoTeam.id()))
|
||||
update(videoTeam);
|
||||
else
|
||||
create(videoTeam);
|
||||
}
|
||||
|
||||
void remove(int32_t teamId)
|
||||
{
|
||||
auto found = m_cache.find(teamId);
|
||||
Q_ASSERT(found != m_cache.end());
|
||||
|
||||
if (!m_db->removeAvmDeviceConfig(found->id))
|
||||
ERROR_LOG(m_logger) << "Error while removing device config";
|
||||
|
||||
m_cache.erase(found);
|
||||
emit m_handler->avDbReloadNeeded();
|
||||
}
|
||||
|
||||
void tryRemove(int32_t teamId)
|
||||
{
|
||||
if (m_cache.contains(teamId))
|
||||
remove(teamId);
|
||||
}
|
||||
|
||||
private:
|
||||
static Database::AvmDeviceConfig toDeviceConfig(const VideoTeam &videoTeam)
|
||||
{
|
||||
Database::AvmDeviceConfig result;
|
||||
result.context = ExerciseContext(videoTeam.exerciseId()).toString();
|
||||
result.type = QStringLiteral("DEKTEC_VIDEO_CHANNEL");
|
||||
result.name = QString::fromStdString(videoTeam.streamName());
|
||||
result.controller = QStringLiteral("EXCAVS01");
|
||||
result.definition = QStringLiteral("mode=1;ssrc=%1;port=%2;programid=%3;programtimeoffset=%4;recording=ECRS@%5")
|
||||
.arg(videoTeam.ssrc()).arg(videoTeam.vtPort()).arg(videoTeam.programId()).arg(videoTeam.timeOffset()).arg(result.controller);
|
||||
return result;
|
||||
}
|
||||
|
||||
QMap<int32_t, Database::AvmDeviceConfig> m_cache; //!< <VideoTeam::id, Database::DeviceConfig>
|
||||
HandlerVideoTeam *m_handler;
|
||||
DatabaseInterface *m_db;
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
HandlerVideoTeam::HandlerVideoTeam(Interface::Dts *dts, Interface::Fts *fts, DatabaseInterface *db, ActiveExercises *activeExercises)
|
||||
: Interface::Fts::VideoTeamModifyRequestHandler(nullptr)
|
||||
, m_dts(dts)
|
||||
, m_fts(fts)
|
||||
, m_db(db)
|
||||
, m_activeExercises(activeExercises)
|
||||
, m_logger(getLogger("HandlerVideoTeam"))
|
||||
, m_deviceConfig(new DeviceConfig(this, db, m_logger))
|
||||
{
|
||||
Q_ASSERT(dts);
|
||||
Q_ASSERT(fts);
|
||||
Q_ASSERT(db);
|
||||
Q_ASSERT(activeExercises);
|
||||
m_fts->setVideoTeamModifyRequestHandler(this);
|
||||
|
||||
connect(activeExercises, &ActiveExercises::contextActivated, this, &HandlerVideoTeam::onContextActivated);
|
||||
connect(activeExercises, &ActiveExercises::contextDeactivated, this, &HandlerVideoTeam::onContextDeactivated);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
HandlerVideoTeam::~HandlerVideoTeam()
|
||||
{
|
||||
m_fts->setVideoTeamModifyRequestHandler(nullptr);
|
||||
qDeleteAll(m_videoTeamObjMap);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool HandlerVideoTeam::init()
|
||||
{
|
||||
QVector<Database::AvmVideoTeam> dataVec;
|
||||
// read all VideoTeam Data from database
|
||||
if (!m_db->select(dataVec))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error reading data from database!";
|
||||
return false;
|
||||
}
|
||||
|
||||
// create objects
|
||||
for (const Database::AvmVideoTeam &data : qAsConst(dataVec))
|
||||
{
|
||||
VideoTeam ddsData = ObjectVideoTeam::toDdsData(data);
|
||||
ObjectVideoTeam *ifs(new ObjectVideoTeam(m_dts, m_db));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(ddsData);
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
return false;
|
||||
}
|
||||
m_videoTeamObjMap.insert(ifs->getId(), ifs);
|
||||
|
||||
if (needDeviceConfig(ddsData))
|
||||
m_deviceConfig->create(ddsData);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "m_VideoTeamObjMap.size() = " << m_videoTeamObjMap.size();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QMap<int, VideoTeam> HandlerVideoTeam::videoTeams() const
|
||||
{
|
||||
QMap<int, VideoTeam> ret;
|
||||
for (const auto &videoTeam : qAsConst(m_videoTeamObjMap))
|
||||
ret.insert(videoTeam->getId(), videoTeam->getData());
|
||||
return ret;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void HandlerVideoTeam::onVideoTeamModifyRequest(const rti::core::SampleIdentity &cookie,
|
||||
const VideoTeamModifyRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onVideoTeamModifyRequest: " << request;
|
||||
auto ret = request.id() > 0 ? videoTeamModifyRequest(request) : videoTeamCreateRequest(request);
|
||||
if (ret.error())
|
||||
WARNING_LOG(m_logger) << ret();
|
||||
m_fts->videoTeamModifyReply(cookie, ret);
|
||||
}
|
||||
|
||||
bool HandlerVideoTeam::needDeviceConfig(const VideoTeam &videoTeam) const
|
||||
{
|
||||
if (videoTeam.exerciseId() == 0)
|
||||
return false;
|
||||
return m_activeExercises->isActive(ExerciseContext(videoTeam.exerciseId()));
|
||||
}
|
||||
|
||||
void HandlerVideoTeam::onContextActivated(const ExerciseContext &context)
|
||||
{
|
||||
for (const auto *ifs : qAsConst(m_videoTeamObjMap))
|
||||
{
|
||||
VideoTeam ddsData = ifs->getData();
|
||||
if (ddsData.exerciseId() == context.id())
|
||||
m_deviceConfig->create(ddsData);
|
||||
}
|
||||
}
|
||||
|
||||
void HandlerVideoTeam::onContextDeactivated(const ExerciseContext &context)
|
||||
{
|
||||
for (ObjectVideoTeam *ifs : qAsConst(m_videoTeamObjMap))
|
||||
{
|
||||
if (ifs->exerciseId() == context.id())
|
||||
{
|
||||
VideoTeam ddsData = ifs->getData();
|
||||
ddsData.exerciseId(0);
|
||||
ddsData.streamName(std::string());
|
||||
ifs->updateObject(ddsData);
|
||||
m_deviceConfig->remove(ddsData.id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static VideoTeam convert(const VideoTeamModifyRequest &request, const VideoTeam &oldData)
|
||||
{
|
||||
Q_ASSERT(request.id() == oldData.id());
|
||||
|
||||
VideoTeam newData(oldData);
|
||||
newData.streamName(request.streamName());
|
||||
newData.exerciseId(request.exerciseId());
|
||||
return newData;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject HandlerVideoTeam::videoTeamModifyRequest(const VideoTeamModifyRequest &request)
|
||||
{
|
||||
ObjectVideoTeam *ifs = m_videoTeamObjMap.value(request.id());
|
||||
if (ifs == nullptr)
|
||||
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Video Team with id %1 not found")).arg(request.id());
|
||||
DEBUG_LOG(m_logger) << "on Modify Request" << request.streamName() << " ID: " << request.name() << " exId " << request.exerciseId();
|
||||
|
||||
VideoTeam ddsData = convert(request, ifs->getData());
|
||||
if (needDeviceConfig(ddsData))
|
||||
m_deviceConfig->createOrUpdate(ddsData);
|
||||
else
|
||||
m_deviceConfig->tryRemove(ddsData.id());
|
||||
|
||||
Core::FunctionReplyObject ret = ifs->updateObject(ddsData);
|
||||
emit mvsChanged();
|
||||
return ret;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject HandlerVideoTeam::videoTeamCreateRequest(const VideoTeamModifyRequest &request)
|
||||
{
|
||||
Q_UNUSED(request);
|
||||
return Core::FunctionReplyObject(tr_lts("dds", "A Video Team cannot be created"));
|
||||
}
|
||||
|
||||
} // Namespace
|
||||
Reference in new issue
Block a user