/** * @RDE_HEADER@ * Xml Reader for Effect Configuration * $Id$ * $HeadURL$ * $Author$ * Created by Gerlinde Rudolphus, SLTE, 2021-06-02 */ #pragma once //#include //#include #include #include #include #include namespace BuildingControlUnit { class HandelEffect; enum EffectType { // Keep in sync with EffectType from bcu_types.h ET_Unset = 0, ET_Relay = 1, // EGCU ET_BackgroundSound = 2, // EGCU ET_BsmFlash = 3, // BSM }; enum EffectOverride { EO_Auto = -1, EO_Off = 0, EO_On = 1, }; enum ActionType { AT_Off = 0, AT_On = 1, AT_Infinite = 2, AT_Flash = 3 }; enum ActionClass { AC_Unset, AC_Standard, AC_Repeat, AC_Pause, AC_Bsm }; enum Category { CT_Default = 0, CT_BGS_Bahnhof = 1, CT_BGS_Personen = 2, CT_BGS_Sonstige = 3, CT_BGS_Stadt = 4, CT_BGS_Testsounds = 5, CT_BGS_Aircrafts = 6, CT_BGS_Battlefields = 7, CT_BGS_Boats = 8, CT_BGS_Explosions = 9, CT_BGS_Helicopter = 10, CT_BGS_Motors_and_urban_traffic = 11, CT_BGS_InsideBuildings = 12, CT_BGS_Vehicles = 13 // CT_RL_Testkategorie = 8 geht auch (RL=Relay): Dann kann man beide Namen je nach EffectType verwenden! }; class Action { public: Action(ActionClass ac = AC_Unset) : aclass(ac) {} ActionClass aclass = AC_Unset; ActionType atype = AT_Off; QUrl url; QString comment; }; class RepeatAction : public Action { public: RepeatAction() : Action(AC_Repeat) {} // -1 => Infinite. So we can skip on (count == 0) in HandelEffect. int count = -1; QVector actions; }; class PauseAction : public Action { public: PauseAction() : Action(AC_Pause) {} int pause = 0; }; class BsmAction : public Action { public: bool isNull() const { return (count == 0 && pause == 0 && pulses == 0); }// Should be enough... int count = 0; int pause = 0; int choplength = 0; int pulses = 0; int pulseduration = 0; BsmAction() : Action(AC_Bsm) {} }; class Range { public: inline bool fits(int value) const { return (min <= value && value <= max); } int min = 0; int max = 100; bool restartOnChange = false; QVector actions; }; class Effect { public: // QVector getActionsByRange(int damagePercent) const; Range* getRangeByDamagePercent(int damagePercent) const; EffectType effectType = ET_Unset; Category category = CT_Default; int id = 0; QString name; QVector ranges; HandelEffect *effectHandler = nullptr; EffectOverride override = EO_Auto; const QVector constRanges() const { return ranges; } }; struct XmlContents { QVector effects; int hitSoundVolume = 50; int bgSoundVolume = 50; QString username; QString password; int port = 80; int updateRelayState = 1000; const QVector constEffects() const { return effects; } QString toString() const { QString str(QStringLiteral("User: %1, Password: %2, Port: %3, BGSound Vol: %4, HitSound Vol: %5, No of Effects: %6")); return str.arg(username, password).arg(port).arg(bgSoundVolume).arg(hitSoundVolume).arg(effects.count()); } }; class XmlReader : public QObject { Q_OBJECT public: explicit XmlReader(QObject *parent = nullptr); ~XmlReader() = default; static QUrl createPreparedUrl(const XmlContents &contents, const QString &hostname = QString()); bool init(const QString &effectConfigFile); XmlContents contents() const { return m_contents; } private: void createHttpRequests(); static QString categoryName(Category c); Effect *parseEffect(QXmlStreamReader &xml); Range *parseRange(QXmlStreamReader &xml); Action *parseAction(QXmlStreamReader &xml); PauseAction *parsePauseAction(QXmlStreamReader &xml); RepeatAction *parseRepeatAction(QXmlStreamReader &xml); BsmAction* parseBsmAction(QXmlStreamReader &xml); Action *parseStandardAction(QXmlStreamReader &xml); // Can be BsmAction or Action alone void generateUrls(const Effect *e, const QVector &actions); void generateUrl(const Effect *e, Action *a); XmlContents m_contents; //BuildingControlUnit::LOGGER_T m_logger; NGL::INGLLogger &m_logger; }; } // BuildingControlUnit