// ************************************************************************** // // (C) Copyright 2009 Swiss SIMTEC AG // // ************************************************************************** // // $HeadURL$ // $LastChangedBy$ // $LastChangedDate$ // $LastChangedRevision$ // // Implementation of the Class PrtCnvApplication // ************************************************************************** #pragma once #include #include "AppComponent.hpp" #include "logger.h" #include #include #include #include /** * Here are all project specific classes of protocol-converter implemented. */ namespace PrtCnv { class PrtCnvThreadStarter; /** * The main-application of protocol-converter. It is responsible for starting and * controlling the threads of this application. * * @author alois.wismer * @version 1.0 * @created 23-Jun-2009 17:48:47 */ class PRTCNVLIB_EXPORT PrtCnvApplication : public QObject, public N_AppComponent::AppComponent { Q_OBJECT public: /** * This enum will be used to unique identify the threads * * @author alois.wismer * @version 1.0 * @created 19-Jan-2010 17:09:00 */ enum E_ThreadId { e_Central, e_Radio, e_Db, e_Log, e_Injection, e_RadioTraffic, e_ThreadIdMax }; PrtCnvApplication(); ~PrtCnvApplication(); /** * Starts the main-application */ void startApp(); void shutdownApp(); static void setCleanDb(bool bCleanDb); void setExerciseId(int exerciseId); int exerciseId() const { return m_exerciseId; } void setConfigFile(const QString &configFile); /** * Starts the childs and then the main application */ int32_t start() override; /** * Synchronisation of threads before init(). * * @param a_threadId id of the calling thread */ void waitForInit(E_ThreadId a_threadId); /** * Synchronisation of threads before start(). * * @param a_threadId id of the calling thread */ void waitForStart(E_ThreadId a_threadId); /** * Synchronisation of threads before create(). * * @param a_threadId Id of the calling thread */ void waitForCreate(const E_ThreadId a_threadId); /** * Synchronisation of threads before execution of thread. * * @param a_threadId id of the calling thread */ void waitForExec(E_ThreadId a_threadId); /** * Returns the desired thread-starter * * @param a_threadId Id of the desired thread-started (corresponding thread has * the same id) */ PrtCnvThreadStarter* getThreadStarter(const E_ThreadId a_threadId); /** * @brief Set the database connection parameter when used as library */ void setDatabaseConnectionParams(const QString &driver, const QString &hostName, const QString &database, const QString &schemaName, const QString &userName, const QString &password); QString databaseDriver() const { return m_dbDriver; } QString databaseHostName() const { return m_dbHostName; } QString databaseName() const { return m_dbDatabaseName; } QString databaseSchemaName() const { return m_dbSchemaName; } QString databaseUserName() const { return m_dbUserName; } QString databasePassword() const { return m_dbPassword; } public slots: void logWlsTelegram(const TrainingAreaBase::TetraIcd::TrainingAreaTelegram *tele, bool bIsSend); signals: void textMessageFromPrtCnvToCentral(const QByteArray &ba); void textMessageFromCentralToPrtCnv(const QByteArray &ba); void outgoingBroadcastTelegramsRequest(int equipmentNumber, int broadcastIndex, int resetCounter); void warehouseMessageFromPtrCnv(const QByteArray &jsonData); protected: /** * Creates the childs */ int32_t createApplication(); /** * Returns true when the specified thread is * already constructed */ bool isConstructed(const E_ThreadId a_threadId) const; /** * The specifed thread is now constructed */ void setConstructed(const E_ThreadId a_threadId); /** * Returns true when the specified thread is * already initialized */ bool isInitialized(const E_ThreadId a_threadId) const; /** * The specifed thread is now initialized */ void setInitialized(const E_ThreadId a_threadId); /** * Returns true when the specified thread is * already created */ bool isCreated(const E_ThreadId a_threadId) const; /** * The specifed thread is now created */ void setCreated(const E_ThreadId a_threadId); /** * Returns true when the specified thread is * already started */ bool isStarted(const E_ThreadId a_threadId) const; /** * The specifed thread is now started */ void setStarted(const E_ThreadId a_threadId); protected: /** * Used to get configuration-parameter */ NGL::Settings *m_Config; struct ThreadInfo { PrtCnvThreadStarter *thread = nullptr; bool isConstructed = false; bool isCreated = false; bool isInitialized = false; bool isStarted = false; } m_threadInfo[e_ThreadIdMax]; /** * The name of the config-file */ QString m_ConfigFileName; /** * The exerciseId (or zero if not set) */ int m_exerciseId; /** * Access Mutex */ mutable QMutex m_accessMutex; QString m_dbDriver; QString m_dbHostName; QString m_dbDatabaseName; QString m_dbSchemaName; QString m_dbUserName; QString m_dbPassword; NGL::INGLLogger &m_logger; }; }