From af9a48243165bc3046376a358e48a7f1a99bcf45 Mon Sep 17 00:00:00 2001 From: Alexander <aleksandr.martynov@demlabs.net> Date: Wed, 16 Oct 2019 06:20:52 -0400 Subject: [PATCH] Features 2581 --- .../DapChainNodeNetworkExplorer.h | 53 ++++++- .../DapChainNodeNetworkModel.h | 21 ++- CellFrameDashboardGUI/DapChainWalletsModel.h | 40 ++++- CellFrameDashboardGUI/DapCommandController.h | 87 +++++++---- CellFrameDashboardGUI/DapScreenDialog.h | 10 +- .../DapScreenDialogChangeWidget.h | 11 +- .../DapScreenHistoryFilterModel.h | 7 +- CellFrameDashboardGUI/DapServiceController.h | 38 +++-- .../DapChainConsoleHandler.h | 3 + .../DapChainDashboardService.h | 25 +++- .../DapChainLogHandler.h | 7 +- .../DapChainNetworkHandler.h | 3 + .../DapChainNodeNetworkHandler.h | 3 + .../DapChainWalletHandler.h | 6 + DapRPCProtocol/DapRpcAbstractServer.h | 22 +++ DapRPCProtocol/DapRpcLocalServer.h | 32 ++++ DapRPCProtocol/DapRpcMessage.h | 137 ++++++++++++++---- DapRPCProtocol/DapRpcServiceProvider.h | 20 +++ DapRPCProtocol/DapRpcServiceReply.h | 18 +++ .../DapChainWallet.cpp | 8 +- libCellFrameDashboardCommon/DapChainWallet.h | 37 ++++- libCellFrameDashboardCommon/DapLogMessage.cpp | 26 ++-- libCellFrameDashboardCommon/DapLogMessage.h | 54 +++++-- libCellFrameDashboardCommon/DapLogModel.h | 41 +++++- 24 files changed, 598 insertions(+), 111 deletions(-) diff --git a/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.h b/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.h index e0a8196..6e90980 100644 --- a/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.h +++ b/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.h @@ -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 diff --git a/CellFrameDashboardGUI/DapChainNodeNetworkModel.h b/CellFrameDashboardGUI/DapChainNodeNetworkModel.h index 261258e..236041c 100644 --- a/CellFrameDashboardGUI/DapChainNodeNetworkModel.h +++ b/CellFrameDashboardGUI/DapChainNodeNetworkModel.h @@ -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); }; diff --git a/CellFrameDashboardGUI/DapChainWalletsModel.h b/CellFrameDashboardGUI/DapChainWalletsModel.h index 74ff829..c622c5a 100755 --- a/CellFrameDashboardGUI/DapChainWalletsModel.h +++ b/CellFrameDashboardGUI/DapChainWalletsModel.h @@ -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(); diff --git a/CellFrameDashboardGUI/DapCommandController.h b/CellFrameDashboardGUI/DapCommandController.h index a8dd9ff..b0d52eb 100755 --- a/CellFrameDashboardGUI/DapCommandController.h +++ b/CellFrameDashboardGUI/DapCommandController.h @@ -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); }; diff --git a/CellFrameDashboardGUI/DapScreenDialog.h b/CellFrameDashboardGUI/DapScreenDialog.h index 0397948..9c06463 100644 --- a/CellFrameDashboardGUI/DapScreenDialog.h +++ b/CellFrameDashboardGUI/DapScreenDialog.h @@ -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: }; diff --git a/CellFrameDashboardGUI/DapScreenDialogChangeWidget.h b/CellFrameDashboardGUI/DapScreenDialogChangeWidget.h index ed0d1da..d1c4dce 100644 --- a/CellFrameDashboardGUI/DapScreenDialogChangeWidget.h +++ b/CellFrameDashboardGUI/DapScreenDialogChangeWidget.h @@ -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: }; diff --git a/CellFrameDashboardGUI/DapScreenHistoryFilterModel.h b/CellFrameDashboardGUI/DapScreenHistoryFilterModel.h index 5753a5c..85bddba 100644 --- a/CellFrameDashboardGUI/DapScreenHistoryFilterModel.h +++ b/CellFrameDashboardGUI/DapScreenHistoryFilterModel.h @@ -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); }; diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index a7bf7ae..1d8b300 100755 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -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: diff --git a/CellFrameDashboardService/DapChainConsoleHandler.h b/CellFrameDashboardService/DapChainConsoleHandler.h index faaced1..0ba265e 100644 --- a/CellFrameDashboardService/DapChainConsoleHandler.h +++ b/CellFrameDashboardService/DapChainConsoleHandler.h @@ -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 diff --git a/CellFrameDashboardService/DapChainDashboardService.h b/CellFrameDashboardService/DapChainDashboardService.h index 5b3ce78..3e246b7 100755 --- a/CellFrameDashboardService/DapChainDashboardService.h +++ b/CellFrameDashboardService/DapChainDashboardService.h @@ -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); }; diff --git a/CellFrameDashboardService/DapChainLogHandler.h b/CellFrameDashboardService/DapChainLogHandler.h index 8f0fb75..78d67fd 100644 --- a/CellFrameDashboardService/DapChainLogHandler.h +++ b/CellFrameDashboardService/DapChainLogHandler.h @@ -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(); }; diff --git a/CellFrameDashboardService/DapChainNetworkHandler.h b/CellFrameDashboardService/DapChainNetworkHandler.h index 515cd22..c3e84c7 100644 --- a/CellFrameDashboardService/DapChainNetworkHandler.h +++ b/CellFrameDashboardService/DapChainNetworkHandler.h @@ -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 diff --git a/CellFrameDashboardService/DapChainNodeNetworkHandler.h b/CellFrameDashboardService/DapChainNodeNetworkHandler.h index 258ab1e..6a38ab1 100644 --- a/CellFrameDashboardService/DapChainNodeNetworkHandler.h +++ b/CellFrameDashboardService/DapChainNodeNetworkHandler.h @@ -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: diff --git a/CellFrameDashboardService/DapChainWalletHandler.h b/CellFrameDashboardService/DapChainWalletHandler.h index 3f8f4a5..c490388 100755 --- a/CellFrameDashboardService/DapChainWalletHandler.h +++ b/CellFrameDashboardService/DapChainWalletHandler.h @@ -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: diff --git a/DapRPCProtocol/DapRpcAbstractServer.h b/DapRPCProtocol/DapRpcAbstractServer.h index 56fa07d..c57deb2 100644 --- a/DapRPCProtocol/DapRpcAbstractServer.h +++ b/DapRPCProtocol/DapRpcAbstractServer.h @@ -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 ¶ms); }; diff --git a/DapRPCProtocol/DapRpcLocalServer.h b/DapRPCProtocol/DapRpcLocalServer.h index 9d7a7e7..3b76556 100644 --- a/DapRPCProtocol/DapRpcLocalServer.h +++ b/DapRPCProtocol/DapRpcLocalServer.h @@ -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 ¶ms); }; diff --git a/DapRPCProtocol/DapRpcMessage.h b/DapRPCProtocol/DapRpcMessage.h index 489ae57..7865306 100644 --- a/DapRPCProtocol/DapRpcMessage.h +++ b/DapRPCProtocol/DapRpcMessage.h @@ -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)); } }; diff --git a/DapRPCProtocol/DapRpcServiceProvider.h b/DapRPCProtocol/DapRpcServiceProvider.h index 6e74d30..e1d873b 100644 --- a/DapRPCProtocol/DapRpcServiceProvider.h +++ b/DapRPCProtocol/DapRpcServiceProvider.h @@ -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); }; diff --git a/DapRPCProtocol/DapRpcServiceReply.h b/DapRPCProtocol/DapRpcServiceReply.h index 2916114..c608ab9 100644 --- a/DapRPCProtocol/DapRpcServiceReply.h +++ b/DapRPCProtocol/DapRpcServiceReply.h @@ -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(); }; diff --git a/libCellFrameDashboardCommon/DapChainWallet.cpp b/libCellFrameDashboardCommon/DapChainWallet.cpp index d2b43c6..22c7cb3 100755 --- a/libCellFrameDashboardCommon/DapChainWallet.cpp +++ b/libCellFrameDashboardCommon/DapChainWallet.cpp @@ -1,13 +1,13 @@ #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) { } diff --git a/libCellFrameDashboardCommon/DapChainWallet.h b/libCellFrameDashboardCommon/DapChainWallet.h index cbfd124..d198ff3 100755 --- a/libCellFrameDashboardCommon/DapChainWallet.h +++ b/libCellFrameDashboardCommon/DapChainWallet.h @@ -8,17 +8,34 @@ class DapChainWallet : public QObject { Q_OBJECT + /// Icon path QString m_sIconPath; + /// Name of wallet QString m_sName; + /// Address of wallet QString m_sAddress; + /// Balance QStringList m_balance; + /// Tokens name QStringList m_tokens; + /// number of tokens int m_iCount; public: + /// Standard constructor DapChainWallet(QObject *parent = nullptr) { Q_UNUSED(parent)} - DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddresss, const QStringList &aBalance, const QStringList& aTokens, QObject * parent = nullptr); - DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddresss, QObject * parent = nullptr); + /// overloaded constructor + /// @param asIconPath Path icon + /// @param asName Name of wallet + /// @param asAddresss Address for wallet + /// @param aBalance Balance + /// @param aTokens Tokens name + DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddress, const QStringList &aBalance, const QStringList& aTokens, QObject * parent = nullptr); + /// overloaded constructor + /// @param asIconPath Path icon + /// @param asName Name of wallet + /// @param asAddresss Address for wallet + DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddress, QObject * parent = nullptr); Q_PROPERTY(QString iconPath MEMBER m_sIconPath READ getIconPath WRITE setIconPath NOTIFY iconPathChanged) @@ -29,17 +46,23 @@ public: Q_PROPERTY(int count MEMBER m_iCount READ getCount) /// Get name of wallet + /// @return name of wallet QString getName() const; - /// Set name for wallet + /// Set name of wallet + /// @param asName name of wallet void setName(const QString &asName); /// Get address of wallet + /// @return Address of wallet QString getAddress() const; /// Set address for wallet + /// @param asAddress address for wallet void setAddress(const QString &asAddress); /// Get icon path + /// @return Icon path QString getIconPath() const; /// Set icon path + /// @param asIconPath Icon path void setIconPath(const QString &asIconPath); /// Get balance @@ -48,23 +71,31 @@ public: void setBalance(const QStringList& aBalance); /// Get tokens name + /// @return tokens name QStringList getTokens() const; /// Set tokens name + /// @param aTokens tokens name void setTokens(const QStringList& aTokens); /// get number of tokens + /// @return number of tokens int getCount() const; signals: /// Signal changes for icon path + /// @param asIconPath Icon path void iconPathChanged(const QString& asIconPath); /// Signal changes for name of wallet + /// @param asName name of wallet void nameChanged(const QString& asName); /// Signal changes for address of wallet + /// @param asAddress address of wallet void addressChanged(const QString& asAddress); /// Signal changes for balance + /// @param aBalance balance void balanceChanged(const QStringList& aBalance); /// Signal changes for tokens + /// @param aTokens tokens name void tokensChanged(const QStringList& aTokens); }; diff --git a/libCellFrameDashboardCommon/DapLogMessage.cpp b/libCellFrameDashboardCommon/DapLogMessage.cpp index 28fc7df..9899438 100644 --- a/libCellFrameDashboardCommon/DapLogMessage.cpp +++ b/libCellFrameDashboardCommon/DapLogMessage.cpp @@ -1,11 +1,11 @@ #include "DapLogMessage.h" -DapLogMessage::DapLogMessage(const QString &type, const QString ×tamp, const QString &file, const QString &message, QObject *parent) : QObject(parent) +DapLogMessage::DapLogMessage(const QString &asType, const QString &asTimestamp, const QString &asFile, const QString &asMessage, QObject *parent) : QObject(parent) { - m_type = type; - m_sTimeStamp = timestamp; - m_sFile = file; - m_sMessage = message; + m_type = asType; + m_sTimeStamp = asTimestamp; + m_sFile = asFile; + m_sMessage = asMessage; } QString DapLogMessage::getType() const @@ -13,9 +13,9 @@ QString DapLogMessage::getType() const return m_type; } -void DapLogMessage::setType(const QString &type) +void DapLogMessage::setType(const QString &asType) { - m_type = type; + m_type = asType; emit typeChanged(m_type); } @@ -25,9 +25,9 @@ QString DapLogMessage::getTimeStamp() const return m_sTimeStamp; } -void DapLogMessage::setTimeStamp(const QString &sTimeStamp) +void DapLogMessage::setTimeStamp(const QString &asTimeStamp) { - m_sTimeStamp = sTimeStamp; + m_sTimeStamp = asTimeStamp; emit timeStampChanged(m_sTimeStamp); } @@ -37,9 +37,9 @@ QString DapLogMessage::getFile() const return m_sFile; } -void DapLogMessage::setFile(const QString &sFile) +void DapLogMessage::setFile(const QString &asFile) { - m_sFile = sFile; + m_sFile = asFile; emit fileChanged(m_sFile); } @@ -49,9 +49,9 @@ QString DapLogMessage::getMessage() const return m_sMessage; } -void DapLogMessage::setMessage(const QString &sMessage) +void DapLogMessage::setMessage(const QString &asMessage) { - m_sMessage = sMessage; + m_sMessage = asMessage; emit messageChanged(m_sMessage); } diff --git a/libCellFrameDashboardCommon/DapLogMessage.h b/libCellFrameDashboardCommon/DapLogMessage.h index d277cb5..ad6d5c3 100644 --- a/libCellFrameDashboardCommon/DapLogMessage.h +++ b/libCellFrameDashboardCommon/DapLogMessage.h @@ -3,6 +3,7 @@ #include <QObject> +// TODO: I think it's useless enum enum Type { Info, @@ -15,14 +16,25 @@ class DapLogMessage : public QObject { Q_OBJECT + /// type of log message QString m_type; + /// timestamp QString m_sTimeStamp; + /// name of file where log message was occur QString m_sFile; + /// text of log message QString m_sMessage; public: + /// standard constructor explicit DapLogMessage(QObject *parent = nullptr) { Q_UNUSED(parent) } - DapLogMessage(const QString &type, const QString ×tamp, const QString &file, const QString &message, QObject *parent = nullptr); + /// overloaded constructor + /// @param asType Еype of log message + /// @param asTimestamp Timestamp of log message + /// @param asFile Name if file where log message was occur + /// @param asMessage Text of log message + DapLogMessage(const QString &asType, const QString &asTimestamp, + const QString &asFile, const QString &asMessage, QObject *parent = nullptr); Q_PROPERTY(QString type READ getType WRITE setType NOTIFY typeChanged) @@ -30,23 +42,47 @@ public: Q_PROPERTY(QString file READ getFile WRITE setFile NOTIFY fileChanged) Q_PROPERTY(QString message READ getMessage WRITE setMessage NOTIFY messageChanged) + /// Get type + /// @return Type of log message QString getType() const; - void setType(const QString &type); + /// Set type to message + /// @param asType Type of log message + void setType(const QString &asType); + /// Get timestamp + /// @return Timestamp of log message QString getTimeStamp() const; - void setTimeStamp(const QString &sTimeStamp); + /// Set timestamp to log message + /// @param asTimeStamp Timestamp of log message + void setTimeStamp(const QString &asTimeStamp); + /// Get name of file + /// @return Name of file where log message was occur QString getFile() const; - void setFile(const QString &sFile); + /// Set name of file + /// @param asFile Name of file + void setFile(const QString &asFile); + /// Get text of log message + /// @return Text of log message QString getMessage() const; - void setMessage(const QString &sMessage); + /// Set text to log message + /// @param asMessage Text of log message + void setMessage(const QString &asMessage); signals: - void typeChanged(QString aType); - void timeStampChanged(const QString& aTimeStamp); - void fileChanged(const QString& aFile); - void messageChanged(const QString& aMessage); + /// The signal emitted in case when type of log message was changed + /// @param asType type of log message + void typeChanged(const QString& asType); + /// The signal emitted in case when timestamp of log message was changed + /// @param asTimeStamp Timestamp of log message + void timeStampChanged(const QString& asTimeStamp); + /// The signal emitted in case when file og log message was changed + /// @param asFile Name of log message was changed + void fileChanged(const QString& asFile); + /// The signal emitted in case when message was changed + /// @param asMessage Text of log message + void messageChanged(const QString& asMessage); }; diff --git a/libCellFrameDashboardCommon/DapLogModel.h b/libCellFrameDashboardCommon/DapLogModel.h index becb284..4a35cfb 100644 --- a/libCellFrameDashboardCommon/DapLogModel.h +++ b/libCellFrameDashboardCommon/DapLogModel.h @@ -11,11 +11,21 @@ #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 }; @@ -23,9 +33,10 @@ enum DapLogRole { class DapLogModel : public QAbstractListModel { Q_OBJECT - + /// list of log messages QList<DapLogMessage*> m_dapLogMessage; + /// standard constructor DapLogModel(QObject *parent = nullptr); public: @@ -36,15 +47,41 @@ public: 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: -- GitLab