/** * Handler for table-io message data request * $Id$ * $HeadURL$ * $Author$ * Created by hjl, SLSE, 2016-10-12 */ #pragma once #include #include "dds_handler.h" #include "logger.h" #include #include #include "main_handler.h" #include #include #include #include // HTTP Request #include #include #include namespace SoundManagement { template void await(const typename QtPrivate::FunctionPointer::Object *sender, Func1 signal) { QEventLoop x; QObject::connect(sender, signal, &x, &QEventLoop::quit); x.exec(); } using DbHandler = NGLDB::DbServiceHandler; inline QPointF geographic2Utm(const Core::GeoPosition2D &geoPos, int *zone = nullptr) { const int zoneToUse = zone ? *zone : -1; auto utm = LtsCoordTrans::UtmCoordinate::fromGeographic(geoPos.lon(), geoPos.lat(), zoneToUse); if (zone) *zone = utm.zone; return {utm.x, utm.y}; } class HandlerSounds final : public QObject , protected Interface::Fts::GetActiveSoundsRequestHandler , protected Interface::Fts::StopAllSoundsRequestHandler , protected Interface::Fts::GetSoundsRequestHandler , protected Interface::Fts::ControlSoundRequestHandler { Q_OBJECT public: explicit HandlerSounds(const std::shared_ptr &ddsHandler, const std::shared_ptr &dbHandler, QObject *parent = nullptr); ~HandlerSounds() = default; bool init(); private Q_SLOTS: void onInstrumentationAssetChanged(const InfrastructureManagement::InstrumentationAsset &data, DataModification modType); void onMountingPointAssetChanged(const InfrastructureManagement::MountingPointAsset &data, DataModification modType); void onSoundStateChanged(const SoundManagement::SoundState &data, DataModification modType); void httpFinished(); void onStopSingleSound(const int egcuId, const SoundManagement::SoundCategory soundCategory, const int soundId); private: // methods QString httpFinishedBlocking(QNetworkReply *reply); void onGetActiveSoundsRequest(const rti::core::SampleIdentity &cookie, const GetActiveSoundsRequest &request) override; void onStopAllSoundsRequest(const rti::core::SampleIdentity &cookie, const StopAllSoundsRequest &request) override; void onGetSoundsRequest(const rti::core::SampleIdentity &cookie, const GetSoundsRequest &request) override; void onControlSoundRequest(const rti::core::SampleIdentity &cookie, const ControlSoundRequest &request) override; void onTimerTimeout(); QString stopAllSounds(const int egcuId); // BLOCKING! void getActiveSounds(); void getActiveSound(const int egcuId); QString playBackgroundSound(const QString &user, const QString &passwd, const QString &host, const QString &category, const int sound, const int volume, const int control); void startRequest(const QUrl &requestedUrl); QString startRequestBlocking(const QUrl &requestedUrl); QString enumToString(const SoundManagement::SoundCategory &category); SoundManagement::SoundCategory stringToEnum(const QString &category); void handleSoundReport(const QString &json, const QString &host); int getAssetId(const QString &hostName); int getDuration(const SoundCategory &category, const int soundId); int getSoundIndex(const SoundCategory &category, const QString &name); private: // attributes struct SoundStr { int index = 0; int soundId = 0; SoundManagement::SoundCategory category = SoundManagement::SoundCategory::Unknown; QString name = QString(); QString displayName = QString(); int duration = 0; bool isRepeatable = false; }; std::shared_ptr m_ddsHandler; ///< Pointer to DDS handler std::shared_ptr m_dbHandler; ///< Pointer to DB handler QHash m_hostnames; // key = assetId, value = hostname QHash m_activeSounds; // key = hostname QNetworkAccessManager m_qnam; QTimer *m_updateActiveSoundsTimer{new QTimer(this)}; bool m_httpRequestAborted{false}; QVector m_soundNames{QVector()}; int m_indexActiveSound{0}; QVector m_soundStates{QVector()}; int m_topicId{0}; QHash m_mountingPointAsset; // Key= structureElementId, value= assetId NGL::INGLLogger &m_logger; }; } // namespace SoundManagement