Skip to content
Snippets Groups Projects
Commit a51c9c11 authored by andrey.daragan's avatar andrey.daragan
Browse files

Merge branch 'features-2871' into 'develop'

Features 2871

See merge request !72
parents 0ab71046 f2b2ac4d
No related branches found
No related tags found
1 merge request!72Features 2871
Pipeline #1601 passed with stage
in 15 minutes and 32 seconds
Showing
with 389 additions and 321 deletions
......@@ -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 \
......
#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);
}
#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
......@@ -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();
}
......@@ -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.
......
import QtQuick 2.4
DapDashboardTopPanelForm {
testButton.onClicked: dapServiceController.requestToService("ADD", 5)
}
import QtQuick 2.4
import QtQuick.Controls 2.0
import "../../"
DapAbstractTopPanel
{
property alias testButton: button
Button
{
id: button
anchors.fill: parent
text: "Press"
}
}
......
......@@ -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)
......
......@@ -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;
}
#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));
}
......@@ -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
......@@ -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();
......
......@@ -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)
{
}
......
......@@ -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);
......
......@@ -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()));
......
#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 &timestamp, 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 &timestamp, 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();
}
#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 &timestamp, 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 &timestamp, 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
#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());
}
/****************************************************************************
**
** 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
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment