diff --git a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro index 4b492e3030f23eee69e14104ab38c1e20579bf9a..b91a437d2da865f70fc96783e590d2d0451259a1 100755 --- a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro +++ b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro @@ -66,7 +66,6 @@ SOURCES += \ $$PWD/main.cpp \ $$PWD/DapServiceClient.cpp \ $$PWD/DapServiceController.cpp \ - $$PWD/DapCommandController.cpp \ $$PWD/DapServiceClientNativeAbstract.cpp \ $$PWD/DapServiceClientNativeLinux.cpp \ $$PWD/DapServiceClientNativeWin.cpp \ @@ -82,7 +81,6 @@ else: unix:!android: target.path = /opt/cellframe-dashboard/bin HEADERS += \ $$PWD/DapServiceClient.h \ $$PWD/DapServiceController.h \ - $$PWD/DapCommandController.h \ $$PWD/DapServiceClientNativeAbstract.h \ $$PWD/DapServiceClientNativeLinux.h \ $$PWD/DapServiceClientNativeWin.h \ diff --git a/CellFrameDashboardGUI/DapCommandController.cpp b/CellFrameDashboardGUI/DapCommandController.cpp deleted file mode 100644 index 99f49ea9af2fea763cf66c95ccd6dc37de295446..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapCommandController.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "DapCommandController.h" - - -/// Overloaded constructor. -/// @param apIODevice Data transfer device. -/// @param apParent Parent. -DapCommandController::DapCommandController(QIODevice *apIODevice, QObject *apParent) - : DapRpcService(apParent) -{ - // Socket initialization - m_DAPRpcSocket = new DapRpcSocket(apIODevice, this); - // Signal-slot connection initiating the execution of the method called by the service - connect(m_DAPRpcSocket, SIGNAL(messageReceived(DapRpcMessage)), SLOT(messageProcessing(DapRpcMessage))); - - addService(this); -} - -/// Process incoming message. -/// @param asMessage Incoming message. -void DapCommandController::messageProcessing(const DapRpcMessage &asMessage) -{ - DapRpcSocket *socket = static_cast<DapRpcSocket*>(sender()); - if (!socket) { - qDebug() << "Called without service socket"; - return; - } - - processMessage(socket, asMessage); -} diff --git a/CellFrameDashboardGUI/DapCommandController.h b/CellFrameDashboardGUI/DapCommandController.h deleted file mode 100644 index 960fdde1128ac270719f68909286e54da5d8dde4..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapCommandController.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef DAPCOMMANDCONTROLLER_H -#define DAPCOMMANDCONTROLLER_H - -#include <QObject> -#include <QIODevice> -#include <QVariantMap> -#include <QDebug> - -#include "DapRpcSocket.h" -#include "DapRpcServiceProvider.h" -#include "DapRpcService.h" -#include "DapChainWallet.h" - -/// Class command controller for service -class DapCommandController : public DapRpcService, public DapRpcServiceProvider -{ - Q_OBJECT - Q_DISABLE_COPY(DapCommandController) - Q_CLASSINFO("serviceName", "RPCClient") - - /// RPC socket. - DapRpcSocket * m_DAPRpcSocket {nullptr}; - -public: - /// Overloaded constructor. - /// @param apIODevice Data transfer device. - /// @param apParent Parent. - DapCommandController(QIODevice *apIODevice, QObject *apParent = nullptr); - -private slots: - /// Process incoming message. - /// @param asMessage Incoming message. - void messageProcessing(const DapRpcMessage &asMessage); -}; - -#endif // COMMANDCONTROLLER_H diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp index 75a4b022b1d6eacc16e473944a41e3b3682d6f3b..94c8780f4ada554741f1797bb0bca92f546e4cb9 100644 --- a/CellFrameDashboardGUI/DapServiceController.cpp +++ b/CellFrameDashboardGUI/DapServiceController.cpp @@ -3,20 +3,22 @@ DapServiceController::DapServiceController(QObject *apParent) : QObject(apParent) { - + } -/// Get company brand. -/// @return Brand Ñompany. +/// Client controller initialization. +/// @param apDapServiceClient Network connection controller. void DapServiceController::init(DapServiceClient *apDapServiceClient) { m_pDapServiceClient = apDapServiceClient; - - // Creating rpc controller - m_pDapCommandController = new DapCommandController(apDapServiceClient->getClientSocket(), this); - + // Socket initialization + m_DAPRpcSocket = new DapRpcSocket(apDapServiceClient->getClientSocket(), this); + // Register command. + registerCommand(); } +/// Get company brand. +/// @return Brand Ñompany. QString DapServiceController::getBrand() const { return m_sBrand; @@ -37,6 +39,47 @@ DapServiceController &DapServiceController::getInstance() return instance; } +/// Send request to service. +/// @param arg1...arg10 Parametrs. +void DapServiceController::requestToService(const QString &asServicename, const QVariant &arg1, + const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, + const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, + const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) +{ + DapAbstractCommand * transceiver = m_transceivers.find(asServicename).value(); + + Q_ASSERT(transceiver); + + transceiver->requestToService(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + connect(transceiver, SIGNAL(serviceResponded(QVariant)), SLOT(find(QVariant))); +} + +/// Register command. +void DapServiceController::registerCommand() +{ + m_transceivers.insert("ADD", new DapAddWalletCommand("ADD", m_DAPRpcSocket, this)); +} + +/// Find the emitted signal. +/// @param aValue Transmitted parameter. +void DapServiceController::findEmittedSignal(const QVariant &aValue) +{ + DapAbstractCommand * transceiver = dynamic_cast<DapAbstractCommand *>(sender()); + + Q_ASSERT(transceiver); + + QString nameSignal = QString("%1Responded").arg(transceiver->getName()); + + for (int idx = 0; idx < metaObject()->methodCount(); ++idx) + { + const QMetaMethod method = metaObject()->method(idx); + if (method.methodType() == QMetaMethod::Signal && method.name() == nameSignal) + { + metaObject()->method(idx).invoke(this, Q_ARG(QVariant, aValue)); + } + } +} + /// Method that implements the singleton pattern for the qml layer. /// @param engine QML application. /// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code. @@ -47,3 +90,5 @@ QObject *DapServiceController::singletonProvider(QQmlEngine *engine, QJSEngine * return &getInstance(); } + + diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index 1872df162cdddc7c969e16b022892f863710d674..3d6ac60c974cecd1cfc63bac80062e200693e359 100644 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -2,11 +2,14 @@ #define DAPSERVICECONTROLLER_H #include <QObject> + +#include <QGenericArgument> #include <QQmlEngine> #include <QJSEngine> -#include "DapCommandController.h" #include "DapServiceClient.h" +#include "Handlers/DapAbstractCommand.h" +#include "Handlers/DapAddWalletCommand.h" class DapServiceController : public QObject { @@ -16,11 +19,12 @@ class DapServiceController : public QObject QString m_sBrand {DAP_BRAND}; /// Application version. QString m_sVersion {DAP_VERSION}; - /// Service connection management service. DapServiceClient *m_pDapServiceClient {nullptr}; - /// RPC protocol controller. - DapCommandController *m_pDapCommandController {nullptr}; + /// Command manager. + QMap<QString, DapAbstractCommand*> m_transceivers; + /// RPC socket. + DapRpcSocket * m_DAPRpcSocket {nullptr}; /// Standard constructor explicit DapServiceController(QObject *apParent = nullptr); @@ -28,12 +32,20 @@ public: /// Get an instance of a class. /// @return Instance of a class. Q_INVOKABLE static DapServiceController &getInstance(); + /// Send request to service. + /// @param arg1...arg10 Parametrs. + Q_INVOKABLE void requestToService(const QString& asServiceName, const QVariant &arg1 = QVariant(), + const QVariant &arg2 = QVariant(), const QVariant &arg3 = QVariant(), + const QVariant &arg4 = QVariant(), const QVariant &arg5 = QVariant(), + const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), + const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), + const QVariant &arg10 = QVariant()); ///******************************************** /// Property /// ******************************************* - /// Brand Ñompany. + /// Brand company. Q_PROPERTY(QString Brand MEMBER m_sBrand READ getBrand NOTIFY brandChanged) /// Application version. Q_PROPERTY(QString Version MEMBER m_sVersion READ getVersion NOTIFY versionChanged) @@ -41,6 +53,9 @@ public: ///******************************************** /// Interface /// ******************************************* + + /// Client controller initialization. + /// @param apDapServiceClient Network connection controller. void init(DapServiceClient *apDapServiceClient); /// Get company brand. /// @return Brand Ñompany. @@ -56,7 +71,14 @@ signals: /// The signal is emitted when the Application version property changes. /// @param version Version void versionChanged(const QString &version); - + +private slots: + /// Register command. + void registerCommand(); + /// Find the emitted signal. + /// @param aValue Transmitted parameter. + void findEmittedSignal(const QVariant& aValue); + public slots: /// Method that implements the singleton pattern for the qml layer. /// @param engine QML application. diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml index 2a368e021ddbbc9ba11b352774de6e56ad1cbf42..d5d43c843182caac5e6eebc1db37be79d0c9ae8c 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml @@ -1,4 +1,5 @@ import QtQuick 2.4 DapDashboardTopPanelForm { + testButton.onClicked: dapServiceController.requestToService("ADD", 5) } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml index ea5ef5959e3cd220fa7a09b158bc0461f64ee4a3..b58555259e7bc024f2f444000d92b2f0484c5839 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml @@ -1,8 +1,16 @@ import QtQuick 2.4 +import QtQuick.Controls 2.0 import "../../" DapAbstractTopPanel { + property alias testButton: button + Button + { + id: button + anchors.fill: parent + text: "Press" + } } diff --git a/CellFrameDashboardService/CellFrameDashboardService.pro b/CellFrameDashboardService/CellFrameDashboardService.pro index 69a9c8fc8d6d119bd703d0d9a54a8a9189fb3350..5f7669d76486d9db678462e5b32d69bf362d3742 100755 --- a/CellFrameDashboardService/CellFrameDashboardService.pro +++ b/CellFrameDashboardService/CellFrameDashboardService.pro @@ -45,12 +45,12 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - $$PWD/DapChainDashboardService.cpp \ + $$PWD/DapServiceController.cpp \ $$PWD/main.cpp \ HEADERS += \ - $$PWD/DapChainDashboardService.h \ + $$PWD/DapServiceController.h \ include (../libdap/libdap.pri) diff --git a/CellFrameDashboardService/DapChainDashboardService.cpp b/CellFrameDashboardService/DapChainDashboardService.cpp.autosave old mode 100755 new mode 100644 similarity index 83% rename from CellFrameDashboardService/DapChainDashboardService.cpp rename to CellFrameDashboardService/DapChainDashboardService.cpp.autosave index 26195151364d7a79ba5c8811592fb33007f39d30..d616c2aaba18e0e1c5ae508cd2f262a44fe38d31 --- a/CellFrameDashboardService/DapChainDashboardService.cpp +++ b/CellFrameDashboardService/DapChainDashboardService.cpp.autosave @@ -12,7 +12,7 @@ bool DapChainDashboardService::start() qInfo() << "DapChainDashboardService::start()"; m_pServer = new DapUiService(); - m_pServer->setSocketOptions(QLocalServer::WorldAccessOption ); + m_pServer->setSocketOptions(QLocalServer::WorldAccessOption); if(m_pServer->listen(DAP_BRAND)) { connect(m_pServer, SIGNAL(onClientConnected()), SIGNAL(onNewClientConnected())); @@ -26,3 +26,8 @@ bool DapChainDashboardService::start() } return true; } + +void DapChainDashboardService::example(int x) +{ + qInfo() << "Example " << x; +} diff --git a/CellFrameDashboardService/DapServiceController.cpp b/CellFrameDashboardService/DapServiceController.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5c2702c2871666d2b312ce082820266f8ff76e3b --- /dev/null +++ b/CellFrameDashboardService/DapServiceController.cpp @@ -0,0 +1,39 @@ +#include "DapServiceController.h" + +/// Standard constructor. +/// @param parent Parent. +DapServiceController::DapServiceController(QObject *parent) : QObject(parent) +{ + connect(this, &DapServiceController::onNewClientConnected, [=] { + qDebug() << "Frontend connected"; + }); +} + +/// Start service: creating server and socket. +/// @return Returns true if the service starts successfully, otherwise false. +bool DapServiceController::start() +{ + qInfo() << "DapChainDashboardService::start()"; + + m_pServer = new DapUiService(); + m_pServer->setSocketOptions(QLocalServer::WorldAccessOption); + if(m_pServer->listen(DAP_BRAND)) + { + connect(m_pServer, SIGNAL(onClientConnected()), SIGNAL(onNewClientConnected())); + // Register command to cellframenode + registerCommand(); + } + else + { + qCritical() << QString("Can't listen on %1").arg(DAP_BRAND); + qCritical() << m_pServer->errorString(); + return false; + } + return true; +} + +/// Register command. +void DapServiceController::registerCommand() +{ + m_pServer->addService(new DapAddWalletCommand("ADD", nullptr, this)); +} diff --git a/CellFrameDashboardService/DapChainDashboardService.h b/CellFrameDashboardService/DapServiceController.h similarity index 63% rename from CellFrameDashboardService/DapChainDashboardService.h rename to CellFrameDashboardService/DapServiceController.h index b299b65a9f9a5a4b8a7d0498cb0dd6ee66b6b128..18be98a0c331a7735cdfafb5922ca04edd231324 100755 --- a/CellFrameDashboardService/DapChainDashboardService.h +++ b/CellFrameDashboardService/DapServiceController.h @@ -9,44 +9,49 @@ ** ****************************************************************************/ -#ifndef DAPCHAINDASHBOARDSERVICE_H -#define DAPCHAINDASHBOARDSERVICE_H +#ifndef DAPSERVICECONTROLLER_H +#define DAPSERVICECONTROLLER_H #include <QObject> #include <QCoreApplication> -#include "DapRpcAbstractServer.h" #include "DapRpcLocalServer.h" -#include "DapRpcTCPServer.h" -#include "DapRpcService.h" #include <QLocalServer> typedef class DapRpcLocalServer DapUiService; + +#include "Handlers/DapAbstractCommand.h" +#include "Handlers/DapAddWalletCommand.h" + /** - * @brief The DapChainDashboardService class + * @brief The DapServiceController class * Service class which provide handle operations with dashboard. * Class is server which works clients. Protocol to communacate with client is RPC. * Work with serves start from public methos start(). - * Class consist of follow handlers: - * @see DapChainLogHandler */ -class DapChainDashboardService : public DapRpcService +class DapServiceController : public QObject { Q_OBJECT - Q_CLASSINFO("serviceName", "RPCServer") - /// Service core. - DapUiService * m_pServer {nullptr}; + /// Service core. + DapUiService * m_pServer {nullptr}; + public: - /// Standard Ñonstructor. - explicit DapChainDashboardService(); - /// Start service: creating server and socket + /// Standard constructor. + /// @param parent Parent. + explicit DapServiceController(QObject * parent = nullptr); + /// Start service: creating server and socket. + /// @return Returns true if the service starts successfully, otherwise false. bool start(); signals: /// The signal is emitted in case of successful connection of a new client. void onNewClientConnected(); + +private slots: + /// Register command. + void registerCommand(); }; -#endif // DAPCHAINDASHBOARDSERVICE_H +#endif // DAPSERVICECONTROLLER_H diff --git a/CellFrameDashboardService/main.cpp b/CellFrameDashboardService/main.cpp index 06b2451e963fa778fb9b424aff32c32e30157d53..c0c8bd051c8233ad2d0fb68151164c8d0fc7981b 100755 --- a/CellFrameDashboardService/main.cpp +++ b/CellFrameDashboardService/main.cpp @@ -7,7 +7,7 @@ #include <unistd.h> #include "DapHalper.h" -#include "DapChainDashboardService.h" +#include "DapServiceController.h" #include "DapLogger.h" #include <sys/stat.h> @@ -50,11 +50,8 @@ int main(int argc, char *argv[]) //#endif // Creating the main application object processArgs(); - DapChainDashboardService service; - service.start(); - - // Initialization of the application in the system tray -// service.initTray(); + DapServiceController serviceController; + serviceController.start(); return a.exec(); diff --git a/DapRPCProtocol/DapRpcService.cpp b/DapRPCProtocol/DapRpcService.cpp index 6c37bbf190d11d8dbb931e0f8ce77924a7fb62f3..d4c22849c324bce93b225bb5ddc61d5c9dff2bd7 100644 --- a/DapRPCProtocol/DapRpcService.cpp +++ b/DapRPCProtocol/DapRpcService.cpp @@ -60,8 +60,13 @@ void DapRpcService::setCurrentRequest(const DapRpcServiceRequest &aCurrentReques m_currentRequest = aCurrentRequest; } -DapRpcService::DapRpcService(QObject *apParent) - : QObject(apParent) +QString DapRpcService::getName() const +{ + return m_sName; +} + +DapRpcService::DapRpcService(const QString &asName, QObject *apParent) + : QObject(apParent), m_sName(asName) { } diff --git a/DapRPCProtocol/DapRpcService.h b/DapRPCProtocol/DapRpcService.h index c13786febbeeddf22ae5d4257c4b3add6353348e..6e348b96658456681ece13ed7d12e31bcb2027c9 100644 --- a/DapRPCProtocol/DapRpcService.h +++ b/DapRPCProtocol/DapRpcService.h @@ -43,13 +43,14 @@ class DapRpcService : public QObject QHash<QByteArray, QList<int> > m_invokableMethodHash; DapRpcServiceRequest m_currentRequest; bool m_delayedResponse {false}; + QString m_sName; protected: DapRpcServiceRequest currentRequest() const; void beginDelayedResponse(); public: - explicit DapRpcService(QObject *apParent = nullptr); + explicit DapRpcService(const QString &asName, QObject *apParent = nullptr); ~DapRpcService(); void cacheInvokableInfo(); @@ -59,6 +60,8 @@ public: void setCurrentRequest(const DapRpcServiceRequest &aCurrentRequest); + QString getName() const; + signals: void result(const DapRpcMessage &aDapRpcMessage); void notifyConnectedClients(const DapRpcMessage &aDapRpcMessage); diff --git a/DapRPCProtocol/DapRpcServiceProvider.cpp b/DapRPCProtocol/DapRpcServiceProvider.cpp index 71168a8f88a8555a50a78379292923cc9a04c172..d9d066b7b0a905ec1100d0b85dff1718ffb60ff3 100644 --- a/DapRPCProtocol/DapRpcServiceProvider.cpp +++ b/DapRPCProtocol/DapRpcServiceProvider.cpp @@ -12,7 +12,8 @@ DapRpcServiceProvider::~DapRpcServiceProvider() QByteArray DapRpcServiceProvider::getServiceName(DapRpcService *apService) { const QMetaObject *mo = apService->metaObject(); - for (int i = 0; i < mo->classInfoCount(); i++) { + for (int i = 0; i < mo->classInfoCount(); i++) + { const QMetaClassInfo mci = mo->classInfo(i); if (mci.name() == QLatin1String("serviceName")) return mci.value(); @@ -23,7 +24,7 @@ QByteArray DapRpcServiceProvider::getServiceName(DapRpcService *apService) bool DapRpcServiceProvider::addService(DapRpcService *apService) { - QByteArray serviceName = getServiceName(apService); + QByteArray serviceName = apService->getName().toUtf8(); if (serviceName.isEmpty()) { qJsonRpcDebug() << "service added without serviceName classinfo, aborting"; return false; @@ -60,8 +61,11 @@ void DapRpcServiceProvider::processMessage(DapRpcSocket *apSocket, const DapRpcM case DapRpcMessage::Request: case DapRpcMessage::Notification: { QByteArray serviceName = aMessage.method().section(".", 0, -2).toLatin1(); - if (serviceName.isEmpty() || !m_services.contains(serviceName)) { - if (aMessage.type() == DapRpcMessage::Request) { + bool b = m_services.contains(serviceName); + if (serviceName.isEmpty() || !m_services.contains(serviceName)) + { + if (aMessage.type() == DapRpcMessage::Request) + { DapRpcMessage error = aMessage.createErrorResponse(DapErrorCode::MethodNotFound, QString("service '%1' not found").arg(serviceName.constData())); diff --git a/libCellFrameDashboardCommon/DapLogModel.cpp b/libCellFrameDashboardCommon/DapLogModel.cpp deleted file mode 100644 index cadb983aa6bd05bba34845d420bde1e9a00c08b2..0000000000000000000000000000000000000000 --- a/libCellFrameDashboardCommon/DapLogModel.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "DapLogModel.h" - -DapLogModel::DapLogModel(QObject *parent) : QAbstractListModel(parent) -{ - -} - -DapLogModel &DapLogModel::getInstance() -{ - static DapLogModel instance; - return instance; -} - -int DapLogModel::rowCount(const QModelIndex &) const -{ - return m_dapLogMessage.count(); -} - -QVariant DapLogModel::data(const QModelIndex &index, int role) const -{ - if (index.row() < rowCount()) - switch (role) { - case TypeRole: - { - QString s = m_dapLogMessage.at(index.row())->getType(); - return m_dapLogMessage.at(index.row())->getType(); - } - case TimeStampRole: return m_dapLogMessage.at(index.row())->getTimeStamp(); - case FileRole: return m_dapLogMessage.at(index.row())->getFile(); - case MessageRole: - { - QString s1 = m_dapLogMessage.at(index.row())->getMessage(); - - return m_dapLogMessage.at(index.row())->getMessage(); - } - default: - break; - } - return QVariant(); -} - -QHash<int, QByteArray> DapLogModel::roleNames() const -{ - static const QHash<int, QByteArray> roles { - { TypeRole, "type" }, - { TimeStampRole, "timestamp" }, - { FileRole, "file" }, - { MessageRole, "message" } - }; - - return roles; -} - -QVariantMap DapLogModel::get(int row) const -{ - const DapLogMessage *widget = m_dapLogMessage.value(row); - return { {"type", widget->getType()}, {"timestamp", widget->getTimeStamp()}, {"file", widget->getFile()}, {"message", widget->getMessage()} }; -} - -void DapLogModel::append(const DapLogMessage &message) -{ - this->append(message.getType(), message.getTimeStamp(), message.getFile(), message.getMessage()); -} - -void DapLogModel::append(const QString &type, const QString ×tamp, const QString &file, const QString &message) -{ - beginInsertRows(QModelIndex(), m_dapLogMessage.count(), m_dapLogMessage.count()); - m_dapLogMessage.insert(m_dapLogMessage.count(), new DapLogMessage(type, timestamp, file, message)); - endInsertRows(); -} - -void DapLogModel::set(int row, const QString &type, const QString ×tamp, const QString &file, const QString &message) -{ - if (row < 0 || row >= m_dapLogMessage.count()) - return; - - DapLogMessage *widget = m_dapLogMessage.value(row); - widget->setType(type); - widget->setTimeStamp(timestamp); - widget->setFile(file); - widget->setMessage(message); - dataChanged(index(row, 0), index(row, 0), { TypeRole, TimeStampRole, FileRole, MessageRole }); -} - -void DapLogModel::remove(int row) -{ - if (row < 0 || row >= m_dapLogMessage.count()) - return; - - beginRemoveRows(QModelIndex(), row, row); - m_dapLogMessage.removeAt(row); - endRemoveRows(); -} - -void DapLogModel::clear() -{ - for(auto it = m_dapLogMessage.begin(); it != m_dapLogMessage.end(); ++it) - { - delete *it; - } - - m_dapLogMessage.clear(); -} - - -/// Method that implements the singleton pattern for the qml layer. -/// @param engine QML application. -/// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code. -QObject *DapLogModel::singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine) -{ - Q_UNUSED(engine) - Q_UNUSED(scriptEngine) - - return &getInstance(); -} diff --git a/libCellFrameDashboardCommon/DapLogModel.h b/libCellFrameDashboardCommon/DapLogModel.h deleted file mode 100644 index 4a35cfbabbe0149e964352c83d379b4b87b45965..0000000000000000000000000000000000000000 --- a/libCellFrameDashboardCommon/DapLogModel.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef DAPLOGMODEL_H -#define DAPLOGMODEL_H - -#include <QObject> -#include <QAbstractListModel> -#include <QList> -#include <QQmlEngine> -#include <QJSEngine> -#include <QXmlStreamWriter> -#include <QXmlStreamReader> -#include <QXmlStreamAttribute> - -#include "DapLogMessage.h" -/** - * @brief The DapLogRole enum - * Roles of dap log model - * - * These values are used in arguments to methods data and roleNames. - * Main goal is return concrete fields from concrete log messages - */ -enum DapLogRole { - /// Type of log message - TypeRole = Qt::DisplayRole, - /// Timestamp of log message - TimeStampRole = Qt::UserRole, - /// Name of file where log message was occured - FileRole, - /// Text of log message - MessageRole - }; - -/// Class model for log screen -class DapLogModel : public QAbstractListModel -{ - Q_OBJECT - /// list of log messages - QList<DapLogMessage*> m_dapLogMessage; - - /// standard constructor - DapLogModel(QObject *parent = nullptr); -public: - - /// Get an instance of a class. - /// @return Instance of a class. - Q_INVOKABLE static DapLogModel &getInstance(); - - - Q_ENUM(DapLogRole) - - /// Count of log messages in model - /// @return count of log messages - int rowCount(const QModelIndex & = QModelIndex()) const; - /// Get data from concrete log messages - /// @param index Index of log message - /// @param role Which field in log message - /// @return Part of log message in according to which field was choosen - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - /// Get all types fields of log message - /// @return set of fiels of log message - QHash<int, QByteArray> roleNames() const; - - /// Get concrete log message - /// @return log message - Q_INVOKABLE QVariantMap get(int row) const; - /// Append to new log message - /// @param message New log message - Q_INVOKABLE void append(const DapLogMessage &message); - /// Append to new log message - /// @param type Type of log message - /// @param timestamp Timestamp of log message - /// @param file Name of file of log message - /// @param message Text of log message - Q_INVOKABLE void append(const QString &type, const QString ×tamp, const QString &file, const QString &message); - /// Change log message by new data - /// @param row Index of log message - /// @param type Type of log message - /// @param timestamp Timestamp of log message - /// @param file Name of file of log message - /// @param message Text of log message - Q_INVOKABLE void set(int row, const QString &type, const QString ×tamp, const QString &file, const QString &message); - /// Remove log message - /// @param row Index of log message - Q_INVOKABLE void remove(int row); - /// Clear all log messages - Q_INVOKABLE void clear(); - -public slots: - /// Method that implements the singleton pattern for the qml layer. - /// @param engine QML application. - /// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code. - static QObject *singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine); -}; - -#endif // DAPLOGMODEL_H diff --git a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a817b4248a5e70cc4cf08cfb42c9e7e137e623b --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp @@ -0,0 +1,70 @@ +#include "DapAbstractCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param apSocket Client connection socket with service. +/// @param parent Parent. +DapAbstractCommand::DapAbstractCommand(const QString &asServiceName, DapRpcSocket* apSocket, QObject *parent) + : DapCommand(asServiceName, parent), m_pSocket(apSocket) +{ + +} + +/// Send request to client. +/// @param arg1...arg10 Parameters. +void DapAbstractCommand::requestToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, + const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) +} + +/// Reply from client. +/// @return Client reply. +QVariant DapAbstractCommand::replyFromClient() +{ + emit clientResponded(QVariant()); + return QVariant(); +} + +/// Send request to service. +/// @param arg1...arg10 Parameters. +void DapAbstractCommand::requestToService(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, + const QVariant &arg6, const QVariant &arg7, + const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + DapRpcServiceReply *reply = m_pSocket->invokeRemoteMethod(QString("%1.%2").arg(this->getName()).arg("respondToClient"), + arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + connect(reply, SIGNAL(finished()), this, SLOT(replyFromService())); +} + +/// Reply from service. +/// @return Service reply. +void DapAbstractCommand::replyFromService() +{ + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + emit serviceResponded(reply->response().toJsonValue().toVariant()); +} diff --git a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..6b3014c22457531109b10e1460aa268a195929c1 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** This file is part of the libCellFrameDashboardClient library. +** +** The class implements the command interface. +** +****************************************************************************/ + +#ifndef DAPABSTRACTCOMMAND_H +#define DAPABSTRACTCOMMAND_H + +#include <QObject> +#include <QVariant> + +#include "DapRpcSocket.h" + +typedef DapRpcService DapCommand; + +class DapAbstractCommand : public DapCommand +{ + Q_OBJECT + + /// Client connection socket with service. + DapRpcSocket *m_pSocket {nullptr}; + +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param apSocket Client connection socket with service. + /// @param parent Parent. + explicit DapAbstractCommand(const QString &asServiceName, DapRpcSocket *apSocket = nullptr, QObject *parent = nullptr); + +signals: + /// The signal is emitted if a response from the client is successfully received. + /// @param asRespond Client response. + void clientResponded(const QVariant& asRespond); + /// The signal is emitted in case of a successful response from the service. + /// @param asRespond Service response. + void serviceResponded(const QVariant& asRespond); + +public slots: + /// Send request to client. + /// @param arg1...arg10 Parameters. + Q_INVOKABLE void requestToClient(const QVariant &arg1 = QVariant(), + const QVariant &arg2 = QVariant(), const QVariant &arg3 = QVariant(), + const QVariant &arg4 = QVariant(), const QVariant &arg5 = QVariant(), + const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), + const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), + const QVariant &arg10 = QVariant()); + /// Send a response to the service. + /// @param arg1...arg10 Parameters. + /// @return Reply to service. + virtual QVariant respondToService(const QVariant &arg1 = QVariant(), + const QVariant &arg2 = QVariant(), const QVariant &arg3 = QVariant(), + const QVariant &arg4 = QVariant(), const QVariant &arg5 = QVariant(), + const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), + const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), + const QVariant &arg10 = QVariant()) = 0; + /// Reply from client. + /// @return Client reply. + virtual QVariant replyFromClient(); + + /// Send request to service. + /// @param arg1...arg10 Parameters. + Q_INVOKABLE void requestToService(const QVariant &arg1 = QVariant(), + const QVariant &arg2 = QVariant(), const QVariant &arg3 = QVariant(), + const QVariant &arg4 = QVariant(), const QVariant &arg5 = QVariant(), + const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), + const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), + const QVariant &arg10 = QVariant()); + /// Send a response to the client. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + virtual QVariant respondToClient(const QVariant &arg1 = QVariant(), + const QVariant &arg2 = QVariant(), const QVariant &arg3 = QVariant(), + const QVariant &arg4 = QVariant(), const QVariant &arg5 = QVariant(), + const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), + const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), + const QVariant &arg10 = QVariant()) = 0; + /// Reply from service. + /// @return Service reply. + virtual void replyFromService(); +}; + +#endif // DAPABSTRACTCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9621391163199f9d5c0940f829c141a73f33e0c2 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp @@ -0,0 +1,55 @@ +#include "DapAddWalletCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param apSocket Client connection socket with service. +/// @param parent Parent. +DapAddWalletCommand::DapAddWalletCommand(const QString &asServicename, DapRpcSocket *apSocket, QObject *parent) + : DapAbstractCommand(asServicename, apSocket, parent) +{ + +} + +/// Send a response to the service. +/// @param arg1...arg10 Parameters. +/// @return Reply to service. +QVariant DapAddWalletCommand::respondToService(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, + const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + return QVariant(); +} + +/// Send a response to the client. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapAddWalletCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, + const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + return 5; +} diff --git a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..6fa07f9516d7e5185ec5f1924e30eaedc4e0b442 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** This file is part of the libCellFrameDashboardClient library. +** +** The class implements the "Add wallet" command interface. +** +****************************************************************************/ + +#ifndef DAPADDWALLETCOMMAND_H +#define DAPADDWALLETCOMMAND_H + +#include "DapAbstractCommand.h" + +class DapAddWalletCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param apSocket Client connection socket with service. + /// @param parent Parent. + explicit DapAddWalletCommand(const QString &asServicename, DapRpcSocket *apSocket = nullptr, QObject *parent = nullptr); + +public slots: + /// Send a response to the service. + /// @param arg1...arg10 Parameters. + /// @return Reply to service. + QVariant respondToService(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()); + /// Send a response to the client. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()); +}; + +#endif // DAPADDWALLETCOMMAND_H diff --git a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri index cf5328792504681b6a7642ad7ddc3bf6491edf80..2a3b8fbf4630e39bfb011c8cfcecff90b0e7cb90 100755 --- a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri +++ b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri @@ -18,8 +18,9 @@ SOURCES +=\ $$PWD/DapHistoryType.cpp \ $$PWD/DapSettings.cpp \ $$PWD/DapLogMessage.cpp \ - $$PWD/DapLogModel.cpp \ - $$PWD/DapChainWallet.cpp + $$PWD/DapChainWallet.cpp \ + $$PWD/Handlers/DapAbstractCommand.cpp \ + $$PWD/Handlers/DapAddWalletCommand.cpp HEADERS +=\ $$PWD/DapChainConvertor.h \ @@ -27,6 +28,7 @@ HEADERS +=\ $$PWD/DapHistoryType.h \ $$PWD/DapSettings.h \ $$PWD/DapLogMessage.h \ - $$PWD/DapLogModel.h \ $$PWD/DapChainWallet.h \ - $$PWD/DapNodeType.h + $$PWD/DapNodeType.h \ + $$PWD/Handlers/DapAbstractCommand.h \ + $$PWD/Handlers/DapAddWalletCommand.h