diff --git a/KelvinDashboardGUI/DapServiceClient.h b/KelvinDashboardGUI/DapServiceClient.h index 8f9763363e48c1e5fedaf1b97f51a810cdd174ee..3e21f0c3b3bd6c13000ca8996113a71ef14bbb8f 100644 --- a/KelvinDashboardGUI/DapServiceClient.h +++ b/KelvinDashboardGUI/DapServiceClient.h @@ -10,6 +10,9 @@ #if defined(Q_OS_LINUX) #include "DapServiceClientNativeLinux.h" typedef class DapServiceClientNativeLinux DapServiceClientNative; +#elif defined(Q_OS_WIN) +#include "DapServiceClientNativeWin.h" +typedef class DapServiceClientNativeWin DapServiceClientNative; #endif typedef QLocalSocket DapUiSocket; diff --git a/KelvinDashboardGUI/DapServiceClientNativeWin.cpp b/KelvinDashboardGUI/DapServiceClientNativeWin.cpp new file mode 100644 index 0000000000000000000000000000000000000000..724c1f0e6bb45d1db7eee932476e7f6a4da36481 --- /dev/null +++ b/KelvinDashboardGUI/DapServiceClientNativeWin.cpp @@ -0,0 +1,30 @@ +#include "DapServiceClientNativeWin.h" + +DapServiceClientNativeWin::DapServiceClientNativeWin() +{ +} + +bool DapServiceClientNativeWin::isServiceRunning() +{ + return true; +} + +DapServiceError DapServiceClientNativeWin::serviceInstallAndRun() { + return DapServiceError::NO_ERRORS; +} + +DapServiceError DapServiceClientNativeWin::serviceStart() { + return DapServiceError::NO_ERRORS; +} + +DapServiceError DapServiceClientNativeWin::serviceRestart() { + return DapServiceError::NO_ERRORS; +} + +DapServiceError DapServiceClientNativeWin::serviceStop() { + return DapServiceError::NO_ERRORS; +} + +DapServiceClientNativeWin::~DapServiceClientNativeWin() { + +} diff --git a/KelvinDashboardGUI/DapServiceClientNativeWin.h b/KelvinDashboardGUI/DapServiceClientNativeWin.h new file mode 100644 index 0000000000000000000000000000000000000000..4a729fe70ee12c89f162aa522bc5235bc4149744 --- /dev/null +++ b/KelvinDashboardGUI/DapServiceClientNativeWin.h @@ -0,0 +1,19 @@ +#ifndef DAPSERVICECLIENTNATIVEWIN_H +#define DAPSERVICECLIENTNATIVEWIN_H + +#include "DapServiceClientNativeAbstract.h" + +class DapServiceClientNativeWin : public DapServiceClientNativeAbstract +{ +public: + DapServiceClientNativeWin(); + ~DapServiceClientNativeWin() override; + bool isServiceRunning() override; + DapServiceError serviceStart() override; + DapServiceError serviceRestart() override; + + DapServiceError serviceStop() override; + DapServiceError serviceInstallAndRun() override; +}; + +#endif // DAPSERVICECLIENTNATIVEWIN_H diff --git a/KelvinDashboardGUI/KelvinDashboardGUI.pro b/KelvinDashboardGUI/KelvinDashboardGUI.pro index 0e5a7c2d17031717a0f0d6001f12b3e48ed6f66e..6d5fa0060541371576c512723499d4a4d04f20b0 100755 --- a/KelvinDashboardGUI/KelvinDashboardGUI.pro +++ b/KelvinDashboardGUI/KelvinDashboardGUI.pro @@ -18,9 +18,11 @@ VER_PAT = 0 win32 { VERSION = $${VER_MAJ}.$${VER_MIN}.$$VER_PAT + DEFINES += CLI_PATH=\\\"./kelvin-node-cli.exe\\\" } else { VERSION = $$VER_MAJ\.$$VER_MIN\-$$VER_PAT + DEFINES += CLI_PATH=\\\"/opt/kelvin-node/bin/kelvin-node-cli\\\" } # The following define makes your compiler emit warnings if you use @@ -53,6 +55,7 @@ SOURCES += \ DapCommandController.cpp \ DapServiceClientNativeAbstract.cpp \ DapServiceClientNativeLinux.cpp \ + DapServiceClientNativeWin.cpp \ DapChainWalletsModel.cpp RESOURCES += qml.qrc @@ -84,6 +87,7 @@ HEADERS += \ DapCommandController.h \ DapServiceClientNativeAbstract.h \ DapServiceClientNativeLinux.h \ + DapServiceClientNativeWin.h \ DapChainWalletsModel.h include (../libdap/libdap.pri) diff --git a/KelvinDashboardService/DapChainLogHandler.cpp b/KelvinDashboardService/DapChainLogHandler.cpp index 645053a420ccd3650f38e9be06e55b98f6b76a64..e484d3be0fc22643c54bf606c55d6ba1e8af60ec 100755 --- a/KelvinDashboardService/DapChainLogHandler.cpp +++ b/KelvinDashboardService/DapChainLogHandler.cpp @@ -26,7 +26,7 @@ QStringList DapChainLogHandler::request(int aiTimeStamp, int aiRowCount) { QByteArray result; QProcess process; - process.start(QString("%1 print_log ts_after %2 limit %3").arg("/opt/kelvin-node/bin/kelvin-node-cli").arg(aiTimeStamp).arg(aiRowCount)); + process.start(QString("%1 print_log ts_after %2 limit %3").arg(CLI_PATH).arg(aiTimeStamp).arg(aiRowCount)); process.waitForFinished(-1); result = process.readAll(); diff --git a/KelvinDashboardService/DapChainWalletHandler.cpp b/KelvinDashboardService/DapChainWalletHandler.cpp index 993490f90110f9c0033c21014679f2764cbe21f9..00e39b7005e7b3cb74753a99a79a731266d064e8 100755 --- a/KelvinDashboardService/DapChainWalletHandler.cpp +++ b/KelvinDashboardService/DapChainWalletHandler.cpp @@ -17,7 +17,7 @@ QStringList DapChainWalletHandler::createWallet(const QString &asNameWallet) { QByteArray result; QProcess process; - process.start(QString("%1 wallet new -w %2").arg("/opt/kelvin-node/bin/kelvin-node-cli").arg(asNameWallet)); + process.start(QString("%1 wallet new -w %2").arg(CLI_PATH).arg(asNameWallet)); process.waitForFinished(-1); result = process.readAll(); QStringList list; @@ -40,7 +40,7 @@ QMap<QString, QVariant> DapChainWalletHandler::getWallets() { QMap<QString, QVariant> map; QProcess process; - process.start(QString("%1 wallet list").arg("/opt/kelvin-node/bin/kelvin-node-cli")); + process.start(QString("%1 wallet list").arg(CLI_PATH)); process.waitForFinished(-1); QString str = QString::fromLatin1(process.readAll()); qDebug() << "ZDES`" << str; @@ -70,9 +70,40 @@ QMap<QString, QVariant> DapChainWalletHandler::getWallets() QStringList DapChainWalletHandler::getWalletInfo(const QString &asNameWallet) { QProcess process; - process.start(QString("%1 wallet info -w %2 -net private").arg("/opt/kelvin-node/bin/kelvin-node-cli").arg(asNameWallet)); + process.start(QString("%1 wallet info -w %2 -net kelvin-testnet").arg(CLI_PATH).arg(asNameWallet)); process.waitForFinished(-1); + char* response = process.readAll().data(); + //qDebug() << response; QStringList list; +#ifdef Q_OS_WIN32 + char *context = nullptr; + char *data = nullptr; + data = strtok_r(response, ":", &context); + if (strcmp(data, "wallet") != 0) { + data = strtok_r(response, ":", &context); + } + data = strtok_r(context+1, "\r", &context); + list.append(QString(data)); + data = strtok_r(context+1, ":", &context); + data = strtok_r(context+1, "\r", &context); + list.append(QString(data)); + data = strtok_r(context+1, ":", &context); + list.append(QString(data)); + data = strtok_r(context+4, "\r", &context); + + char *subctx; + char *subdata; + if (strlen(data) > 2) { + subdata = strtok_r(data+1, " ", &subctx); + } else { + subdata = strtok_r(data, " ", &subctx); + } + list.append(QString(subdata)); + subdata = strtok_r(subctx, " ", &subctx); + list.append(QString(subdata)); + subdata = strtok_r(subctx, "\r", &subctx); + list.append(QString(subdata)); +#else QString str = QString::fromLatin1(process.readAll()).replace("\\", "\\\\"); QRegExp rx("[(:\\)\\t]{1,1}([^\\\\\\n\\t]+)[\\\\(|\\n|\\r]{1,1}"); @@ -84,6 +115,7 @@ QStringList DapChainWalletHandler::getWalletInfo(const QString &asNameWallet) list.append(rx.cap(1)); pos += rx.matchedLength(); } +#endif qDebug() << list; return list; } @@ -93,8 +125,8 @@ QString DapChainWalletHandler::sendToken(const QString &asSendWallet, const QStr QString answer; qInfo() << QString("sendTokenTest(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount); QProcess processCreate; - processCreate.start(QString("%1 tx_create -net private -chain gdb -from_wallet %2 -to_addr %3 -token %4 -value %5") - .arg("/opt/kelvin-node/bin/kelvin-node-cli") + processCreate.start(QString("%1 tx_create -net kelvin-testnet -chain gdb -from_wallet %2 -to_addr %3 -token %4 -value %5") + .arg(CLI_PATH) .arg(asSendWallet) .arg(asAddressReceiver) .arg(asToken) @@ -105,7 +137,7 @@ QString DapChainWalletHandler::sendToken(const QString &asSendWallet, const QStr if(!(resultCreate.isEmpty() || resultCreate.isNull())) { QProcess processMempool; - processMempool.start(QString("%1 mempool_proc -net private -chain gdb").arg("/opt/kelvin-node/bin/kelvin-node-cli")); + processMempool.start(QString("%1 mempool_proc -net kelvin-testnet -chain gdb").arg(CLI_PATH)); processMempool.waitForFinished(-1); answer = QString::fromLatin1(processMempool.readAll()); qDebug() << answer; diff --git a/KelvinDashboardService/KelvinDashboardService.pro b/KelvinDashboardService/KelvinDashboardService.pro index 7d40ebc9edcb5268a2a51c98cdd65eeccc1bb2bc..e2e43067917c2b75a08ca986ecf69b1aa4fc6202 100755 --- a/KelvinDashboardService/KelvinDashboardService.pro +++ b/KelvinDashboardService/KelvinDashboardService.pro @@ -20,9 +20,11 @@ ICON = icon.ico win32 { VERSION = $${VER_MAJ}.$${VER_MIN}.$$VER_PAT + DEFINES += CLI_PATH=\\\"./kelvin-node-cli.exe\\\" } else { VERSION = $$VER_MAJ\.$$VER_MIN\-$$VER_PAT + DEFINES += CLI_PATH=\\\"/opt/kelvin-node/bin/kelvin-node-cli\\\" } # The following define makes your compiler emit warnings if you use diff --git a/KelvinDashboardService/main.cpp b/KelvinDashboardService/main.cpp index 82ed77b9453543136d8a8b59f6abe379ea5c6cd7..93c2dd46d3f7cf4a9286e6245cec3c67f8374a8e 100755 --- a/KelvinDashboardService/main.cpp +++ b/KelvinDashboardService/main.cpp @@ -16,9 +16,9 @@ int main(int argc, char *argv[]) { // Creating a semaphore for locking external resources, as well as initializing an external resource-memory QSystemSemaphore systemSemaphore(QString("systemSemaphore for %1").arg("KelvinDashboardService"), 1); -#ifndef Q_OS_WIN + QSharedMemory memmoryAppBagFix(QString("memmory for %1").arg("KelvinDashboardService")); -#endif + QSharedMemory memmoryApp(QString("memmory for %1").arg("KelvinDashboardService")); // Check for the existence of a running instance of the program bool isRunning = DapHalper::getInstance().checkExistenceRunningInstanceApp(systemSemaphore, memmoryApp, memmoryAppBagFix);