Skip to content
Snippets Groups Projects
Commit af9a4824 authored by Alexander's avatar Alexander Committed by dmitriy.gerasimov
Browse files

Features 2581

parent c0fc3c48
No related branches found
No related tags found
1 merge request!11Cellframe clone
Showing
with 467 additions and 84 deletions
......@@ -10,7 +10,7 @@
#include "DapNodeType.h"
/// The DapChainNodeNetworkExplorer class
/// details Class paiting DapCellFrame map
/// details Class painting DapCellFrame map
/// @warning To use this class it requers to send DapChainNodeNetworkModel model to slot setModel()
class DapChainNodeNetworkExplorer : public QQuickPaintedItem
{
......@@ -25,36 +25,66 @@ class DapChainNodeNetworkExplorer : public QQuickPaintedItem
Q_PROPERTY(DapChainNodeNetworkModel* model READ getModel WRITE setModel NOTIFY modelChanged)
public:
/**
* @brief The DapNodeState enum
* The values are used to display state of nodes
*/
enum DapNodeState {
/// Normal
Normal,
/// Focused
Focused,
/// Selected
Selected
};
/**
* @brief The DapNodeGui struct
* Structure which has state of node and size of area node
*/
struct DapNodeGui {
/// State of node
DapNodeState State;
/// Graphic area node
QRect Rect;
};
private:
/// Model for Network Explorer
DapChainNodeNetworkModel* m_model;
QMap<QString /*Address*/, DapNodeGui /*NodeDataGui*/> m_nodeMap; // node map for gui
QPair<QString /*Address*/, DapNodeGui* /*NodeDataGui*/> m_currentSelectedNode; // selected node
/// node map for gui
QMap<QString /*Address*/, DapNodeGui /*NodeDataGui*/> m_nodeMap;
/// selected node
QPair<QString /*Address*/, DapNodeGui* /*NodeDataGui*/> m_currentSelectedNode;
/// Color online state
QColor m_colorOnline;
/// Color offline state
QColor m_colorOffline;
/// Color selected state
QColor m_colorSelect;
/// Color normal state
QColor m_colorNormal;
/// Color focused state
QColor m_colorFocused;
/// Width of line
int m_widthLine;
/// Size of node
int m_sizeNode;
protected:
/// Event occurs when moused pressed
/// @param event Mouse event
void mousePressEvent(QMouseEvent* event);
/// Event occurs when wheel moves
/// @param event Wheel event
void wheelEvent(QWheelEvent* event);
/// Event occurs when mouse hover under item
/// @param event Hover move
void hoverMoveEvent(QHoverEvent* event);
public:
/// Standard constructor
explicit DapChainNodeNetworkExplorer(QQuickItem *parent = nullptr);
/// Overload method for paiting
void paint(QPainter* painter);
......@@ -134,16 +164,33 @@ public slots:
void setModel(DapChainNodeNetworkModel* aModel);
private slots:
/// Create graph
void proccessCreateGraph();
signals:
/// Signals emitted when select color was changed
/// @param colorSelect Color for select state
void colorSelectChanged(QColor colorSelect);
/// Signals emitted when normal state color was changed
/// @param colorNormal Color for normal state
void colorNormalChanged(QColor colorNormal);
/// Signals emitted when focused state color was changed
/// @param colorActivated Color for focused state
void colorFocusedChanged(QColor colorActivated);
/// Signals emitted when online state color was changed
/// @param colorOnline Color for online state
void colorOnlineChanged(QColor colorOnline);
/// Signals emitted when offline state color was changed
/// @param colorOffline Color for offline state
void colorOfflineChanged(QColor colorOffline);
/// Signals emitted when width line was changed
/// @param widthLine Width of line
void widthLineChanged(int widthLine);
/// Signals emitted when size node was changed
/// @param sizeNode Size of node
void sizeNodeChanged(int sizeNode);
/// Signals emitted when model was changed
/// @param model New model for Network Explorer
void modelChanged(DapChainNodeNetworkModel* model);
/// Signal selected node
......
......@@ -14,20 +14,27 @@ class DapChainNodeNetworkModel : public QObject
Q_OBJECT
private:
/// Data about network with nodes
QVariant m_data;
/// Timer for request
QTimer* m_timerRequest;
protected:
/// Data about whole network with nodes
DapNodeMap m_nodeMap;
public:
/// Standard constructor
explicit DapChainNodeNetworkModel(QObject *parent = nullptr);
/// Get an instance of a class.
/// @return Instance of a class.
Q_INVOKABLE static DapChainNodeNetworkModel &getInstance();
/// Get data about whole network with nodes
/// @return QMap where key is address and value is structure about one node
const DapNodeMap* getDataMap() const;
/// Get data about onde node by address
/// Get data about node by address
/// @param aAddress Address of node
/// @return data's node structure
const DapNodeData* getNodeData(const QString& aAddress) const;
......@@ -35,20 +42,23 @@ public:
/// @return address of current node
QString getCurrentAddress() const;
/// Get status of node
/// @param aAddress Address of node
/// @return It is true if node is online
Q_INVOKABLE bool isNodeOnline(const QString& aAddress) const;
public slots:
/// Receive new network data and repaint the screen
/// @param QMap<QString, QStringList> data of node n
/// @param aData data of node network
void receiveNewNetwork(const QVariant& aData);
/// Receive changes status for nodes
/// @param aData data of node network
void receiveNodeStatus(const QVariant& aData);
/// Send request to service about changing status of node
/// @param aIsOnline set new status to node
Q_INVOKABLE void sendRequestNodeStatus(const bool aIsOnline);
/// Start timer for request new data of network
Q_INVOKABLE void startRequest();
/// @param time in milliseconds for delay
/// @param aTimeout in milliseconds for delay
Q_INVOKABLE void startRequest(const int aTimeout);
/// Stop timer for request data of network
Q_INVOKABLE void stopRequest();
......@@ -59,9 +69,12 @@ signals:
/// Signal for request network
void requestNodeNetwork();
/// Signal for request status of node
/// @param status status of node
void requestNodeStatus(bool status);
/// SIgnal about changing status node
void changeStatusNode(QString node, bool isOnline);
/// @param node Address of node
/// @param aIsOnline new status to node
void changeStatusNode(QString asNode, bool aIsOnline);
};
......
......@@ -11,13 +11,24 @@
#include <QXmlStreamAttribute>
#include <DapChainWallet.h>
/**
* @brief The DapChainWalletRole enum
*
* These values are used in arguments to methods data and roleNames.
* Main goal is return data from selected information about wallet
*/
enum DapChainWalletRole {
/// Icon wallet
IconWalletRole = Qt::DisplayRole,
/// Name of wallet
NameWalletRole = Qt::UserRole,
/// Address of wallet
AddressWalletRole,
/// Balance
BalanceWalletRole,
/// Tokens name
TokensWalletRole,
/// Number of wallets
CountWalletRole
};
......@@ -25,9 +36,10 @@ enum DapChainWalletRole {
class DapChainWalletsModel : public QAbstractListModel
{
Q_OBJECT
/// Set of wallets
QList<DapChainWallet*> m_dapChainWallets;
/// standard constructor
DapChainWalletsModel(QObject* parent = nullptr);
public:
/// Get an instance of a class.
......@@ -35,18 +47,42 @@ public:
Q_INVOKABLE static DapChainWalletsModel &getInstance();
/// Overraid model's methods
/// Get number of wallets
/// @return Number of wallets
int rowCount(const QModelIndex & = QModelIndex()) const;
/// Information about selected wallet by index and which field needs
/// @return Information about wallet
/// @param index Index of wallet
/// @param role Concrete fields about wallet
/// @return Data about concrete field of wallet
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
/// Information about fields of wallet
/// @return Set of fields wallet
QHash<int, QByteArray> roleNames() const;
/// Get data in a row
/// @param row Row of wallet
/// @return Information about wallet selected by row
Q_INVOKABLE QVariantMap get(int row) const;
/// Add new wallet
/// @param arWallet new wallet
Q_INVOKABLE void append(const DapChainWallet &arWallet);
/// Add new wallet
/// @param asIconPath Path icon
/// @param asName Name of wallet
/// @param asAddress Address of wallet
/// @param aBalance Balance
/// @param aTokens Tokens name
Q_INVOKABLE void append(const QString& asIconPath, const QString &asName, const QString &asAddress, const QStringList &aBalance, const QStringList &aTokens);
/// Change data for wallet in a row
/// @param row Row of wallet
/// @param asName Name of wallet
/// @param asAddress Address of wallet
/// @param aBalance Balance
/// @param aTokens Tokens name
Q_INVOKABLE void set(int row, const QString& asIconPath, const QString &asName, const QString &asAddresss, const QStringList &aBalance, const QStringList &aTokens);
/// Remove row with wallet
/// @param row Row of wallet
Q_INVOKABLE void remove(int row);
/// Clear screen
Q_INVOKABLE void clear();
......
......@@ -10,6 +10,7 @@
#include "DapRpcServiceProvider.h"
#include "DapRpcService.h"
/// Class command controller for service
class DapCommandController : public DapRpcService, public DapRpcServiceProvider
{
Q_OBJECT
......@@ -19,38 +20,56 @@ class DapCommandController : public DapRpcService, public DapRpcServiceProvider
/// RPC socket.
DapRpcSocket * m_DAPRpcSocket {nullptr};
signals:
signals:
/// The signal is emitted after receiving a response from the service about the command execution.
void sigCommandResult(QJsonValue );
/// The signal is emitted when node logs are received from the service.
/// @param aNodeLogs List of node logs.
void sigNodeLogsReceived(const QStringList& aNodeLogs);
/// The signal is emitted when new wallet was added
/// @param asWalletName Wallet's name
/// @param asWalletAddress Wallet's address
void sigWalletAdded(const QString& asWalletName, const QString& asWalletAddress);
/// The signal is emitted when token was sent
/// @param asAnswer Answer from service
void onTokenSended(const QString& asAnswer);
/// The signal is emitted when receive current wallets
/// @param aWallets current wallets
void sigWalletsReceived(const QMap<QString, QVariant>& aWallets);
/// The signal is emitted when the main application window is activated.
/// @param aIsActivated Accepts true - when requesting to
/// display a client, falso - when requesting to hide a client.
void onClientActivate(bool aIsActivated);
///
/// The signal is emitted when the main application window closed
void onClientClose();
/// Signal for changing information of wallet
/// @param asWalletName Wallet's name
/// @param asWalletAddress Wallet's address
void sigWalletInfoChanged(const QString& asWalletName, const QString& asWalletAddress, const QStringList& aBalance, const QStringList& aTokens);
/// Signal for data network
/// @param Data network
void sendNodeNetwork(const QVariant& aData);
/// Signal for sending status of node
/// @param Status of node
void sendNodeStatus(const QVariant& aData);
///
/// The signal is emitted when execute command result was changed
/// @param result Result of command
void executeCommandChanged(const QString& result);
/// Signal for changing logs
/// The signal for changing logs
void onChangeLogModel();
/// Signal for sending new transaction history
/// Ths signal for sending new transaction history
/// @param aData New transaction history
void sendHistory(const QVariant& aData);
/// Response from service about command request
/// The signal for response from service about command request
/// @param Responce from service
void responseConsole(const QString& aResponse);
/// Signal about changing history of commands
/// The signal about changing history of commands
/// @param aHistory Changed history of commands
void sigCmdHistory(const QString& aHistory);
/// The signal for send network list
/// @param List of networks
void sendNetworkList(const QStringList& aList);
public:
......@@ -67,25 +86,27 @@ private slots:
void processCommandResult();
/// Handling service response for receiving node logs.
void processGetNodeLogs();
/// Handling service response for add new wallet
void processAddWallet();
/// Handling service response for send token
void processSendToken();
/// Handling service response for get wallets
void processGetWallets();
/// Handling service response for get information about wallet
void processGetWalletInfo();
/// Handling service response for get node network
void processGetNodeNetwork();
/// Handling service response for get node status
void processGetNodeStatus();
/// Handling service response for execute command from service
void processExecuteCommand();
/// Handling service response for get history
void processGetHistory();
/// Handling service response for get list network and send to network model
void processGetNetworkList();
/// Handling service response for send new history operation to console model
void processResponseConsole();
/// Handling service response for changing history of commands
void processGetCmdHistory();
public slots:
......@@ -95,23 +116,34 @@ public slots:
void activateClient(bool aIsActivated);
/// Shut down client.
void closeClient();
/// Send signal for changing log model
void processChangedLog();
/// Add new wallet
/// @param asWalletName Name of new wallet
void addWallet(const QString& asWalletName);
/// Remove wallet
/// @param asWalletName Name of removing wallet
void removeWallet(const QString& asWalletName);
/// Send new token
/// @param asSendWallet Sent wallet
/// @param asAddressReceiver Address of receiver
/// @param asToken Name of token
/// @param aAmount sum for transaction
void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount);
/// Get wallets
void getWallets();
/// Get information about wallet
/// @param asWalletName Name of wallet
void getWalletInfo(const QString& asWalletName);
/// Get node network for explorer
void getNodeNetwork();
/// Request about new network list
void getNetworkList();
/// Set new status for node
/// @param aIsOnline New status for node
void setNodeStatus(const bool aIsOnline);
/// Execute command
/// @param command Command for executing
void executeCommand(const QString& command);
/// Get node logs.
......@@ -120,12 +152,15 @@ public slots:
/// Get transaction history
void getHistory();
/// Send to model new history
/// @param aData New history transaction
void setNewHistory(const QVariant& aData);
/// Commands request
/// @param aQueue Result for command
void requestConsole(const QString& aQueue);
/// Get command history
void getCmdHistory();
/// Change current network
/// @param name of network which was selected
void changeCurrentNetwork(const QString& aNetwork);
};
......
......@@ -6,20 +6,28 @@
#include "DapUiQmlWidgetModel.h"
/// Class of screen dialog. Can filtered different models
class DapScreenDialog : public QObject
{
Q_OBJECT
/// Pointer to current filter proxy model
QSortFilterProxyModel *m_proxyModel;
public:
/// Standard constructor
explicit DapScreenDialog(QObject *parent = nullptr);
Q_PROPERTY(QSortFilterProxyModel* ProxyModel MEMBER m_proxyModel READ proxyModel WRITE setProxyModel NOTIFY proxyModelChanged)
/// Get current filter of proxy model
/// @return Pointer to current filter of proxy model
QSortFilterProxyModel *proxyModel() const;
/// Setn new proxy model
/// @param proxyModel New current filter of proxy model
void setProxyModel(QSortFilterProxyModel *proxyModel);
signals:
/// The signal is emitted when filter of proxy model was changed
/// @param proxyModel New current filter of proxy model
void proxyModelChanged(QSortFilterProxyModel *proxyModel);
public slots:
};
......
......@@ -6,19 +6,26 @@
#include "DapUiQmlWidgetModel.h"
/// Class of dialog change widget
class DapScreenDialogChangeWidget : public QObject
{
Q_OBJECT
/// Pointer to current filter proxy model
QSortFilterProxyModel *m_proxyModel;
public:
/// Standard constructor
explicit DapScreenDialogChangeWidget(QObject *parent = nullptr);
Q_PROPERTY(QSortFilterProxyModel* ProxyModel MEMBER m_proxyModel READ proxyModel WRITE setProxyModel NOTIFY proxyModelChanged)
/// Get current filter of proxy model
/// @return Pointer to current filter of proxy model
QSortFilterProxyModel *proxyModel() const;
/// Setn new proxy model
/// @param proxyModel New current filter of proxy model
void setProxyModel(QSortFilterProxyModel *proxyModel);
signals:
/// The signal is emitted when filter of proxy model was changed
/// @param proxyModel New current filter of proxy model
void proxyModelChanged(QSortFilterProxyModel *proxyModel);
public slots:
};
......
......@@ -5,14 +5,19 @@
#include "DapScreenHistoryModel.h"
/// Class screen of history transaction
class DapScreenHistoryFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
/// Number of wallet
QString m_walletNumber;
/// Minimum date
QDate m_dateLeft;
/// Maximum date
QDate m_dateRight;
/// Filter status
int m_status;
protected:
......@@ -34,7 +39,7 @@ public slots:
/// @param Min date
/// @param Max date
void setFilterDate(const QDate& aDateLeft, const QDate& aDateRight);
/// Filter with status of transacrion
/// Filter with status of transaction
/// @param status of transaction
void setFilterStatus(const DapTransactionStatus aStatus);
};
......
......@@ -35,7 +35,7 @@ class DapServiceController : public QObject
DapServiceClient *m_pDapServiceClient {nullptr};
/// RPC protocol controller.
DapCommandController *m_pDapCommandController {nullptr};
/// Standard constructor
explicit DapServiceController(QObject *apParent = nullptr);
public:
......@@ -76,9 +76,6 @@ public:
void getNodeLogs(int aiTimeStamp, int aiRowCount) const;
/// Get wallets
Q_INVOKABLE void getWallets() const;
DapLogModel getLogModel() const;
void setLogModel(const DapLogModel &dapLogModel);
/// Add new wallet
/// @param wallet
Q_INVOKABLE void addWallet(const QString& asWalletName);
......@@ -86,6 +83,8 @@ public:
Q_INVOKABLE void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount);
Q_INVOKABLE void executeCommand(const QString& command);
/// Get information about wallet
/// @param name of wallet
void getWalletInfo(const QString& asWalletName);
/// Request about new netowrk list
void getNetworkList();
......@@ -94,17 +93,24 @@ public:
signals:
/// The signal is emitted when the Brand company property changes.
/// @param asBrand Brand
void brandChanged(const QString &brand);
/// The signal is emitted when the Application version property changes.
/// @param version Version
void versionChanged(const QString &version);
/// The signal is emitted when the result execute property changes.
void resultChanged();
/// The signal is emitted when the main application window is activated.
void activateWindow();
/// The signal is emitted when checking the existence of an already running copy of the application.
/// @param isExistenceClient True if after checking client is exist. False when not
void isExistenceClient(bool isExistenceClient);
/// The signal is emitted when sending to QML
void sendToQML(QString);
/// The signal is emitted when log message append to log model or logs was cleared
void logCompleted();
/// Signal for data network
/// @param aData Data network
void sendNodeNetwork(const QVariant& aData);
void userSettingsLoaded();
void userSettingsSaved();
......@@ -113,19 +119,29 @@ private slots:
/// Handling service response for receiving node logs.
/// @param aNodeLogs List of node logs.
void processGetNodeLogs(const QStringList& aNodeLogs);
/// Handling service response for add new wallet
/// @param asWalletName Name of wallet
/// @param asWalletAddress Address of wallet
void processAddWallet(const QString& asWalletName, const QString& asWalletAddress);
// TODO: Implement logic to proccess.
/// Handling service response for send new token
/// @param asAnswer Answer
void processSendToken(const QString& asAnswer);
/// Handling service response for get wallets
/// @param aWallets Wallets
void processGetWallets(const QMap<QString, QVariant>& aWallets);
/// Handling service response for get information about selected wallet
/// @param asWalletName Name of wallet
/// @param asWalletAddress Address of wallet
void processGetWalletInfo(const QString& asWalletName, const QString& asWalletAddress, const QStringList &aBalance, const QStringList& aTokens);
/// Handling service response for write information of result executing command
/// @param result Result executing information
void processExecuteCommandInfo(const QString& result);
/// Handling service response for get node network
/// @param aData Data of node network
void processGetNodeNetwork(const QVariant& aData);
/// Handling service response for get transaction history
/// @param Data of history
void processGetHistory(const QVariant& aData);
public slots:
......
......@@ -7,14 +7,17 @@
#include <QFile>
#include <QDir>
/// Class of recipient history commands
class DapChainConsoleHandler : public QObject
{
Q_OBJECT
private:
/// System file
QFile * m_File;
public:
/// Standard constructor
explicit DapChainConsoleHandler(QObject *parent = nullptr);
/// Get history of commands
......
......@@ -34,6 +34,19 @@
typedef class DapRpcLocalServer DapUiService;
typedef class QLocalServer DapUiSocketServer;
/**
* @brief The DapChainDashboardService 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
* @see DapChainWalletHandler
* @see DapChainNodeNetworkHandler
* @see DapChainHistoryHandler
* @see DapChainConsoleHandler
* @see DapChainNetworkHandler
*/
class DapChainDashboardService : public DapRpcService
{
Q_OBJECT
......@@ -42,9 +55,9 @@ class DapChainDashboardService : public DapRpcService
DapUiService * m_pServer {nullptr};
/// Socket of client connection with the service.
DapUiSocketServer * m_pSocketService {nullptr};
/// Log reader.
/// Recipient logs information
DapChainLogHandler * m_pDapChainLogHandler {nullptr};
/// Recipient wallet inforamtion
/// Recipient wallet information
DapChainWalletHandler * m_pDapChainWalletHandler {nullptr};
/// Recipient node network
DapChainNodeNetworkHandler * m_pDapChainNodeHandler {nullptr};
......@@ -52,13 +65,13 @@ class DapChainDashboardService : public DapRpcService
DapChainHistoryHandler* m_pDapChainHistoryHandler {nullptr};
/// Recipient history of commands
DapChainConsoleHandler* m_pDapChainConsoleHandler {nullptr};
/// Recipient network's name
DapChainNetworkHandler* m_pDapChainNetworkHandler {nullptr};
public:
/// Standard сonstructor.
explicit DapChainDashboardService();
/// Start service: creating server and socket
bool start();
signals:
......@@ -69,6 +82,7 @@ signals:
void onSaveSetting();
public slots:
/// Change log model
void changedLogModel();
/// Activate the main client window by double-clicking the application icon in the system tray.
/// @param reason Type of action on the icon in the system tray.
......@@ -124,7 +138,10 @@ public slots:
QString getCmdHistory() const;
private slots:
/// Request new history request by handle wallet's name
void doRequestWallets();
/// Send new history transaction to client
/// @param New history transaction
void doSendNewHistory(const QVariant& aData);
};
......
......@@ -11,6 +11,7 @@
#include "DapLogMessage.h"
/// Class read logs from system file when it's changed
class DapChainLogHandler : public QObject
{
Q_OBJECT
......@@ -20,13 +21,17 @@ class DapChainLogHandler : public QObject
/// Current caret position in log file
qint64 m_currentCaretPosition{0};
public:
/// Standard constructor
/// Add path to system logs file
explicit DapChainLogHandler(QObject *parent = nullptr);
signals:
void onUpdateModel();
/// The signal is emitted when system logs file was changed
void onChangedLog();
public slots:
/// Request new logs from system logs file
/// @return list of new logs
QStringList request();
};
......
......@@ -7,14 +7,17 @@
#include <QFile>
/// Class provides to get network's name list
class DapChainNetworkHandler : public QObject
{
Q_OBJECT
private:
/// List of network's name
QStringList m_NetworkList;
public:
/// Standard constructor
explicit DapChainNetworkHandler(QObject *parent = nullptr);
/// Get network list
......
......@@ -9,14 +9,17 @@
#include "DapNodeType.h"
/// Class provides to operations with nodes of network
class DapChainNodeNetworkHandler : public QObject
{
Q_OBJECT
private:
/// Current network's name
QString m_CurrentNetwork;
public:
/// Standard constructor
explicit DapChainNodeNetworkHandler(QObject *parent = nullptr);
public:
......
......@@ -6,17 +6,23 @@
#include <QRegExp>
#include <QDebug>
/// Class provides operations at wallets
class DapChainWalletHandler : public QObject
{
Q_OBJECT
private:
/// Current network's name
QString m_CurrentNetwork;
protected:
/// Parse address of wallet from console command
/// @param aWalletAddress Console command to create new wallet's address
/// @return Address of wallet
virtual QString parse(const QByteArray& aWalletAddress);
public:
/// Standard constructor
explicit DapChainWalletHandler(QObject *parent = nullptr);
signals:
......
......@@ -8,23 +8,45 @@
#include "DapRpcMessage.h"
#include "DapRpcServiceProvider.h"
/**
* @brief The DapRpcAbstractServer class
* Class of abstract RPC server. Include information about all clients
* Server can send/receive message to/from client by RPC protocol
*/
class DapRpcAbstractServer : public DapRpcServiceProvider
{
protected:
/// List of clients
QList<DapRpcSocket*> m_clients;
public:
/// Standard constructor
DapRpcAbstractServer();
/// Virtual destructor
virtual ~DapRpcAbstractServer();
/// Connected clients count
/// @return Clients count
virtual int connectedClientCount() const;
/// Tells to server to listen incoming connections on address and port.
/// @param asAddress Address
/// @param aPort Port
/// @return If Server is currently listening then it will return false.
/// Otherwise return true.
virtual bool listen(const QString &asAddress = QString(), quint16 aPort = 0) = 0;
// signals:
/// The signal is emitted when client was connected
virtual void onClientConnected() = 0;
/// The signal is emitted when client was disconnected
virtual void onClientDisconnected() = 0;
// public slots:
/// Notify connected clients. Send all message
/// @param message Message to client
virtual void notifyConnectedClients(const DapRpcMessage &message);
/// Notify connected clients. Send all message
/// @param method Method which clients were notified
/// @param params Parameters of message in JSON format
virtual void notifyConnectedClients(const QString &method, const QJsonArray &params);
};
......
......@@ -9,35 +9,67 @@
#include "DapRpcService.h"
#include "DapRpcAbstractServer.h"
/**
* @brief The DapRpcLocalServer class
* Local RPC server. inheritance from DapRpcAbstractServer
* @see DapRpcAbstractServer
* @see QLocalServer
*/
class DapRpcLocalServer : public QLocalServer, public DapRpcAbstractServer
{
Q_OBJECT
Q_DISABLE_COPY(DapRpcLocalServer)
/// Hash map socket lookups. LocalSocket according to RPC socket
QHash<QLocalSocket*, DapRpcSocket*> m_socketLookup;
protected:
/// Call when new connection is available
/// @param aSocketDescriptor SocketDescriptor is the native socket descriptor for the accepted connection
virtual void incomingConnection(quintptr aSocketDescriptor);
public:
/// Standard constructor
explicit DapRpcLocalServer(QObject *apParent = nullptr);
/// Virtual overrided descriptor
virtual ~DapRpcLocalServer();
/// Tells to server to listen incoming connections on address and port.
/// @param asAddress Address
/// @param aPort Port
/// @return If Server is currently listening then it will return false.
/// Otherwise return true.
virtual bool listen(const QString &asAddress = QString(), quint16 aPort = 0);
/// Add new service
/// @param apService New service
/// @return If service add successfully return true. Otherwise return false
bool addService(DapRpcService *apService);
/// Remove service
/// @param apService Service for removing
/// @return If service add successfully return true. Otherwise return false
bool removeService(DapRpcService *apService);
signals:
/// The signal is emitted when client was connected
void onClientConnected();
/// The signal is emitted when client was disconnected
void onClientDisconnected();
private slots:
/// Calls when client disconnected
void clientDisconnected();
/// When receive message from client prepare message by type of message
/// @param asMessage Message
void messageProcessing(const DapRpcMessage &asMessage);
// DapRpcAbstractServer interface
public slots:
/// Notify connected clients. Send all message
/// @param message Message to client
void notifyConnectedClients(const DapRpcMessage &message);
/// Notify connected clients. Send all message
/// @param method Method which clients were notified
/// @param params Parameters of message in JSON format
void notifyConnectedClients(const QString &method, const QJsonArray &params);
};
......
......@@ -11,81 +11,168 @@
#define qJsonRpcDebug if (qgetenv("QJSONRPC_DEBUG").isEmpty()); else qDebug
/**
* @brief The DapErrorCode enum
* This enum values are used to mark code of error
*/
enum DapErrorCode {
NoError = 0,
ParseError = -32700, // Invalid JSON was received by the server.
// An error occurred on the server while parsing the JSON text.
InvalidRequest = -32600, // The JSON sent is not a valid Request object.
MethodNotFound = -32601, // The method does not exist / is not available.
InvalidParams = -32602, // Invalid method parameter(s).
InternalError = -32603, // Internal JSON-RPC error.
ServerErrorBase = -32000, // Reserved for implementation-defined server-errors.
UserError = -32099, // Anything after this is user defined
TimeoutError = -32100
NoError = 0, ///< No error
ParseError = -32700, /*!< Invalid JSON was received by the server.
An error occurred on the server while parsing the JSON text. */
InvalidRequest = -32600, ///< The JSON sent is not a valid Request object.
MethodNotFound = -32601, ///< The method does not exist / is not available.
InvalidParams = -32602, ///< Invalid method parameter(s).
InternalError = -32603, ///< Internal JSON-RPC error.
ServerErrorBase = -32000, ///< Reserved for implementation-defined server-errors.
UserError = -32099, ///< Anything after this is user defined
TimeoutError = -32100 ///< Timeout
};
Q_DECLARE_METATYPE(DapErrorCode)
class DapRpcMessagePrivate;
/// Class of message type by RPC protocol
class DapRpcMessage
{
friend class DapRpcMessagePrivate;
QSharedDataPointer<DapRpcMessagePrivate> d;
public:
/// Standard constructor
DapRpcMessage();
/// Copy constructor
/// @param aDapRPCMessage Other message
DapRpcMessage(const DapRpcMessage &aDapRPCMessage);
/// Assignment operator
/// @param aDapRPCMessage Other message
/// @return RPC message
DapRpcMessage &operator=(const DapRpcMessage &aDapRPCMessage);
/// Standard destructor
~DapRpcMessage();
/// Swap message
/// @param aDapRPCMessage Swaped message
inline void swap(DapRpcMessage &aDapRPCMessage) { qSwap(d, aDapRPCMessage.d); }
/**
* @brief The Type enum
* Type of message
*/
enum Type {
Invalid,
Request,
Response,
Notification,
Error
Invalid, ///< Invalid
Request, ///< Request
Response, ///< Responce
Notification, ///< Notification
Error ///< Error
};
/// Create new request message
/// @param asMethod Remote method
/// @param aParams Params message in format JsonArray
/// @return aParams New RPC message
static DapRpcMessage createRequest(const QString &asMethod, const QJsonArray &aParams = QJsonArray());
/// Create new request message
/// @param asMethod Remote method
/// @param aParams Params message in format JsonValue
/// @return aParam New RPC message
static DapRpcMessage createRequest(const QString &asMethod, const QJsonValue &aParam);
/// Create new request message
/// @param asMethod Remote method
/// @param aNamedParameters Named params message in format JsonObject
/// @return New RPC message
static DapRpcMessage createRequest(const QString &asMethod, const QJsonObject &aNamedParameters);
/// Create new request message
/// @param asMethod Remote method
/// @param aStream Message stream
/// @return New RPC message
static DapRpcMessage createRequest(const QString &asMethod, const QByteArray& aStream);
/// Create new notification message
/// @param asMethod Remote method
/// @param aParams Params message in format JsonArray.
/// @return aParams New RPC message
static DapRpcMessage createNotification(const QString &asMethod, const QJsonArray &aParams = QJsonArray());
/// Create new notification message
/// @param asMethod Remote method
/// @param aParams Params message in format JsonValue
/// @return aParam New RPC message
static DapRpcMessage createNotification(const QString &asMethod, const QJsonValue &aParam);
/// Create new notification message
/// @param asMethod Remote method
/// @param aNamedParameters Named params message in format JsonObject
/// @return New RPC message
static DapRpcMessage createNotification(const QString &asMethod, const QJsonObject &aNamedParameters);
/// Create new notification message
/// @param asMethod Remote method
/// @param aStream Message stream
/// @return New RPC message
static DapRpcMessage createNotification(const QString &asMethod, const QByteArray& aStream);
/// Create new response message
/// @param aResult Result of operation
/// @return aParams Response RPC message
DapRpcMessage createResponse(const QJsonValue &aResult) const;
/// Create new error responce
/// @param aCode Code of error
/// @see DapErrorCode
/// @param asMessage Message
/// @param aData Data of message
/// @return Rpc message
DapRpcMessage createErrorResponse(DapErrorCode aCode,
const QString &asMessage = QString(),
const QJsonValue &aData = QJsonValue()) const;
const QString &asMessage = QString(),
const QJsonValue &aData = QJsonValue()) const;
/// Get type of message
/// @return Type of message
DapRpcMessage::Type type() const;
/// Validation of message
/// @return True if message is valid. False otherwise
bool isValid() const;
/// Get id message
/// @return id message
int id() const;
// request
/// Remote method from request message
/// @return Remote method
QString method() const;
/// Params from request message
/// @return Params of message as JsonValue
QJsonValue params() const;
// response
/// Get result of response message
/// @return Result of response message as JsonValue
QJsonValue toJsonValue() const;
/// Get result of response message
/// @return Result of response message as yteArray
QByteArray toByteArray() const;
// error
/// Get error code. @see DapErrorCode
/// @return Error code
int errorCode() const;
/// Get text of error message
/// @return Text of error message. If message isn't error type return default string;
QString errorMessage() const;
/// Get data of error message
/// @return Data of error. If message isn't error type return default JsonValue
QJsonValue errorData() const;
/// Convert message to JsonObject
/// @return Message as JsonObject
QJsonObject toObject() const;
/// Static method to convert JsonObject to Rpc message
/// @param aObject Message as JsonObject
/// @return Converted message
static DapRpcMessage fromObject(const QJsonObject &aObject);
/// Serilize message
/// @return Message as byte array
QByteArray toJson() const;
/// Static method to convert serilisation message to Rpc message
/// @param aData Data of message
/// @return Converted message
static DapRpcMessage fromJson(const QByteArray &aData);
/// Overloaded relational operator (equal)
/// @param aDapRpcMessage Other message
/// @return True if equal and false when not
bool operator==(const DapRpcMessage &aDapRpcMessage) const;
/// Overloaded relational operator (not equal)
/// @param aDapRpcMessage Other message
/// @return True if not equal and false when yes
inline bool operator!=(const DapRpcMessage &aDapRpcMessage) const { return !(operator==(aDapRpcMessage)); }
};
......
......@@ -10,19 +10,39 @@
#include "DapRpcService.h"
/**
* @brief The DapRpcServiceProvider class
* Class provides to add/remove services and store them.
*/
class DapRpcServiceProvider
{
/// Store pointers to service by the name
QHash<QByteArray, DapRpcService*> m_services;
/// Handle service to cleanup
QObjectCleanupHandler m_cleanupHandler;
protected:
/// Standard constructor
DapRpcServiceProvider();
/// Process message to send by socket interface
/// @param apSocket Remote socket
/// aMessage Rpc message
void processMessage(DapRpcSocket *apSocket, const DapRpcMessage &aMessage);
public:
/// Virtual destructor
virtual ~DapRpcServiceProvider();
/// Add new service
/// @param apService New service
/// @return True if service add successfullym false if not
virtual bool addService(DapRpcService *apService);
/// Remove existing service
/// @param apService Service to remove
/// @return If service alreade removing or not existing return false, else return true
virtual bool removeService(DapRpcService *apService);
/// Get service name
/// @param apService Service
/// @return Serilization name of service
QByteArray getServiceName(DapRpcService *apService);
};
......
......@@ -6,24 +6,42 @@
#include "DapRpcMessage.h"
/**
* @brief The DapRpcServiceReply class
* Class provides service reply from sender.
* Class has methods to operate with response and request
*/
class DapRpcServiceReply : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(DapRpcServiceReply)
/// Request message
DapRpcMessage m_request;
/// Response message
DapRpcMessage m_response;
public:
/// Standard constructor
explicit DapRpcServiceReply(QObject *apParent = nullptr);
/// Virtual destructor
virtual ~DapRpcServiceReply();
/// Get request message
/// @return Request message
DapRpcMessage request() const;
/// Get response message
/// @return Response message
DapRpcMessage response() const;
/// Set request message
/// @param aRequest New request message
void setRequest(const DapRpcMessage &aRequest);
/// Set response message
/// @param aResponse Responce message
void setResponse(const DapRpcMessage &aResponse);
signals:
/// The signal is emitted when reply finished
void finished();
};
......
#include "DapChainWallet.h"
DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddresss, const QStringList &aBalance, const QStringList &aTokens, QObject *parent)
: QObject(parent), m_sIconPath(asIconPath), m_sName(asName), m_sAddress(asAddresss), m_balance(aBalance), m_tokens(aTokens)
DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddress, const QStringList &aBalance, const QStringList &aTokens, QObject *parent)
: QObject(parent), m_sIconPath(asIconPath), m_sName(asName), m_sAddress(asAddress), m_balance(aBalance), m_tokens(aTokens)
{
}
DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddresss, QObject *parent)
: DapChainWallet(asIconPath, asName, asAddresss, QStringList(), QStringList(), parent)
DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddress, QObject *parent)
: DapChainWallet(asIconPath, asName, asAddress, QStringList(), QStringList(), parent)
{
}
......
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