Add first version which at least complies.
This commit is contained in:
		
							
								
								
									
										22
									
								
								plugins/ATBAPPplugin.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								plugins/ATBAPPplugin.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#ifndef ATBAPPPLUGIN_H
 | 
			
		||||
#define ATBAPPPLUGIN_H
 | 
			
		||||
 | 
			
		||||
/***********************************************************
 | 
			
		||||
 * a simple class with only one method for plugin info
 | 
			
		||||
 */
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
class ATBAPPplugin
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    virtual const QString & getPluginInfo() = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Q_DECLARE_INTERFACE(ATBAPPplugin,
 | 
			
		||||
                    "eu.atb.ptu.plugin.ATBAPPplugin/0.9")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // ATBAPPPLUGIN_H
 | 
			
		||||
							
								
								
									
										147
									
								
								plugins/CC/CCDummy.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										147
									
								
								plugins/CC/CCDummy.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,147 @@
 | 
			
		||||
#include "CCDummy.h"
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
using namespace nsCCInterface;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const std::string CCInterfacePluginInfoString = R"(
 | 
			
		||||
{
 | 
			
		||||
    "PluginName": "CCDummy",
 | 
			
		||||
    "Version": "1.0",
 | 
			
		||||
    "git-describe": "",
 | 
			
		||||
}
 | 
			
		||||
)";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CCDummy::CCDummy(QObject *parent) :
 | 
			
		||||
    QObject(parent),
 | 
			
		||||
    errorCode(1),
 | 
			
		||||
    errorDescription(""),
 | 
			
		||||
    pluginState(PLUGIN_STATE::NOT_INITIALIZED)
 | 
			
		||||
{
 | 
			
		||||
    this->pluginInfo = QString::fromUtf8(CCInterfacePluginInfoString.c_str());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CCDummy::~CCDummy()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PLUGIN_STATE CCDummy::initCCInterfacePlugin(QObject *healthEventReceiver, const QSettings & settings)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(healthEventReceiver)
 | 
			
		||||
 | 
			
		||||
    qDebug() << "called CCDummy::initCalculatePricePlugin()";
 | 
			
		||||
    qDebug() << "   pluginName from setting is: " << settings.value("PLUGINS/CCPlugin", "").toString();
 | 
			
		||||
 | 
			
		||||
    this->pluginState = PLUGIN_STATE::INITIALIZED;
 | 
			
		||||
 | 
			
		||||
    return this->pluginState;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestReset()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestStartTransaction(quint32 amount)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(amount)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestCancelTransaction()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestRevertTransaction()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestConfirmTransaction()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestDayClose()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestCardInfo()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestPreAuthTransaction(quint32 amount)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(amount);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestCancelPreAuthTransaction(QString & receiptNumber)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(receiptNumber);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CCDummy::requestBookTotalTransaction(quint32 amount, QString & receiptNumber)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(amount)
 | 
			
		||||
    Q_UNUSED(receiptNumber)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CCDummy::wakeupCC()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CCDummy::sleepCC()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/************************************************************************************************
 | 
			
		||||
 * Mandatory plugin methods
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PLUGIN_STATE CCDummy::getState()
 | 
			
		||||
{
 | 
			
		||||
    return this->pluginState;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
quint32 CCDummy::getLastError()
 | 
			
		||||
{
 | 
			
		||||
    return this->errorCode;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const QString & CCDummy::getLastErrorDescription()
 | 
			
		||||
{
 | 
			
		||||
    return this->errorDescription;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const QString & CCDummy::getPluginInfo()
 | 
			
		||||
{
 | 
			
		||||
    return pluginInfo;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										68
									
								
								plugins/CC/CCDummy.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								plugins/CC/CCDummy.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,68 @@
 | 
			
		||||
#ifndef CCDUMMY_H
 | 
			
		||||
#define CCDUMMY_H
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include "CCInterface.h"
 | 
			
		||||
#include "ATBAPPplugin.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CCDummy : public QObject,
 | 
			
		||||
        public CCInterface
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    Q_INTERFACES(ATBAPPplugin)
 | 
			
		||||
    Q_INTERFACES(CCInterface)
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    CCDummy(QObject *parent = 0);
 | 
			
		||||
    ~CCDummy();
 | 
			
		||||
 | 
			
		||||
    // interface:
 | 
			
		||||
    nsCCInterface::PLUGIN_STATE initCCInterfacePlugin(QObject *healthEventReceiver, const QSettings & settings);
 | 
			
		||||
 | 
			
		||||
    nsCCInterface::PLUGIN_STATE getState();
 | 
			
		||||
    quint32 getLastError();
 | 
			
		||||
    const QString & getLastErrorDescription();
 | 
			
		||||
 | 
			
		||||
    // return a plugin description in JSON or XML
 | 
			
		||||
    const QString & getPluginInfo();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void requestReset();
 | 
			
		||||
    void requestStartTransaction(quint32 amount);
 | 
			
		||||
    void requestCancelTransaction();
 | 
			
		||||
    void requestRevertTransaction();
 | 
			
		||||
    void requestConfirmTransaction();
 | 
			
		||||
    void requestDayClose();
 | 
			
		||||
    void requestCardInfo();
 | 
			
		||||
    void requestPreAuthTransaction(quint32 amount);
 | 
			
		||||
    void requestCancelPreAuthTransaction(QString & receiptNumber);
 | 
			
		||||
    void requestBookTotalTransaction(quint32 amount, QString & receiptNumber);
 | 
			
		||||
 | 
			
		||||
    void wakeupCC();
 | 
			
		||||
    void sleepCC();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void sendStartTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
    void sendCancelTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
    void sendRevertTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
    void sendConfirmTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
    void sendDayCloseResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
    void sendCardInfoResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
    void sendPreAuthTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
    void sendCancelPreAuthTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
    void sendBookTotalTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
   quint32 errorCode;
 | 
			
		||||
   QString errorCodeString;
 | 
			
		||||
   QString errorDescription;
 | 
			
		||||
   QString pluginInfo;
 | 
			
		||||
 | 
			
		||||
   nsCCInterface::PLUGIN_STATE pluginState;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // CCDUMMY_H
 | 
			
		||||
							
								
								
									
										86
									
								
								plugins/CC/CCInterface.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								plugins/CC/CCInterface.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,86 @@
 | 
			
		||||
#ifndef CCINTERFACE_H
 | 
			
		||||
#define CCINTERFACE_H
 | 
			
		||||
 | 
			
		||||
#include <QtPlugin>
 | 
			
		||||
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
#include "ATBAPPplugin.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace nsCCInterface {
 | 
			
		||||
    enum class PLUGIN_STATE : quint8;
 | 
			
		||||
    enum class RESULT_STATE : quint8;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CCInterface : public ATBAPPplugin
 | 
			
		||||
{
 | 
			
		||||
    Q_INTERFACES(ATBAPPplugin)
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    virtual ~CCInterface() {}
 | 
			
		||||
 | 
			
		||||
    virtual nsCCInterface::PLUGIN_STATE initCCInterfacePlugin(QObject *healthEventReceiver, const QSettings & settings) = 0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    virtual nsCCInterface::PLUGIN_STATE getState() = 0;
 | 
			
		||||
    virtual quint32 getLastError() = 0;
 | 
			
		||||
    virtual const QString & getLastErrorDescription() = 0;
 | 
			
		||||
 | 
			
		||||
    // return a plugin description in JSON or XML
 | 
			
		||||
    // -> ATBAPPplugin::getPluginInfo()
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    virtual void requestReset() = 0;
 | 
			
		||||
    virtual void requestStartTransaction(quint32 amount) = 0;
 | 
			
		||||
    virtual void requestCancelTransaction() = 0;
 | 
			
		||||
    virtual void requestRevertTransaction() = 0;
 | 
			
		||||
    virtual void requestConfirmTransaction() = 0;
 | 
			
		||||
    virtual void requestDayClose() = 0;
 | 
			
		||||
    virtual void requestCardInfo() = 0;
 | 
			
		||||
    virtual void requestPreAuthTransaction(quint32 amount) = 0;
 | 
			
		||||
    virtual void requestCancelPreAuthTransaction(QString & receiptNumber) = 0;
 | 
			
		||||
    virtual void requestBookTotalTransaction(quint32 amount, QString & receiptNumber) = 0;
 | 
			
		||||
    virtual void wakeupCC() = 0;
 | 
			
		||||
    virtual void sleepCC() = 0;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    virtual void sendStartTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
    virtual void sendCancelTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
    virtual void sendRevertTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
    virtual void sendConfirmTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
    virtual void sendDayCloseResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
    virtual void sendCardInfoResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
    virtual void sendPreAuthTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
    virtual void sendCancelPreAuthTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
    virtual void sendBookTotalTransactionResult(nsCCInterface::RESULT_STATE resultState, QString & result) = 0;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Q_DECLARE_INTERFACE(CCInterface,
 | 
			
		||||
                    "eu.atb.ptu.plugin.CCInterface/2.9.1")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace nsCCInterface {
 | 
			
		||||
 | 
			
		||||
    enum class PLUGIN_STATE : quint8 {
 | 
			
		||||
        NOT_INITIALIZED = 0,
 | 
			
		||||
        INITIALIZED = 1
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    enum class RESULT_STATE : quint8 {
 | 
			
		||||
        SUCCESS = 1,
 | 
			
		||||
        ERROR_BACKEND = 2,
 | 
			
		||||
        ERROR_NETWORK = 3,
 | 
			
		||||
        ERROR_TIMEOUT = 4,
 | 
			
		||||
        ERROR_PROCESS = 5,
 | 
			
		||||
        ERROR_BUSY    = 6,
 | 
			
		||||
        ERROR_STATE   = 7,
 | 
			
		||||
        INFO = 8
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // CCINTERFACE_H
 | 
			
		||||
							
								
								
									
										215
									
								
								plugins/CalculatePrice/CalculatePriceDefault.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										215
									
								
								plugins/CalculatePrice/CalculatePriceDefault.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,215 @@
 | 
			
		||||
#include "CalculatePriceDefault.h"
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
using namespace nsCalculatePriceInterface;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const std::string CalculatePriceInterfacePluginInfoString = R"(
 | 
			
		||||
{
 | 
			
		||||
    "PluginName": "CalculatePriceDummy",
 | 
			
		||||
    "Version": "1.0",
 | 
			
		||||
    "git-describe": "",
 | 
			
		||||
}
 | 
			
		||||
)";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CalculatePriceDefault::CalculatePriceDefault(QObject *parent) :
 | 
			
		||||
    QObject(parent),
 | 
			
		||||
    errorCode(1),
 | 
			
		||||
    errorDescription(""),
 | 
			
		||||
    pluginState(PLUGIN_STATE::NOT_INITIALIZED)
 | 
			
		||||
{
 | 
			
		||||
    this->pluginInfo = QString::fromUtf8(CalculatePriceInterfacePluginInfoString.c_str());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CalculatePriceDefault::~CalculatePriceDefault()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PLUGIN_STATE CalculatePriceDefault::initCalculatePricePlugin(QObject *healthEventReceiver, const QSettings & settings)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(healthEventReceiver)
 | 
			
		||||
 | 
			
		||||
    qDebug() << "called CalculatePriceDummy::initCalculatePricePlugin()";
 | 
			
		||||
    qDebug() << "   pluginName from setting is: " << settings.value("PLUGINS/CalculatePricePlugin", "").toString();
 | 
			
		||||
 | 
			
		||||
    this->pluginState = PLUGIN_STATE::INITIALIZED;
 | 
			
		||||
 | 
			
		||||
    return this->pluginState;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CalculatePriceDefault::requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                                   const QString & AccessInformationType,
 | 
			
		||||
                                   const QString & PermitType)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(PermitType)
 | 
			
		||||
 | 
			
		||||
    emit this->requestCalculatePriceResult(RESULT_STATE::SUCCESS,
 | 
			
		||||
                                           AccessInformation,
 | 
			
		||||
                                           AccessInformationType,
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "1",
 | 
			
		||||
                                           "dummyPlugin"
 | 
			
		||||
                                           );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CalculatePriceDefault::requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                           const QString & AccessInformationType,
 | 
			
		||||
                           const QString & PermitType,
 | 
			
		||||
                           const QString & parktime)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(PermitType)
 | 
			
		||||
    Q_UNUSED(parktime)
 | 
			
		||||
 | 
			
		||||
    emit this->requestCalculatePriceResult(RESULT_STATE::SUCCESS,
 | 
			
		||||
                                           AccessInformation,
 | 
			
		||||
                                           AccessInformationType,
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "1",
 | 
			
		||||
                                           "dummyPlugin"
 | 
			
		||||
                                           );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CalculatePriceDefault::requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                           const QString & AccessInformationType,
 | 
			
		||||
                           const QString & PermitType,
 | 
			
		||||
                           nsCalculatePriceInterface::STEP step)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(AccessInformation)
 | 
			
		||||
    Q_UNUSED(AccessInformationType)
 | 
			
		||||
    Q_UNUSED(PermitType)
 | 
			
		||||
    Q_UNUSED(step)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CalculatePriceDefault::requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                           const QString & AccessInformationType,
 | 
			
		||||
                           const QString & PermitType,
 | 
			
		||||
                           int coinValue)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(AccessInformation)
 | 
			
		||||
    Q_UNUSED(AccessInformationType)
 | 
			
		||||
    Q_UNUSED(PermitType)
 | 
			
		||||
    Q_UNUSED(coinValue)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CalculatePriceDefault::requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                           const QString & AccessInformationType,
 | 
			
		||||
                           const QString & PermitType,
 | 
			
		||||
                           const QString & parktime,
 | 
			
		||||
                           const QString & cardInfo,
 | 
			
		||||
                           const QString & transactionInfo)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(PermitType)
 | 
			
		||||
    Q_UNUSED(parktime)
 | 
			
		||||
    Q_UNUSED(cardInfo)
 | 
			
		||||
    Q_UNUSED(transactionInfo)
 | 
			
		||||
 | 
			
		||||
    emit this->requestCalculatePriceResult(RESULT_STATE::SUCCESS,
 | 
			
		||||
                                           AccessInformation,
 | 
			
		||||
                                           AccessInformationType,
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "",
 | 
			
		||||
                                           "1",
 | 
			
		||||
                                           "dummyPlugin"
 | 
			
		||||
                                           );
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CalculatePriceDefault::requestProcessTransaction(const QString & AccessInformation,
 | 
			
		||||
                                      const QString & AccessInformationType,
 | 
			
		||||
                                      const QString &amount,
 | 
			
		||||
                                      bool isOffline,
 | 
			
		||||
                                      const QString & TransactionId,
 | 
			
		||||
                                      const QString & ReceiptData,
 | 
			
		||||
                                      const QString & PermitType, const QString &PaymentType)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(isOffline)
 | 
			
		||||
    Q_UNUSED(AccessInformation)
 | 
			
		||||
    Q_UNUSED(AccessInformationType)
 | 
			
		||||
    Q_UNUSED(amount)
 | 
			
		||||
    Q_UNUSED(TransactionId)
 | 
			
		||||
    Q_UNUSED(ReceiptData)
 | 
			
		||||
    Q_UNUSED(PermitType)
 | 
			
		||||
    Q_UNUSED(PaymentType)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/************************************************************************************************
 | 
			
		||||
 * Mandatory plugin methods
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PLUGIN_STATE CalculatePriceDefault::getState()
 | 
			
		||||
{
 | 
			
		||||
    return this->pluginState;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
quint32 CalculatePriceDefault::getLastError()
 | 
			
		||||
{
 | 
			
		||||
    return this->errorCode;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const QString & CalculatePriceDefault::getLastErrorDescription()
 | 
			
		||||
{
 | 
			
		||||
    return this->errorDescription;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const QString & CalculatePriceDefault::getPluginInfo()
 | 
			
		||||
{
 | 
			
		||||
    return pluginInfo;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const QString CalculatePriceDefault::getString(nsCalculatePriceInterface::RESULT_STATE resultState)
 | 
			
		||||
{
 | 
			
		||||
    QString str;
 | 
			
		||||
 | 
			
		||||
    switch (resultState) {
 | 
			
		||||
    case nsCalculatePriceInterface::RESULT_STATE::SUCCESS:
 | 
			
		||||
        str = QString("RESULT_STATE::SUCCESS");
 | 
			
		||||
        break;
 | 
			
		||||
    case nsCalculatePriceInterface::RESULT_STATE::ERROR_BACKEND:
 | 
			
		||||
        str = QString("RESULT_STATE::ERROR_BACKEND");
 | 
			
		||||
        break;
 | 
			
		||||
    case nsCalculatePriceInterface::RESULT_STATE::ERROR_NETWORK:
 | 
			
		||||
        str = QString("RESULT_STATE::ERROR_NETWORK");
 | 
			
		||||
        break;
 | 
			
		||||
    case nsCalculatePriceInterface::RESULT_STATE::ERROR_TIMEOUT:
 | 
			
		||||
        str = QString("RESULT_STATE::ERROR_TIMEOUT");
 | 
			
		||||
        break;
 | 
			
		||||
    case nsCalculatePriceInterface::RESULT_STATE::ERROR_PROCESS:
 | 
			
		||||
        str = QString("RESULT_STATE::ERROR_PROCESS");
 | 
			
		||||
        break;
 | 
			
		||||
    case nsCalculatePriceInterface::RESULT_STATE::ERROR_RETRY:
 | 
			
		||||
        str = QString("RESULT_STATE::ERROR_RETRY");
 | 
			
		||||
        break;
 | 
			
		||||
    case nsCalculatePriceInterface::RESULT_STATE::INFO:
 | 
			
		||||
        str = QString("RESULT_STATE::INFO");
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    return str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										95
									
								
								plugins/CalculatePrice/CalculatePriceDefault.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								plugins/CalculatePrice/CalculatePriceDefault.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,95 @@
 | 
			
		||||
#ifndef CALCULATEPRICEDUMMY_H
 | 
			
		||||
#define CALCULATEPRICEDUMMY_H
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include "CalculatePriceInterface.h"
 | 
			
		||||
using namespace nsCalculatePriceInterface;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CalculatePriceDefault : public QObject,
 | 
			
		||||
        public CalculatePriceInterface
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    Q_INTERFACES(CalculatePriceInterface)
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    CalculatePriceDefault(QObject *parent = 0);
 | 
			
		||||
    ~CalculatePriceDefault();
 | 
			
		||||
 | 
			
		||||
    // interface:
 | 
			
		||||
    PLUGIN_STATE initCalculatePricePlugin(QObject *healthEventReceiver, const QSettings & settings);
 | 
			
		||||
    void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                               const QString & AccessInformationType,
 | 
			
		||||
                               const QString & PermitType);
 | 
			
		||||
    void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                               const QString & AccessInformationType,
 | 
			
		||||
                               const QString & PermitType,
 | 
			
		||||
                               const QString & parktime);
 | 
			
		||||
    void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                               const QString & AccessInformationType,
 | 
			
		||||
                               const QString & PermitType,
 | 
			
		||||
                               nsCalculatePriceInterface::STEP step);
 | 
			
		||||
    void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                               const QString & AccessInformationType,
 | 
			
		||||
                               const QString & PermitType,
 | 
			
		||||
                               int coinValue);
 | 
			
		||||
    void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                               const QString & AccessInformationType,
 | 
			
		||||
                               const QString & PermitType,
 | 
			
		||||
                               const QString & parktime,
 | 
			
		||||
                               const QString & cardInfo,
 | 
			
		||||
                               const QString & transactionInfo);
 | 
			
		||||
    void requestProcessTransaction(const QString & AccessInformation,
 | 
			
		||||
                                   const QString & AccessInformationType,
 | 
			
		||||
                                   const QString & amount,
 | 
			
		||||
                                   bool isOffline,
 | 
			
		||||
                                   const QString & TransactionId,
 | 
			
		||||
                                   const QString & ReceiptData,
 | 
			
		||||
                                   const QString & PermitType,
 | 
			
		||||
                                   const QString & PaymentType);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    PLUGIN_STATE getState();
 | 
			
		||||
    quint32 getLastError();
 | 
			
		||||
    const QString & getLastErrorDescription();
 | 
			
		||||
 | 
			
		||||
    const QString & getPluginInfo();
 | 
			
		||||
 | 
			
		||||
    const QString getString(nsCalculatePriceInterface::RESULT_STATE resultState);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void requestCalculatePriceResult(RESULT_STATE resultState,
 | 
			
		||||
                                  const QString & accessInformation,
 | 
			
		||||
                                  const QString & accessInformationType,
 | 
			
		||||
                                  const QString & amountDuePeriodStart,
 | 
			
		||||
                                  const QString & amountDuePeriodEnd,
 | 
			
		||||
                                  const QString & amountDueNet,
 | 
			
		||||
                                  const QString & amountDueTax,
 | 
			
		||||
                                  const QString & gracePeriod,
 | 
			
		||||
                                  const QString & errorCode,
 | 
			
		||||
                                  const QString & errorDescription);
 | 
			
		||||
    void requestCalculatePriceResult(RESULT_STATE resultState,
 | 
			
		||||
                                  const QString & accessInformation,
 | 
			
		||||
                                  const QString & accessInformationType,
 | 
			
		||||
                                  const QString & amountDuePeriodStart,
 | 
			
		||||
                                  const QString & amountDuePeriodEnd,
 | 
			
		||||
                                  const PriceInfo & priceInfo,
 | 
			
		||||
                                  const QString & errorCode,
 | 
			
		||||
                                  const QString & errorDescription);
 | 
			
		||||
   void requestProcessTransactionResult(RESULT_STATE resultState,
 | 
			
		||||
                                        const QString & errorCode,
 | 
			
		||||
                                        const QString & errorDescription);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
   quint32 errorCode;
 | 
			
		||||
   QString errorCodeString;
 | 
			
		||||
   QString errorDescription;
 | 
			
		||||
   QString pluginInfo;
 | 
			
		||||
 | 
			
		||||
   PLUGIN_STATE pluginState;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // CALCULATEPRICEDUMMY_H
 | 
			
		||||
							
								
								
									
										157
									
								
								plugins/CalculatePrice/CalculatePriceInterface.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										157
									
								
								plugins/CalculatePrice/CalculatePriceInterface.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,157 @@
 | 
			
		||||
#ifndef CALCULATEPRICEINTERFACE_H
 | 
			
		||||
#define CALCULATEPRICEINTERFACE_H
 | 
			
		||||
 | 
			
		||||
#include <QtPlugin>
 | 
			
		||||
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
#include "ATBAPPplugin.h"
 | 
			
		||||
 | 
			
		||||
namespace nsCalculatePriceInterface {
 | 
			
		||||
    enum class PLUGIN_STATE : quint8;
 | 
			
		||||
    enum class RESULT_STATE : quint8;
 | 
			
		||||
    enum class STEP : quint8;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class PriceInfo
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    int priceNet;    // price net in cent
 | 
			
		||||
    int priceTax;    // price tax in cent
 | 
			
		||||
    int priceGross;  // price gross in cent
 | 
			
		||||
    int taxRate;     // tax rate per mill
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CalculatePriceInterface : public ATBAPPplugin
 | 
			
		||||
{
 | 
			
		||||
    Q_INTERFACES(ATBAPPplugin)
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
   virtual ~CalculatePriceInterface() {}
 | 
			
		||||
 | 
			
		||||
   virtual nsCalculatePriceInterface::PLUGIN_STATE initCalculatePricePlugin(QObject *healthEventReceiver,
 | 
			
		||||
                                                 const QSettings & settings) = 0;
 | 
			
		||||
 | 
			
		||||
   // for price calculation dependent on ID (AccessInformation)
 | 
			
		||||
   virtual void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                                      const QString & AccessInformationType,
 | 
			
		||||
                                      const QString & PermitType) = 0;
 | 
			
		||||
   
 | 
			
		||||
   // for price calculation dependent on value (e.g. parking time)
 | 
			
		||||
   virtual void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                                      const QString & AccessInformationType,
 | 
			
		||||
                                      const QString & PermitType,
 | 
			
		||||
                                      const QString & parktime) = 0;
 | 
			
		||||
 | 
			
		||||
    // for price/time calculation on next step up/down
 | 
			
		||||
    virtual void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                                       const QString & AccessInformationType,
 | 
			
		||||
                                       const QString & PermitType,
 | 
			
		||||
                                       nsCalculatePriceInterface::STEP step) = 0;
 | 
			
		||||
 | 
			
		||||
    // for price/time calculation on next coin value
 | 
			
		||||
    virtual void requestCalculatePrice(const QString & AccessInformation,
 | 
			
		||||
                                       const QString & AccessInformationType,
 | 
			
		||||
                                       const QString & PermitType,
 | 
			
		||||
                                       int coinValue) = 0;
 | 
			
		||||
 | 
			
		||||
    // for price calculation dependent on additonal values (e.g. parking time, card info, ...)
 | 
			
		||||
    virtual void requestCalculatePrice(const QString & AccessInformation,         // primary key e.g. a license plate, credit card number
 | 
			
		||||
                                       const QString & AccessInformationType,     // type of AccessInformation: LICENSEPLATE, CREDITCARD, PIN, ...
 | 
			
		||||
                                       const QString & PermitType,                // e.g. selected product / vehicle
 | 
			
		||||
                                       const QString & parktime,                  // parktime in minutes
 | 
			
		||||
                                       const QString & cardInfo,                  // additonal card info (e.g. PAN, Institusnummer, Token, ...)
 | 
			
		||||
                                       const QString & transactionInfo) = 0;      // kind of a transcation id, could be used for identification of transaction
 | 
			
		||||
 | 
			
		||||
    virtual void requestProcessTransaction(const QString & AccessInformation,
 | 
			
		||||
                                          const QString & AccessInformationType,
 | 
			
		||||
                                          const QString & amount,
 | 
			
		||||
                                          bool isOffline,
 | 
			
		||||
                                          const QString & TransactionId,
 | 
			
		||||
                                          const QString & ReceiptData,
 | 
			
		||||
                                          const QString & PermitType,
 | 
			
		||||
                                          const QString & PaymentType) = 0;
 | 
			
		||||
                                         
 | 
			
		||||
                                      
 | 
			
		||||
   virtual nsCalculatePriceInterface::PLUGIN_STATE getState() = 0;
 | 
			
		||||
   virtual quint32 getLastError() = 0;
 | 
			
		||||
   virtual const QString & getLastErrorDescription() = 0;
 | 
			
		||||
 | 
			
		||||
   // return a plugin description in JSON or XML
 | 
			
		||||
   // -> ATBAPPplugin::getPluginInfo()
 | 
			
		||||
 | 
			
		||||
   // helpers e.g. for debug / log
 | 
			
		||||
   virtual const QString getString(nsCalculatePriceInterface::RESULT_STATE resultState) = 0;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    virtual void requestCalculatePriceResult(nsCalculatePriceInterface::RESULT_STATE resultState,
 | 
			
		||||
                         const QString & accessInformation,
 | 
			
		||||
                         const QString & accessInformationType,
 | 
			
		||||
                         const QString & amountDuePeriodStart,
 | 
			
		||||
                         const QString & amountDuePeriodEnd,
 | 
			
		||||
                         const QString & amountDueNet,
 | 
			
		||||
                         const QString & amountDueTax,
 | 
			
		||||
                         const QString & gracePeriod,
 | 
			
		||||
                         const QString & errorCode,
 | 
			
		||||
                         const QString & errorDescription) = 0;
 | 
			
		||||
 | 
			
		||||
    virtual void requestCalculatePriceResult(nsCalculatePriceInterface::RESULT_STATE resultState,
 | 
			
		||||
                         const QString & accessInformation,
 | 
			
		||||
                         const QString & accessInformationType,
 | 
			
		||||
                         const QString & amountDuePeriodStart,
 | 
			
		||||
                         const QString & amountDuePeriodEnd,
 | 
			
		||||
                         const PriceInfo & priceInfo,
 | 
			
		||||
                         const QString & errorCode,
 | 
			
		||||
                         const QString & errorDescription) = 0;
 | 
			
		||||
 | 
			
		||||
    virtual void requestProcessTransactionResult(nsCalculatePriceInterface::RESULT_STATE resultState,
 | 
			
		||||
                                                 const QString & errorCode,
 | 
			
		||||
                                                 const QString & errorDescription) = 0;
 | 
			
		||||
 | 
			
		||||
    // TODO:
 | 
			
		||||
    /* APPLICATION_PROCESS_TYPE is a global ATB-Type:
 | 
			
		||||
     *   - BACKGROUND -> process can work in background without display
 | 
			
		||||
     *   - HMI        -> display is needed
 | 
			
		||||
     *   - t.b.d
 | 
			
		||||
     *
 | 
			
		||||
     * PROCESS_ID is an identifier for e.g. debuging or log which process/module/library/plugin...
 | 
			
		||||
     * caused the prevent
 | 
			
		||||
     *
 | 
			
		||||
    virtual void preventSuspend(APPLICATION_PROCESS_TYPE pt, PROCESS_ID pid) = 0;
 | 
			
		||||
    virtual void allowSuspend(PROCESS_ID pid)   = 0;
 | 
			
		||||
    */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Q_DECLARE_INTERFACE(CalculatePriceInterface,
 | 
			
		||||
                    "eu.atb.ptu.plugin.CalculatePriceInterface/4.0")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace nsCalculatePriceInterface {
 | 
			
		||||
 | 
			
		||||
    enum class PLUGIN_STATE : quint8 {
 | 
			
		||||
        NOT_INITIALIZED = 0,
 | 
			
		||||
        INITIALIZED = 1
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    enum class RESULT_STATE : quint8 {
 | 
			
		||||
        SUCCESS = 1,                    // got price and time from remote
 | 
			
		||||
        ERROR_BACKEND = 2,              // error from backand (e.g. backend replies with error)
 | 
			
		||||
        ERROR_NETWORK = 3,              // error from network (e.g. host not available)
 | 
			
		||||
        ERROR_TIMEOUT = 4,              // the operation timed out
 | 
			
		||||
        ERROR_PROCESS = 5,              // internal plugin error (e.g. bug in implementation)
 | 
			
		||||
        ERROR_RETRY = 6,                // retry operation
 | 
			
		||||
        INFO = 7
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    enum class STEP : quint8 {
 | 
			
		||||
        UP = 1,
 | 
			
		||||
        DOWN = 2
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // CALCULATEPRICEINTERFACE_H
 | 
			
		||||
							
								
								
									
										134
									
								
								plugins/PluginManager.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								plugins/PluginManager.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,134 @@
 | 
			
		||||
#include <QPluginLoader>
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
 | 
			
		||||
#include "PluginManager.h"
 | 
			
		||||
#include "ATBHMIconfig.h"
 | 
			
		||||
 | 
			
		||||
#include "plugins/ATBAPPplugin.h"
 | 
			
		||||
#include "plugins/CC/CCInterface.h"
 | 
			
		||||
#include "plugins/CalculatePrice/CalculatePriceInterface.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PluginManager::PluginManager(ATBHMIconfig *config, QObject *parent) :
 | 
			
		||||
    QObject(parent),
 | 
			
		||||
    config(config)
 | 
			
		||||
{
 | 
			
		||||
    this->loadPlugins();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PluginManager::loadPlugins()
 | 
			
		||||
{
 | 
			
		||||
    /* NOTE: setting a search path via 'QCoreApplication::addLibraryPath' does not work for
 | 
			
		||||
     * user specific plugins...
 | 
			
		||||
     * This seems to work only for QT core plugins which are loaded before QApplication object is
 | 
			
		||||
     * created.
 | 
			
		||||
     * => we set the path for our plugins manually here.
 | 
			
		||||
     */
 | 
			
		||||
    // DEBUG
 | 
			
		||||
    /* qDebug() << "--------------------------- DEBUG -----------------------------------";
 | 
			
		||||
     * qDebug() << "QCoreApplication::applicationDirPath() = " << QCoreApplication::applicationDirPath();
 | 
			
		||||
     * qDebug() << " ";
 | 
			
		||||
     * qDebug() << "QCoreApplication::libraryPaths()";
 | 
			
		||||
     * foreach (const QString &path, QCoreApplication::libraryPaths()) {
 | 
			
		||||
     *    qDebug() <<  "   " << path;
 | 
			
		||||
     * }
 | 
			
		||||
     * qDebug() << "---------------------------------------------------------------------";
 | 
			
		||||
     */
 | 
			
		||||
    /* NOTE: qputenv() to set LD_LIBRARY_PATH does not work either!
 | 
			
		||||
     * We tried this to set the path were libraries used by the plugin itself could be found
 | 
			
		||||
     * (e.g. kdsoap-library, which is used by several plugins).
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    // load all available plugins in config group [PLUGINS]
 | 
			
		||||
    QSettings * settings = this->config->getSettingsPtr();
 | 
			
		||||
 | 
			
		||||
    if (!settings->childGroups().contains("PLUGINS")) {
 | 
			
		||||
        qCritical() << "PluginManager: no plugins defined in config";
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    settings->beginGroup("PLUGINS");
 | 
			
		||||
    QStringList pluginStringList = settings->childKeys();
 | 
			
		||||
 | 
			
		||||
    QStringListIterator PluginsIterator(pluginStringList);
 | 
			
		||||
    QString pluginKey;
 | 
			
		||||
    QString pluginName;
 | 
			
		||||
    while(PluginsIterator.hasNext()) {
 | 
			
		||||
        pluginKey = PluginsIterator.next();
 | 
			
		||||
        pluginName = settings->value(pluginKey, "").toString();
 | 
			
		||||
 | 
			
		||||
        if (pluginName == "") {
 | 
			
		||||
            qCritical() << "PluginManager: plugin " << pluginKey << " is not defined";
 | 
			
		||||
        }
 | 
			
		||||
        else if (pluginKey.startsWith('#')) {
 | 
			
		||||
            qCritical() << "PluginManager: skip comment " << pluginKey;
 | 
			
		||||
        }
 | 
			
		||||
        else if (QString::compare(pluginName, "notUsed", Qt::CaseInsensitive) == 0) {
 | 
			
		||||
            qCritical() << "PluginManager: plugin " << pluginKey << " is not used";
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            if (!QLibrary::isLibrary(pluginName))  pluginName.append(".so");
 | 
			
		||||
            if (!pluginName.startsWith("lib"))     pluginName.prepend("lib");
 | 
			
		||||
            if (!pluginName.startsWith("plugins")) pluginName.prepend("plugins/");
 | 
			
		||||
 | 
			
		||||
            if (!pluginName.startsWith('/')) {
 | 
			
		||||
                pluginName.prepend('/').prepend(QApplication::applicationDirPath());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            qCritical() << "PluginManager::loadPlugins() load plugin: "
 | 
			
		||||
                     << pluginName;
 | 
			
		||||
 | 
			
		||||
            // TODO: check, if plugin file is available, readable etc...
 | 
			
		||||
 | 
			
		||||
            QPluginLoader* pluginLoader = new QPluginLoader();
 | 
			
		||||
            pluginLoader->setFileName(pluginName);
 | 
			
		||||
 | 
			
		||||
            plugins.insert(pluginKey, pluginLoader);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    settings->endGroup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QObject * PluginManager::getInstance(const QString & pluginname)
 | 
			
		||||
{
 | 
			
		||||
    QObject * result = nullptr;
 | 
			
		||||
 | 
			
		||||
    QPluginLoader* pluginLoader = plugins[pluginname];
 | 
			
		||||
 | 
			
		||||
    if (pluginLoader != nullptr) {
 | 
			
		||||
 | 
			
		||||
        QObject* plugin = pluginLoader->instance();
 | 
			
		||||
        if (!pluginLoader->isLoaded()) {
 | 
			
		||||
            qCritical() << "PluginManager::getInstance("
 | 
			
		||||
                        << pluginname
 | 
			
		||||
                        << ") errorString: "
 | 
			
		||||
                        << pluginLoader->errorString();
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            result = plugin;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const QList<QString> PluginManager::listAvailablePlugins()
 | 
			
		||||
{
 | 
			
		||||
    return plugins.keys();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool PluginManager::isPluginAvailable(const QString & pluginname)
 | 
			
		||||
{
 | 
			
		||||
    if (plugins[pluginname] != nullptr) {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								plugins/PluginManager.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								plugins/PluginManager.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
#ifndef PLUGINMANAGER_H
 | 
			
		||||
#define PLUGINMANAGER_H
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include <QHash>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ATBHMIconfig;
 | 
			
		||||
class QPluginLoader;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PluginManager : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit PluginManager(ATBHMIconfig *config, QObject *parent = nullptr);
 | 
			
		||||
 | 
			
		||||
    QObject * getInstance(const QString & pluginname);
 | 
			
		||||
 | 
			
		||||
    const QList<QString> listAvailablePlugins();
 | 
			
		||||
    bool isPluginAvailable(const QString & pluginname);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    ATBHMIconfig *config;
 | 
			
		||||
 | 
			
		||||
    QDir pluginsDir;
 | 
			
		||||
 | 
			
		||||
    void loadPlugins();
 | 
			
		||||
 | 
			
		||||
    // Hash to store all plugins
 | 
			
		||||
    QHash<QString, QPluginLoader*> plugins;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // PLUGINMANAGER_H
 | 
			
		||||
		Reference in New Issue
	
	Block a user