96 lines
3.3 KiB
C++
Executable File
96 lines
3.3 KiB
C++
Executable File
/**
|
|
* Manages central aes data to be sent
|
|
* $Id: handler_oc_situation_data.h 57655 2022-07-20 11:38:28Z karwat $
|
|
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/3dws_devel/Lts/Services/OcSituationServer/handler_oc_situation_data.h $
|
|
* $Author: karwat $
|
|
* Created by Hannes Fritsche, SLTE, 16-08-2022
|
|
*/
|
|
#pragma once
|
|
|
|
#include <QQueue>
|
|
#include "oc_situation.h"
|
|
#include <QObject>
|
|
#include "logger.h"
|
|
#include <QMutex>
|
|
#include <QMutexLocker>
|
|
#include "central_aes_data_builder.h"
|
|
|
|
namespace OcSituationServer
|
|
{
|
|
|
|
class CentralAesDataQueue : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit CentralAesDataQueue(QObject *parent = nullptr);
|
|
|
|
template <typename T>
|
|
void addAesItem(const T &aesItem)
|
|
{
|
|
QMutexLocker locker(&m_accessMutex);
|
|
QByteArray data;
|
|
bool isPrioritized = false; // we prioritize every single fire
|
|
|
|
clearSpecificMessage(aesItem.id(), OcSituation::AddMod);
|
|
|
|
DataBuilder::addCentralAesChangeType(data, OcSituation::AddMod);
|
|
data.append(DataBuilder::getByteStreamAesItem(aesItem, isPrioritized));
|
|
|
|
if (isPrioritized)
|
|
m_internalPrioritizedQueue.enqueue({aesItem.id(), OcSituation::AddMod, data});
|
|
else
|
|
m_internalQueue.enqueue({aesItem.id(), OcSituation::AddMod, data});
|
|
|
|
DEBUG_LOG(m_logger) << "New AesItem added. " << m_internalQueue.size() << " normal, "
|
|
<< m_internalPrioritizedQueue.size() << " prioritized and "
|
|
<< m_internalQueue.size() + m_internalPrioritizedQueue.size() << " messages in total.";
|
|
}
|
|
|
|
void addRemoveMessage(int32_t aesItemId, AreaEffectSimulation::AesType aesType, bool isPrioritized = false);
|
|
void addRemoveMessage(const AreaEffectSimulation::EffectCluster &effectCluster);
|
|
void addRemoveMessage(const AreaEffectSimulation::NContamination &nContamination);
|
|
void addRemoveMessage(const AreaEffectSimulation::BCContamination &bCContamination);
|
|
void addRemoveMessage(const AreaEffectSimulation::ExplosionArea &explosionArea);
|
|
void addRemoveMessage(const AreaEffectSimulation::ExplosionSingle &explosionSingle);
|
|
void addRemoveMessage(const AreaEffectSimulation::MineArea &mineArea);
|
|
void addRemoveMessage(const AreaEffectSimulation::FunctionalArea &functionalArea);
|
|
void addRemoveMessage(const AreaEffectSimulation::BoobyTrap &boobyTrap);
|
|
void addRemoveMessage(const AreaEffectSimulation::OffRouteMine &offRouteMine);
|
|
void addRemoveMessage(const AreaEffectSimulation::ExplosionCluster &explosionCluster);
|
|
|
|
QByteArray getSendingData(qint32 size);
|
|
|
|
bool hasMessages() const;
|
|
|
|
void clear();
|
|
private:
|
|
void clearSpecificMessage(int32_t aesItemId, OcSituation::CentralAesChangeType changeType);
|
|
|
|
struct SendingMessage
|
|
{
|
|
int32_t aesItemId;
|
|
OcSituation::CentralAesChangeType changeType;
|
|
QByteArray data;
|
|
|
|
SendingMessage()
|
|
: aesItemId(0)
|
|
, changeType(OcSituation::AddMod)
|
|
, data(QByteArray())
|
|
{}
|
|
|
|
SendingMessage(int32_t aesItemId, OcSituation::CentralAesChangeType changeType, const QByteArray &data)
|
|
: aesItemId(aesItemId)
|
|
, changeType(changeType)
|
|
, data(data)
|
|
{}
|
|
};
|
|
|
|
// attributes
|
|
QMutex m_accessMutex;
|
|
QQueue<SendingMessage> m_internalQueue;
|
|
QQueue<SendingMessage> m_internalPrioritizedQueue;
|
|
LOGGER_T &m_logger;
|
|
};
|
|
|
|
} // namespace OcSituationServer
|