Files
qt5-legatus-legacy/Lts/Services/AudioVideoManagement/audio_video_handler_impl.h
T
2026-08-13 18:33:10 +02:00

172 lines
4.5 KiB
C++
Executable File

/**
* @RDE_HEADER@
* AudioVideoHandlerImpl
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Fröbel, NLSE, 2018-01-09
*/
#pragma once
#include "exercise_context.h"
#include "logger.h"
#include "avm_export.h"
#include <AudioVideoManagement/avm_db_structs.h>
#include <boost/optional.hpp>
#include <QObject>
#include <string>
#include <map>
#include <cstdint>
namespace LtsUtils
{
class JsonObject;
}
namespace AudioVideoManagement
{
class Asset;
class MountingPoint;
class Exercise;
class Stream;
/**
* Just stores the associated StreamType with the AvmDeviceConfig.
*/
struct AVM_COMMON_EXPORT AvmDeviceConfigEx : public Database::AvmDeviceConfig
{
AvmDeviceConfigEx(const AvmDeviceConfig &dc, StreamType streamType_);
StreamType streamType;
};
/**
* For each device there exists at least one entry (aka stream) in the device_config.
* Cameras with microphone or speaker also have an additional audio stream.
* If both entries are set they have the same stream name.
* If there are two streams -- video and audio --, the video stream is the first stream.
*/
struct AVM_COMMON_EXPORT Streams
{
Streams(Asset *asset_, const AvmDeviceConfigEx &first_);
Streams(Asset *asset_, const AvmDeviceConfigEx &first_, const AvmDeviceConfigEx &second_);
Asset *asset; //!< never nullptr and always mounted
AvmDeviceConfigEx first;
boost::optional<AvmDeviceConfigEx> second;
int32_t assetId() const;
int32_t mountingPointId() const;
};
/**
* The implementation of AudioVideoHandler.
* The implementation itself does not have any direct dependency to the database or DDS.
* Instead, access to database and DDS is done via interfaces which can be stubbed out
* in UnitTests.
*
* @see AudioVideoHandler
* @author Christian Fröbel
*/
class AVM_COMMON_EXPORT AudioVideoHandlerImpl : public QObject
{
Q_OBJECT
public:
class IDbProxy;
class IDtsProxy;
AudioVideoHandlerImpl(Exercise *exercise, IDbProxy *dbProxy, IDtsProxy *dtsProxy);
static QString internalStreamName(int32_t mountingPointId);
/**
* @name Helper functions.
* These are only public in order to test them in UnitTests.
* Do not use directly.
*/
///@{
static QString deviceDefinitionAnnouncementUnit(const std::string &hostname, const LtsUtils::JsonObject &assetProperties, const LtsUtils::JsonObject &mountingPointProperties);
static QString deviceDefinitionCameraVideo(const std::string &hostname, const LtsUtils::JsonObject &assetProperties, const LtsUtils::JsonObject &mountingPointProperties);
static QString deviceDefinitionCameraAudio(const std::string &hostname, const LtsUtils::JsonObject &assetProperties, const LtsUtils::JsonObject &mountingPointProperties);
///@}
signals:
void avDbReloadNeeded();
public slots:
/**
* @name Public as the connection will be made by AudioVideoHandler, not by ourselves.
* This way we don't have the direct dependency to ExerciseHandler.
* Also, these slots need to by called directly in UnitTests.
*/
///@{
void onContextActivated();
void onContextDeactivated();
///@}
private slots:
void onAssetAssigned(Asset *asset);
void onAssetUnassigned(Asset *asset);
void onAssetChanged(Asset *asset);
void onMountingPointChanged(MountingPoint *mountingPoint);
private:
void addDeviceConfigToDb(Asset *asset_);
void updateDeviceConfig(Asset *asset);
void removeDeviceConfigFromDb(Asset *asset);
void ddsPublish(const Streams &streams);
void ddsUpdate(const Streams &oldStreams, const Streams &newStreams);
void ddsRemove(const Streams &streams);
Streams createStreams(Asset *asset_);
ExerciseContext m_exContext;
Exercise *m_exercise;
bool m_isActive{false};
IDbProxy *m_dbProxy;
IDtsProxy *m_dtsProxy;
LOGGER_T m_logger;
};
/**
* Small interface used by AudioVideoHandlerImpl in order to access the database.
*/
class AudioVideoHandlerImpl::IDbProxy
{
public:
using AssetId = int;
virtual ~IDbProxy() = default;
virtual const Streams &findStreams(AssetId id) const = 0;
virtual const Streams &findStreams(Asset *asset) = 0;
virtual void insert(Streams &streams) = 0;
virtual void update(Streams &newStreams) = 0;
virtual void remove(Asset *asset) = 0;
};
/**
* Small interface used by AudioVideoHandlerImpl in order to access the DDS.
*/
class AudioVideoHandlerImpl::IDtsProxy
{
public:
virtual ~IDtsProxy() = default;
virtual void publish(const Stream &stream) = 0;
virtual void remove(uint64_t streamId) = 0;
};
} // namespace AudioVideoManagement